Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
change-template: '- #$NUMBER $TITLE'
sort-direction: ascending
exclude-contributors:
- 'github-actions[bot]'
- 'github-actions'
- 'renovate[bot]'
- 'renovate'
- 'pre-commit-ci'
- 'pre-commit-ci[bot]'
- 'crowdin-bot'
exclude-labels:
- 'skip-changelog'
- 'dependencies'
version-resolver:
major:
labels:
- 'major'
minor:
labels:
- 'minor'
patch:
labels:
- 'patch'
default: patch
autolabeler:
- label: 'ci/cd'
files:
- '/.github/**/*'
- label: 'documentation'
files:
- '*.md'
- '/docs/*'
branch:
- '/docs{0,1}\/.+/'
- label: 'bug'
branch:
- '/fix\/.+/'
title:
- '/fix/i'
- label: 'enhancement'
branch:
- '/feature\/.+/'
body:
- '/JIRA-[0-9]{1,4}/'
commitish: refs/heads/main
template: |
## 🚀 Changes

$CHANGES

## ❤️ Contributors
$CONTRIBUTORS
37 changes: 37 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: "Lint"

on:
# push:
pull_request:
# schedule:
# - cron: "0 0 * * *"

jobs:
lint:
name: Lint
runs-on: "ubuntu-latest"
steps:
- name: "Checkout the repository"
uses: actions/checkout@v4

- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"

- name: "Install requirements"
run: python3 -m pip install -r requirements.txt

- name: "Install linters"
run: python3 -m pip install ruff yamllint

- name: "ruff check ."
run: python3 -m ruff check .

# - name: yaml-lint
# uses: ibiqlik/action-yamllint@v3
# with:
# # file_or_dir: myfolder/*values*.yaml
# config_file: .yamllint.yaml
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
tags:
- v**
release:
types: [created]
types: [published]

permissions:
contents: read
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/release-drafter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: Release Drafter

on:
push:
branches: [main, master]
pull_request:
types: [opened, reopened, synchronize]
workflow_dispatch:

permissions:
contents: read

jobs:
update_release_draft:
permissions:
# write permission is required to create a github release
contents: write
# write permission is required for autolabeler
# otherwise, read permission is required at least
pull-requests: write
name: Update release draft
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Create Release
uses: release-drafter/release-drafter@v6
with:
disable-releaser: github.ref != 'refs/heads/main'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22 changes: 22 additions & 0 deletions .github/workflows/sourcery-for-codebase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Sourcery (for Codebase)

on:
push:
branches: [main, master]
workflow_dispatch:

jobs:
review-codebase-with-sourcery:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.11'

# https://github.com/sourcery-ai/action
- uses: sourcery-ai/action@v1
with:
token: ${{ secrets.SOURCERY_TOKEN }}
23 changes: 23 additions & 0 deletions .github/workflows/sourcery-for-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: Sourcery (for PR)

on:
pull_request:

jobs:
review-pr-with-sourcery:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-python@v5
with:
python-version: '3.11'

# https://github.com/sourcery-ai/action
- uses: sourcery-ai/action@v1
with:
token: ${{ secrets.SOURCERY_TOKEN }}
diff_ref: ${{ github.event.pull_request.base.sha }}
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.7
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
files: ^((pyopenhardwaremonitor|tests)/.+)?[^/]+\.(py|pyi)$

- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: yamllint
language: python
types: [file, yaml]
files: ^((pyopenhardwaremonitor|tests)/.+)?[^/]+\.(yaml|yml)$

- repo: https://github.com/sourcery-ai/sourcery
rev: v1.34.0
hooks:
- id: sourcery
# The best way to use Sourcery in a pre-commit hook:
# * review only changed lines:
# * omit the summary
args: [--diff=git diff HEAD, --no-summary]
stages: [pre-push]
86 changes: 86 additions & 0 deletions .sourcery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# 🪄 This is your project's Sourcery configuration file.

# You can use it to get Sourcery working in the way you want, such as
# ignoring specific refactorings, skipping directories in your project,
# or writing custom rules.

# 📚 For a complete reference to this file, see the documentation at
# https://docs.sourcery.ai/Configuration/Project-Settings/

# This file was auto-generated by Sourcery on 2025-02-25 at 16:44.
# EDIT: With some manual edits made to adhere to yamllint.
---
version: '1' # The schema version of this config file

ignore: # A list of paths or files which Sourcery will ignore.
- .git
- env
- .env
- .tox
- node_modules
- vendor
- venv
- .venv
- ~/.pyenv
- ~/.rye
- ~/.vscode
- .vscode
- ~/.cache
- ~/.config
- ~/.local

rule_settings:
enable:
- default
disable: [] # A list of rule IDs Sourcery will never suggest.
rule_types:
- refactoring
- suggestion
- comment

# A string specifying the lowest Python version your project supports.
# Sourcery will not suggest refactorings requiring a higher Python version.
python_version: '3.11'

# rules: # A list of custom rules Sourcery will include in its analysis.
# - id: no-print-statements
# description: Do not use print statements in the test directory.
# pattern: print(...)
# language: python
# replacement:
# condition:
# explanation:
# paths:
# include:
# - test
# exclude:
# - conftest.py
# tests: []
# tags: []

# rule_tags: {} # Additional rule tags.

# metrics:
# quality_threshold: 25.0

# github:
# labels: []
# ignore_labels:
# - sourcery-ignore
# request_review: author
# sourcery_branch: sourcery/{base_branch}

# clone_detection:
# min_lines: 3
# min_duplicates: 2
# identical_clones_only: false

# proxy:
# url:
# ssl_certs_file:
# no_ssl_verify: false

# coding_assistant:
# project_description: ''
# enabled: true
# recipe_prompts: {}
5 changes: 5 additions & 0 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
extends: default
rules:
truthy:
check-keys: false
4 changes: 2 additions & 2 deletions FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# These are supported funding model platforms

---
github: lazytarget
custom: "https://paypal.me/peteraslund"
custom: "https://paypal.me/peteraslund"
3 changes: 2 additions & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ async def main(host=None, port=8085):
def get_current_ip() -> str:
"""Gets the local IP-address of this machine"""
import socket

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
return str(s.getsockname()[0])


if __name__ == '__main__':
if __name__ == "__main__":
# if running on Windows
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

Expand Down
16 changes: 11 additions & 5 deletions pyopenhardwaremonitor/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


class OpenHardwareMonitorAPI:

DEFAULT_TIMEOUT = 10

def __init__(
Expand All @@ -23,7 +22,7 @@ def __init__(
session=None,
timeout=DEFAULT_TIMEOUT,
retry_count=3,
retry_delay=None
retry_delay=None,
):
self._timeout = timeout
self._close_session = False
Expand All @@ -35,7 +34,9 @@ def __init__(
self._close_session = True

self._retry_count = retry_count
self._retry_delay = retry_delay or (lambda attempt: 3**attempt + random.uniform(0, 3))
self._retry_delay = retry_delay or (
lambda attempt: 3**attempt + random.uniform(0, 3)
)

self.API_URL = URL(f"http://{host}:{port}/")

Expand Down Expand Up @@ -76,11 +77,16 @@ async def raw_request( # pylint: disable=too-many-arguments
delay = self._retry_delay(attempt)
_LOGGER.info("Request limit exceeded, retrying in %s second", delay)
await asyncio.sleep(delay)
return await self.raw_request(uri, params, data, method, attempt=attempt + 1)
return await self.raw_request(
uri, params, data, method, attempt=attempt + 1
)
raise OpenHardwareMonitorError("Request limit exceeded")

content = None
if "Content-Type" in response.headers and "application/json" in response.headers["Content-Type"]:
if (
"Content-Type" in response.headers
and "application/json" in response.headers["Content-Type"]
):
content = await response.json()
else:
content = await response.read()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"Programming Language :: Python :: 3",
"Topic :: Home Automation",
"Topic :: Software Development :: Libraries :: Python Modules",
"License :: OSI Approved :: MIT License"
"License :: OSI Approved :: MIT License",
],
)
Loading