Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Py bump and ruff over black/isort #484

Merged
merged 5 commits into from
Dec 24, 2023
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
13 changes: 9 additions & 4 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
name: Latest release

env:
CACHE_VERSION: 7
DEFAULT_PYTHON: "3.11"
CACHE_VERSION: 8
DEFAULT_PYTHON: "3.12"

# Only run on merges
on:
Expand All @@ -28,9 +28,14 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Build a distribution
- name: Install pypa/build
run: >-
python setup.py sdist
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down
35 changes: 20 additions & 15 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
name: Latest commit

env:
CACHE_VERSION: 6
DEFAULT_PYTHON: "3.11"
CACHE_VERSION: 9
DEFAULT_PYTHON: "3.12"
PRE_COMMIT_HOME: ~/.cache/pre-commit

on:
Expand Down Expand Up @@ -65,9 +65,9 @@ jobs:
. venv/bin/activate
pre-commit install-hooks

black:
ruff:
runs-on: ubuntu-latest
name: Black check and force
name: Ruff check and force
needs: prepare
steps:
- name: Check out committed code
Expand All @@ -94,27 +94,27 @@ jobs:
run: |
echo "Failed to restore Python ${{ env.DEFAULT_PYTHON }} virtual environment from cache"
exit 1
- name: Run black --check --exclude venv .
- name: Ruff (with fix)
run: |
. venv/bin/activate
black --check --exclude venv .
- name: If needed, commit black changes to the pull request
ruff plugwise/*py tests/*py
- name: If needed, commit ruff changes to the pull request
if: failure()
run: |
. venv/bin/activate
black --exclude venv .
git config --global user.name 'autoblack'
ruff --fix plugwise/*py tests/*py
git config --global user.name 'autoruff'
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.PAT_CT }}@github.com/$GITHUB_REPOSITORY
git checkout $GITHUB_HEAD_REF
git commit -am "fixup: ${GITHUB_REF##*/} Python code reformatted using Black"
git commit -am "fixup: ${GITHUB_REF##*/} Python code fixed using ruff"
git push origin ${GITHUB_REF##*/}

commitcheck:
runs-on: ubuntu-latest
name: Check commit
needs:
- black
- ruff
- shellcheck
- dependencies_check
steps:
Expand Down Expand Up @@ -167,7 +167,7 @@ jobs:
needs: commitcheck
strategy:
matrix:
python-version: ["3.12", "3.11", "3.10"]
python-version: ["3.12"]
steps:
- name: Check out committed code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
Expand Down Expand Up @@ -206,7 +206,7 @@ jobs:
needs: prepare-test-cache
strategy:
matrix:
python-version: ["3.12", "3.11", "3.10"]
python-version: ["3.12"]

steps:
- name: Check out committed code
Expand Down Expand Up @@ -360,9 +360,14 @@ jobs:
run: |
echo "Failed to restore Python virtual environment from cache"
exit 1
- name: Build a distribution
- name: Install pypa/build
run: >-
python setup.py sdist
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
continue-on-error: true
Expand Down
14 changes: 1 addition & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ci:

default_language_version:
# force all unspecified python hooks to run python3
python: python3.11
python: python3.12

repos:
# Run manually in CI skipping the branch checks
Expand All @@ -16,10 +16,6 @@ repos:
- id: ruff
args:
- --fix
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand All @@ -33,14 +29,6 @@ repos:
hooks:
- id: pyupgrade
args: [--py39-plus]
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
args:
- --safe
- --quiet
files: ^((plugwise|tests|scripts)/.+)?[^/]+\.py$
# Moved codespell configuration to setup.cfg as per 'all-files' issues not reading args
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Ongoing

- Refresh adam_plus_anna_new userdata and adapt.
- Bump actions and requirements to Python 3.12
- Ruff as per #470 (defaulting black and isort to ruff)

## v0.35.4

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ Our main usage for this module is supporting [Home Assistant](https://www.home-a
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/plugwise/python-plugwise/main.svg)](https://results.pre-commit.ci/latest/github/plugwise/python-plugwise/main)
[![renovate maintained](https://img.shields.io/badge/maintained%20with-renovate-blue?logo=renovatebot)](https://github.com/plugwise/python-plugwise/issues/291)

The below scoring only applies to Plugwise Smile components:

[![CodeFactor](https://www.codefactor.io/repository/github/plugwise/python-plugwise/badge)](https://www.codefactor.io/repository/github/plugwise/python-plugwise)
[![codecov](https://codecov.io/gh/plugwise/python-plugwise/branch/main/graph/badge.svg)](https://codecov.io/gh/plugwise/python-plugwise)

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=plugwise_python-plugwise&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=plugwise_python-plugwise)
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=plugwise_python-plugwise&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=plugwise_python-plugwise)
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=plugwise_python-plugwise&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=plugwise_python-plugwise)

## Integration

### Home-Assistant Integration
Expand Down
31 changes: 15 additions & 16 deletions plugwise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,22 +424,21 @@ async def _smile_detect_legacy(
locator = f"./{network}/mac"
if (net_locator := self._system.find(locator)) is not None:
self.smile_mac_address = net_locator.text
else:
# P1 legacy:
if dsmrmain is not None:
self._status = await self._request(STATUS)
self.smile_fw_version = self._status.find("./system/version").text
model = self._status.find("./system/product").text
self.smile_hostname = self._status.find("./network/hostname").text
self.smile_mac_address = self._status.find("./network/mac_address").text

else: # pragma: no cover
# No cornercase, just end of the line
LOGGER.error(
"Connected but no gateway device information found, please create"
" an issue on http://github.com/plugwise/python-plugwise"
)
raise ResponseError
# P1 legacy:
elif dsmrmain is not None:
self._status = await self._request(STATUS)
self.smile_fw_version = self._status.find("./system/version").text
model = self._status.find("./system/product").text
self.smile_hostname = self._status.find("./network/hostname").text
self.smile_mac_address = self._status.find("./network/mac_address").text

else: # pragma: no cover
# No cornercase, just end of the line
LOGGER.error(
"Connected but no gateway device information found, please create"
" an issue on http://github.com/plugwise/python-plugwise"
)
raise ResponseError

self._smile_legacy = True
return model
Expand Down
15 changes: 7 additions & 8 deletions plugwise/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,14 +1095,13 @@ def _get_measurement_data(self, dev_id: str) -> DeviceData:

# Loria/Thermastage: cooling-related is based on cooling_state
# and modulation_level
else:
if self._cooling_present and "cooling_state" in data["binary_sensors"]:
self._cooling_enabled = data["binary_sensors"]["cooling_state"]
self._cooling_active = data["sensors"]["modulation_level"] == 100
# For Loria the above does not work (pw-beta issue #301)
if "cooling_ena_switch" in data["switches"]:
self._cooling_enabled = data["switches"]["cooling_ena_switch"]
self._cooling_active = data["binary_sensors"]["cooling_state"]
elif self._cooling_present and "cooling_state" in data["binary_sensors"]:
self._cooling_enabled = data["binary_sensors"]["cooling_state"]
self._cooling_active = data["sensors"]["modulation_level"] == 100
# For Loria the above does not work (pw-beta issue #301)
if "cooling_ena_switch" in data["switches"]:
self._cooling_enabled = data["switches"]["cooling_ena_switch"]
self._cooling_active = data["binary_sensors"]["cooling_state"]

self._cleanup_data(data)

Expand Down
13 changes: 6 additions & 7 deletions plugwise/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ def format_measure(measure: str, unit: str) -> float | int:
result = float(f"{round(float_measure, 3):.3f}")
elif unit == ELECTRIC_POTENTIAL_VOLT:
result = float(f"{round(float_measure, 1):.1f}")
else:
if abs(float_measure) < 10:
result = float(f"{round(float_measure, 2):.2f}")
elif abs(float_measure) >= 10 and abs(float_measure) < 100:
result = float(f"{round(float_measure, 1):.1f}")
elif abs(float_measure) >= 100:
result = int(round(float_measure))
elif abs(float_measure) < 10:
result = float(f"{round(float_measure, 2):.2f}")
elif abs(float_measure) >= 10 and abs(float_measure) < 100:
result = float(f"{round(float_measure, 1):.1f}")
elif abs(float_measure) >= 100:
result = int(round(float_measure))

return result

Expand Down
Loading
Loading