Skip to content

Commit d88ff2d

Browse files
committed
ruff: PLR2004 static constants (first dash, leaving out work on energy log constants considering ongoing effort
1 parent b295a7f commit d88ff2d

File tree

6 files changed

+20
-10
lines changed

6 files changed

+20
-10
lines changed

plugwise_usb/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
LOCAL_TIMEZONE = dt.datetime.now(dt.UTC).astimezone().tzinfo
1616
UTF8: Final = "utf-8"
1717

18+
# Value limits
19+
MAX_UINT_2: Final = 255
20+
MAX_UINT_4: Final = 65535
21+
1822
# Time
1923
DAY_IN_HOURS: Final = 24
2024
WEEK_IN_HOURS: Final = 168

plugwise_usb/nodes/helpers/pulses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ def _last_known_duration(self) -> timedelta:
950950
if self._logs is None:
951951
raise EnergyError("Unable to return last known duration without any logs")
952952

953-
if len(self._logs) < 2:
953+
if len(self._logs) < 2: # noqa: PLR2004
954954
return timedelta(hours=1)
955955

956956
address, slot = self._last_log_reference()

plugwise_usb/nodes/node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ async def _available_update_state(
425425
if (
426426
self._last_seen is not None
427427
and timestamp is not None
428-
and int((timestamp - self._last_seen).total_seconds()) > 5
428+
and int((timestamp - self._last_seen).total_seconds()) > 5 # noqa: PLR2004
429429

430430
):
431431
self._last_seen = timestamp
@@ -659,7 +659,7 @@ def _get_cache_as_datetime(self, setting: str) -> datetime | None:
659659
"""Retrieve value of specified setting from cache memory and return it as datetime object."""
660660
if (timestamp_str := self._get_cache(setting)) is not None:
661661
data = timestamp_str.split("-")
662-
if len(data) == 6:
662+
if len(data) == 6: # noqa: PLR2004
663663
try:
664664
return datetime(
665665
year=int(data[0]),

plugwise_usb/nodes/scan.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from ..api import MotionConfig, MotionSensitivity, MotionState, NodeEvent, NodeFeature
1313
from ..connection import StickController
14+
from ..constants import MAX_UINT_2
1415
from ..exceptions import MessageError, NodeError, NodeTimeout
1516
from ..messages.requests import ScanConfigureRequest, ScanLightCalibrateRequest
1617
from ..messages.responses import (
@@ -306,7 +307,7 @@ async def set_motion_reset_timer(self, minutes: int) -> bool:
306307
self._motion_config.reset_timer,
307308
minutes,
308309
)
309-
if minutes < 1 or minutes > 255:
310+
if minutes < 1 or minutes > MAX_UINT_2:
310311
raise ValueError(
311312
f"Invalid motion reset timer ({minutes}). It must be between 1 and 255 minutes."
312313
)

plugwise_usb/nodes/sed.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from ..api import BatteryConfig, NodeEvent, NodeFeature, NodeInfo
2121
from ..connection import StickController
22+
from ..constants import MAX_UINT_2, MAX_UINT_4
2223
from ..exceptions import MessageError, NodeError
2324
from ..messages.requests import NodeSleepConfigRequest
2425
from ..messages.responses import (
@@ -63,6 +64,8 @@
6364
# Time in minutes the SED will sleep
6465
SED_DEFAULT_SLEEP_DURATION: Final = 60
6566

67+
# Value limits
68+
MAX_MINUTE_INTERVAL: Final = 1440
6669

6770
_LOGGER = logging.getLogger(__name__)
6871

@@ -232,7 +235,7 @@ async def set_awake_duration(self, seconds: int) -> bool:
232235
self._battery_config.awake_duration,
233236
seconds,
234237
)
235-
if seconds < 1 or seconds > 255:
238+
if seconds < 1 or seconds > MAX_UINT_2:
236239
raise ValueError(
237240
f"Invalid awake duration ({seconds}). It must be between 1 and 255 seconds."
238241
)
@@ -262,7 +265,7 @@ async def set_clock_interval(self, minutes: int) -> bool:
262265
self._battery_config.clock_interval,
263266
minutes,
264267
)
265-
if minutes < 1 or minutes > 65535:
268+
if minutes < 1 or minutes > MAX_UINT_4:
266269
raise ValueError(
267270
f"Invalid clock interval ({minutes}). It must be between 1 and 65535 minutes."
268271
)
@@ -315,7 +318,7 @@ async def set_maintenance_interval(self, minutes: int) -> bool:
315318
self._battery_config.maintenance_interval,
316319
minutes,
317320
)
318-
if minutes < 1 or minutes > 1440:
321+
if minutes < 1 or minutes > MAX_MINUTE_INTERVAL:
319322
raise ValueError(
320323
f"Invalid maintenance interval ({minutes}). It must be between 1 and 1440 minutes."
321324
)
@@ -348,7 +351,7 @@ async def set_sleep_duration(self, minutes: int) -> bool:
348351
self._battery_config.sleep_duration,
349352
minutes,
350353
)
351-
if minutes < 1 or minutes > 65535:
354+
if minutes < 1 or minutes > MAX_UINT_4:
352355
raise ValueError(
353356
f"Invalid sleep duration ({minutes}). It must be between 1 and 65535 minutes."
354357
)

plugwise_usb/nodes/sense.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
# Sense calculations
2121
SENSE_HUMIDITY_MULTIPLIER: Final = 125
2222
SENSE_HUMIDITY_OFFSET: Final = 6
23+
SENSE_HUMIDITY_LIMIT: Final = 65535
2324
SENSE_TEMPERATURE_MULTIPLIER: Final = 175.72
2425
SENSE_TEMPERATURE_OFFSET: Final = 46.85
26+
SENSE_TEMPERATURE_LIMIT: Final = 65535
2527

2628
SENSE_FEATURES: Final = (
2729
NodeFeature.INFO,
@@ -111,14 +113,14 @@ async def _sense_report(self, response: PlugwiseResponse) -> bool:
111113
)
112114
report_received = False
113115
await self._available_update_state(True, response.timestamp)
114-
if response.temperature.value != 65535:
116+
if response.temperature.value != SENSE_TEMPERATURE_LIMIT:
115117
self._sense_statistics.temperature = float(
116118
SENSE_TEMPERATURE_MULTIPLIER * (response.temperature.value / 65536)
117119
- SENSE_TEMPERATURE_OFFSET
118120
)
119121
report_received = True
120122

121-
if response.humidity.value != 65535:
123+
if response.humidity.value != SENSE_HUMIDITY_LIMIT:
122124
self._sense_statistics.humidity = float(
123125
SENSE_HUMIDITY_MULTIPLIER * (response.humidity.value / 65536)
124126
- SENSE_HUMIDITY_OFFSET

0 commit comments

Comments
 (0)