Skip to content

Commit 254cb84

Browse files
committed
Update ruff configuration
- Run ruff in GitHub test workflow
1 parent e8e3865 commit 254cb84

File tree

14 files changed

+76
-75
lines changed

14 files changed

+76
-75
lines changed

.github/workflows/test-python-package.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
python-version: ${{ matrix.python-version }}
2626
- name: Install dependencies
2727
run: uv sync --locked --all-extras --dev
28+
- name: Run Ruff
29+
run: uvx ruff check . --output-format=github
2830
- name: Run tests
2931
run: |
3032
uv run pytest \

example.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
#!/usr/bin/env python3
22
import time
3-
from pystiebeleltron import pystiebeleltron as pyse
3+
44
from pymodbus.client import ModbusTcpClient as ModbusClient
55

6+
from pystiebeleltron import pystiebeleltron as pyse
7+
68
host_ip = "192.168.1.20"
79
host_port = 502
810
device_id = 1
911

12+
1013
def test_function(mod, fun):
1114
"""Executes the given function on the Stiebel Heatpump and prints the result."""
12-
result = getattr(mod, fun) # Executes function directly, instead of giving back the function reference
15+
result = getattr(mod, fun) # Executes function directly, instead of giving back the function reference
1316
print("{}: {}".format(str(fun), str(result)))
1417

1518

@@ -40,9 +43,7 @@ def execute_tests(unit):
4043

4144

4245
def main():
43-
client = ModbusClient(host=host_ip,
44-
port=host_port,
45-
timeout=2)
46+
client = ModbusClient(host=host_ip, port=host_port, timeout=2)
4647
client.connect()
4748

4849
unit = pyse.StiebelEltronAPI(client, device_id)
@@ -52,5 +53,6 @@ def main():
5253

5354
client.close()
5455

56+
5557
if __name__ == "__main__":
5658
main()

pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dev = [
3131
"pytest>=8.3.5",
3232
"pytest-asyncio>=0.26.0",
3333
"pytest-mock>=3.14.0",
34-
"ruff>=0.9.6",
34+
"ruff>=0.12.0",
3535
]
3636

3737
[tool.hatch.build.targets.sdist]
@@ -45,6 +45,12 @@ path = "pystiebeleltron/__init__.py"
4545

4646
[tool.ruff]
4747
line-length = 200
48+
lint.select = ["E", "F", "B", "I"]
49+
lint.ignore = []
50+
target-version = "py310"
51+
52+
[tool.ruff.lint.pydocstyle]
53+
convention = "google"
4854

4955
[tool.pytest.ini_options]
5056

pystiebeleltron/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import asyncio
22
import logging
3-
3+
from dataclasses import dataclass
44
from enum import Enum
55

6-
from dataclasses import dataclass
76
from pymodbus.client import AsyncModbusTcpClient
87

9-
108
__version__ = "0.2.2"
119

1210
_LOGGER: logging.Logger = logging.getLogger(__package__)

pystiebeleltron/lwz.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
from enum import Enum
44

55
from . import (
6-
ModbusRegister,
7-
ModbusRegisterBlock,
8-
StiebelEltronAPI,
9-
IsgRegisters,
10-
RegisterType,
116
ENERGY_DATA_BLOCK_NAME,
12-
VIRTUAL_REGISTER_OFFSET,
13-
VIRTUAL_TOTAL_AND_DAY_REGISTER_OFFSET,
147
ENERGY_MANAGEMENT_SETTINGS_REGISTERS,
158
ENERGY_SYSTEM_INFORMATION_REGISTERS,
9+
VIRTUAL_REGISTER_OFFSET,
10+
VIRTUAL_TOTAL_AND_DAY_REGISTER_OFFSET,
11+
IsgRegisters,
12+
ModbusRegister,
13+
ModbusRegisterBlock,
14+
RegisterType,
15+
StiebelEltronAPI,
1616
)
1717

1818

pystiebeleltron/pystiebeleltron.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,12 @@ def get_conv_val(self, name: str):
225225
# self.update()
226226
# return self._block_2_holding_regs[name]
227227

228-
# def set_raw_holding_register(self, name, value):
229-
# """Write to register by name."""
230-
# self._conn.write_register(
231-
# device_id=self._device_id,
232-
# address=(self._holding_regs[name]['addr']),
233-
# value=value)
234-
228+
# def set_raw_holding_register(self, name, value):
229+
# """Write to register by name."""
230+
# self._conn.write_register(
231+
# device_id=self._device_id,
232+
# address=(self._holding_regs[name]['addr']),
233+
# value=value)
235234

236235
# Handle room temperature & humidity
237236

@@ -251,7 +250,6 @@ def set_target_temp(self, temp: float):
251250
"""Set the target room temperature (day)(HC1)."""
252251
self._conn.write_register(device_id=self._device_id, address=(self._block_2_holding_regs["ROOM_TEMP_HEAT_DAY_HC1"]["addr"]), value=round(temp * 10.0))
253252

254-
255253
def get_current_humidity(self):
256254
"""Get the current room humidity."""
257255
if self._update_on_read:

pystiebeleltron/wpm.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
"""Modbus api for stiebel eltron heat pumps. This file is generated. Do not modify it manually."""
22

33
from . import (
4-
ModbusRegister,
5-
ModbusRegisterBlock,
6-
StiebelEltronAPI,
7-
IsgRegisters,
8-
RegisterType,
94
ENERGY_DATA_BLOCK_NAME,
10-
VIRTUAL_REGISTER_OFFSET,
115
ENERGY_MANAGEMENT_SETTINGS_REGISTERS,
126
ENERGY_SYSTEM_INFORMATION_REGISTERS,
7+
VIRTUAL_REGISTER_OFFSET,
138
VIRTUAL_TOTAL_AND_DAY_REGISTER_OFFSET,
9+
IsgRegisters,
10+
ModbusRegister,
11+
ModbusRegisterBlock,
12+
RegisterType,
13+
StiebelEltronAPI,
1414
)
1515

1616

scripts/gen.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
uv run scripts/generate.py
44
uvx ruff format pystiebeleltron
5+
uvx ruff check --fix pystiebeleltron

scripts/generate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Generate python files to access the stiebel eltron heat pumps."""
22

3-
from pathlib import Path
43
import csv
5-
64
from dataclasses import dataclass
5+
from pathlib import Path
76

87
from jinja2 import Environment, FileSystemLoader, Template, select_autoescape
8+
99
from pystiebeleltron import RegisterType
1010

1111
ENERGY_DATA_BLOCK_NAME = "Energy Data"

test/mock_modbus_server.py

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,22 @@
77
twisted library as its backend. This allows it to scale to many thousands
88
of nodes which can be helpful for testing monitoring software.
99
"""
10+
1011
# --------------------------------------------------------------------------- #
1112
# import the various server implementations
1213
# --------------------------------------------------------------------------- #
13-
from pymodbus.server import StartTcpServer, ServerStop
14-
14+
from pymodbus.datastore import ModbusDeviceContext, ModbusSequentialDataBlock, ModbusServerContext
1515
from pymodbus.pdu.device import ModbusDeviceIdentification
16-
from pymodbus.datastore import ModbusSequentialDataBlock
17-
from pymodbus.datastore import ModbusDeviceContext, ModbusServerContext
16+
from pymodbus.server import ServerStop, StartTcpServer
1817

1918

2019
class MockModbusServer(object):
2120
# --------------------------------------------------------------------------- #
2221
# configure the service logging
2322
# --------------------------------------------------------------------------- #
2423
import logging
25-
FORMAT = ('%(asctime)-15s %(threadName)-15s'
26-
' %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s')
24+
25+
FORMAT = "%(asctime)-15s %(threadName)-15s %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s"
2726
logging.basicConfig(format=FORMAT)
2827
log = logging.getLogger()
2928
log.setLevel(logging.DEBUG)
@@ -83,9 +82,7 @@ def run_async_server(self):
8382
#
8483
# store = ModbusDeviceContext(..., zero_mode=True)
8584
# ----------------------------------------------------------------------- #
86-
store = ModbusDeviceContext(
87-
hr=ModbusSequentialDataBlock(0, [0]*3000),
88-
ir=ModbusSequentialDataBlock(0, [0]*3000))
85+
store = ModbusDeviceContext(hr=ModbusSequentialDataBlock(0, [0] * 3000), ir=ModbusSequentialDataBlock(0, [0] * 3000))
8986
self.context = ModbusServerContext(devices=store, single=True)
9087

9188
# ----------------------------------------------------------------------- #
@@ -94,12 +91,12 @@ def run_async_server(self):
9491
# If you don't set this or any fields, they are defaulted to empty strings.
9592
# ----------------------------------------------------------------------- #
9693
identity = ModbusDeviceIdentification()
97-
identity.VendorName = 'Pymodbus'
98-
identity.ProductCode = 'PM'
99-
identity.VendorUrl = 'http://github.com/bashwork/pymodbus/'
100-
identity.ProductName = 'Pymodbus Server'
101-
identity.ModelName = 'Pymodbus Server'
102-
identity.MajorMinorRevision = '1.5'
94+
identity.VendorName = "Pymodbus"
95+
identity.ProductCode = "PM"
96+
identity.VendorUrl = "http://github.com/bashwork/pymodbus/"
97+
identity.ProductName = "Pymodbus Server"
98+
identity.ModelName = "Pymodbus Server"
99+
identity.MajorMinorRevision = "1.5"
103100

104101
# ----------------------------------------------------------------------- #
105102
# run the server you want
@@ -112,7 +109,7 @@ def stop_async_server(self):
112109
ServerStop()
113110

114111
def update_context(self, register, address, values):
115-
""" Update values of the active context. It should be noted
112+
"""Update values of the active context. It should be noted
116113
that there is a race condition for the update.
117114
118115
:param register: Type of register to update,
@@ -123,30 +120,26 @@ def update_context(self, register, address, values):
123120
"""
124121
assert register == 3 or register == 4
125122
device_id = 0x00
126-
old_values = self.context[device_id].getValues(register,
127-
address, count=1)
128-
self.log.debug("Change value at address {} from {} to {}".format(
129-
address, old_values, values))
123+
old_values = self.context[device_id].getValues(register, address, count=1)
124+
self.log.debug("Change value at address {} from {} to {}".format(address, old_values, values))
130125
self.context[device_id].setValues(register, address, values)
131126

132127
def update_holding_register(self, address, value):
133-
""" Update value of a holding register.
128+
"""Update value of a holding register.
134129
135130
:param address: Address to update
136131
:param value: Value to save
137132
"""
138-
self.log.debug("Update holding register: {}:{}".format(address,
139-
int(value)))
133+
self.log.debug("Update holding register: {}:{}".format(address, int(value)))
140134
self.update_context(3, address, [int(value)])
141135

142136
def update_input_register(self, address, value):
143-
""" Update value of an input register.
137+
"""Update value of an input register.
144138
145139
:param address: Address to update
146140
:param value: Value to save
147141
"""
148-
self.log.debug("Update input register: {}:{}".format(address,
149-
int(value)))
142+
self.log.debug("Update input register: {}:{}".format(address, int(value)))
150143
self.update_context(4, address, [int(value)])
151144

152145

0 commit comments

Comments
 (0)