Skip to content

Commit d72610b

Browse files
authored
Merge pull request #484 from plugwise/var
Py bump and ruff over black/isort
2 parents 391195f + c7e4a13 commit d72610b

File tree

12 files changed

+146
-80
lines changed

12 files changed

+146
-80
lines changed

.github/workflows/merge.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
name: Latest release
55

66
env:
7-
CACHE_VERSION: 7
8-
DEFAULT_PYTHON: "3.11"
7+
CACHE_VERSION: 8
8+
DEFAULT_PYTHON: "3.12"
99

1010
# Only run on merges
1111
on:
@@ -28,9 +28,14 @@ jobs:
2828
uses: actions/setup-python@v5
2929
with:
3030
python-version: ${{ env.DEFAULT_PYTHON }}
31-
- name: Build a distribution
31+
- name: Install pypa/build
3232
run: >-
33-
python setup.py sdist
33+
python3 -m
34+
pip install
35+
build
36+
--user
37+
- name: Build a binary wheel and a source tarball
38+
run: python3 -m build
3439
- name: Publish distribution 📦 to PyPI
3540
uses: pypa/gh-action-pypi-publish@release/v1
3641
with:

.github/workflows/verify.yml

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
name: Latest commit
55

66
env:
7-
CACHE_VERSION: 6
8-
DEFAULT_PYTHON: "3.11"
7+
CACHE_VERSION: 9
8+
DEFAULT_PYTHON: "3.12"
99
PRE_COMMIT_HOME: ~/.cache/pre-commit
1010

1111
on:
@@ -65,9 +65,9 @@ jobs:
6565
. venv/bin/activate
6666
pre-commit install-hooks
6767
68-
black:
68+
ruff:
6969
runs-on: ubuntu-latest
70-
name: Black check and force
70+
name: Ruff check and force
7171
needs: prepare
7272
steps:
7373
- name: Check out committed code
@@ -94,27 +94,27 @@ jobs:
9494
run: |
9595
echo "Failed to restore Python ${{ env.DEFAULT_PYTHON }} virtual environment from cache"
9696
exit 1
97-
- name: Run black --check --exclude venv .
97+
- name: Ruff (with fix)
9898
run: |
9999
. venv/bin/activate
100-
black --check --exclude venv .
101-
- name: If needed, commit black changes to the pull request
100+
ruff plugwise/*py tests/*py
101+
- name: If needed, commit ruff changes to the pull request
102102
if: failure()
103103
run: |
104104
. venv/bin/activate
105-
black --exclude venv .
106-
git config --global user.name 'autoblack'
105+
ruff --fix plugwise/*py tests/*py
106+
git config --global user.name 'autoruff'
107107
git config --global user.email 'plugwise@users.noreply.github.com'
108108
git remote set-url origin https://x-access-token:${{ secrets.PAT_CT }}@github.com/$GITHUB_REPOSITORY
109109
git checkout $GITHUB_HEAD_REF
110-
git commit -am "fixup: ${GITHUB_REF##*/} Python code reformatted using Black"
110+
git commit -am "fixup: ${GITHUB_REF##*/} Python code fixed using ruff"
111111
git push origin ${GITHUB_REF##*/}
112112
113113
commitcheck:
114114
runs-on: ubuntu-latest
115115
name: Check commit
116116
needs:
117-
- black
117+
- ruff
118118
- shellcheck
119119
- dependencies_check
120120
steps:
@@ -167,7 +167,7 @@ jobs:
167167
needs: commitcheck
168168
strategy:
169169
matrix:
170-
python-version: ["3.12", "3.11", "3.10"]
170+
python-version: ["3.12"]
171171
steps:
172172
- name: Check out committed code
173173
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
@@ -206,7 +206,7 @@ jobs:
206206
needs: prepare-test-cache
207207
strategy:
208208
matrix:
209-
python-version: ["3.12", "3.11", "3.10"]
209+
python-version: ["3.12"]
210210

211211
steps:
212212
- name: Check out committed code
@@ -360,9 +360,14 @@ jobs:
360360
run: |
361361
echo "Failed to restore Python virtual environment from cache"
362362
exit 1
363-
- name: Build a distribution
363+
- name: Install pypa/build
364364
run: >-
365-
python setup.py sdist
365+
python3 -m
366+
pip install
367+
build
368+
--user
369+
- name: Build a binary wheel and a source tarball
370+
run: python3 -m build
366371
- name: Publish distribution 📦 to Test PyPI
367372
uses: pypa/gh-action-pypi-publish@release/v1
368373
continue-on-error: true

.pre-commit-config.yaml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ci:
66

77
default_language_version:
88
# force all unspecified python hooks to run python3
9-
python: python3.11
9+
python: python3.12
1010

1111
repos:
1212
# Run manually in CI skipping the branch checks
@@ -16,10 +16,6 @@ repos:
1616
- id: ruff
1717
args:
1818
- --fix
19-
- repo: https://github.com/PyCQA/isort
20-
rev: 5.13.2
21-
hooks:
22-
- id: isort
2319
- repo: https://github.com/pre-commit/pre-commit-hooks
2420
rev: v4.5.0
2521
hooks:
@@ -33,14 +29,6 @@ repos:
3329
hooks:
3430
- id: pyupgrade
3531
args: [--py39-plus]
36-
- repo: https://github.com/psf/black
37-
rev: 23.12.1
38-
hooks:
39-
- id: black
40-
args:
41-
- --safe
42-
- --quiet
43-
files: ^((plugwise|tests|scripts)/.+)?[^/]+\.py$
4432
# Moved codespell configuration to setup.cfg as per 'all-files' issues not reading args
4533
- repo: https://github.com/codespell-project/codespell
4634
rev: v2.2.6

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## Ongoing
44

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

79
## v0.35.4
810

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ Our main usage for this module is supporting [Home Assistant](https://www.home-a
1414
[![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)
1515
[![renovate maintained](https://img.shields.io/badge/maintained%20with-renovate-blue?logo=renovatebot)](https://github.com/plugwise/python-plugwise/issues/291)
1616

17-
The below scoring only applies to Plugwise Smile components:
18-
1917
[![CodeFactor](https://www.codefactor.io/repository/github/plugwise/python-plugwise/badge)](https://www.codefactor.io/repository/github/plugwise/python-plugwise)
2018
[![codecov](https://codecov.io/gh/plugwise/python-plugwise/branch/main/graph/badge.svg)](https://codecov.io/gh/plugwise/python-plugwise)
2119

20+
[![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)
21+
[![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)
22+
[![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)
23+
2224
## Integration
2325

2426
### Home-Assistant Integration

plugwise/__init__.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -424,22 +424,21 @@ async def _smile_detect_legacy(
424424
locator = f"./{network}/mac"
425425
if (net_locator := self._system.find(locator)) is not None:
426426
self.smile_mac_address = net_locator.text
427-
else:
428-
# P1 legacy:
429-
if dsmrmain is not None:
430-
self._status = await self._request(STATUS)
431-
self.smile_fw_version = self._status.find("./system/version").text
432-
model = self._status.find("./system/product").text
433-
self.smile_hostname = self._status.find("./network/hostname").text
434-
self.smile_mac_address = self._status.find("./network/mac_address").text
435-
436-
else: # pragma: no cover
437-
# No cornercase, just end of the line
438-
LOGGER.error(
439-
"Connected but no gateway device information found, please create"
440-
" an issue on http://github.com/plugwise/python-plugwise"
441-
)
442-
raise ResponseError
427+
# P1 legacy:
428+
elif dsmrmain is not None:
429+
self._status = await self._request(STATUS)
430+
self.smile_fw_version = self._status.find("./system/version").text
431+
model = self._status.find("./system/product").text
432+
self.smile_hostname = self._status.find("./network/hostname").text
433+
self.smile_mac_address = self._status.find("./network/mac_address").text
434+
435+
else: # pragma: no cover
436+
# No cornercase, just end of the line
437+
LOGGER.error(
438+
"Connected but no gateway device information found, please create"
439+
" an issue on http://github.com/plugwise/python-plugwise"
440+
)
441+
raise ResponseError
443442

444443
self._smile_legacy = True
445444
return model

plugwise/helper.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,14 +1095,13 @@ def _get_measurement_data(self, dev_id: str) -> DeviceData:
10951095

10961096
# Loria/Thermastage: cooling-related is based on cooling_state
10971097
# and modulation_level
1098-
else:
1099-
if self._cooling_present and "cooling_state" in data["binary_sensors"]:
1100-
self._cooling_enabled = data["binary_sensors"]["cooling_state"]
1101-
self._cooling_active = data["sensors"]["modulation_level"] == 100
1102-
# For Loria the above does not work (pw-beta issue #301)
1103-
if "cooling_ena_switch" in data["switches"]:
1104-
self._cooling_enabled = data["switches"]["cooling_ena_switch"]
1105-
self._cooling_active = data["binary_sensors"]["cooling_state"]
1098+
elif self._cooling_present and "cooling_state" in data["binary_sensors"]:
1099+
self._cooling_enabled = data["binary_sensors"]["cooling_state"]
1100+
self._cooling_active = data["sensors"]["modulation_level"] == 100
1101+
# For Loria the above does not work (pw-beta issue #301)
1102+
if "cooling_ena_switch" in data["switches"]:
1103+
self._cooling_enabled = data["switches"]["cooling_ena_switch"]
1104+
self._cooling_active = data["binary_sensors"]["cooling_state"]
11061105

11071106
self._cleanup_data(data)
11081107

plugwise/util.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ def format_measure(measure: str, unit: str) -> float | int:
3838
result = float(f"{round(float_measure, 3):.3f}")
3939
elif unit == ELECTRIC_POTENTIAL_VOLT:
4040
result = float(f"{round(float_measure, 1):.1f}")
41-
else:
42-
if abs(float_measure) < 10:
43-
result = float(f"{round(float_measure, 2):.2f}")
44-
elif abs(float_measure) >= 10 and abs(float_measure) < 100:
45-
result = float(f"{round(float_measure, 1):.1f}")
46-
elif abs(float_measure) >= 100:
47-
result = int(round(float_measure))
41+
elif abs(float_measure) < 10:
42+
result = float(f"{round(float_measure, 2):.2f}")
43+
elif abs(float_measure) >= 10 and abs(float_measure) < 100:
44+
result = float(f"{round(float_measure, 1):.1f}")
45+
elif abs(float_measure) >= 100:
46+
result = int(round(float_measure))
4847

4948
return result
5049

0 commit comments

Comments
 (0)