|
19 | 19 |
|
20 | 20 | from ..api import BatteryConfig, NodeEvent, NodeFeature, NodeInfo |
21 | 21 | from ..connection import StickController |
| 22 | +from ..constants import MAX_UINT_2, MAX_UINT_4 |
22 | 23 | from ..exceptions import MessageError, NodeError |
23 | 24 | from ..messages.requests import NodeSleepConfigRequest |
24 | 25 | from ..messages.responses import ( |
|
63 | 64 | # Time in minutes the SED will sleep |
64 | 65 | SED_DEFAULT_SLEEP_DURATION: Final = 60 |
65 | 66 |
|
| 67 | +# Value limits |
| 68 | +MAX_MINUTE_INTERVAL: Final = 1440 |
66 | 69 |
|
67 | 70 | _LOGGER = logging.getLogger(__name__) |
68 | 71 |
|
@@ -232,7 +235,7 @@ async def set_awake_duration(self, seconds: int) -> bool: |
232 | 235 | self._battery_config.awake_duration, |
233 | 236 | seconds, |
234 | 237 | ) |
235 | | - if seconds < 1 or seconds > 255: |
| 238 | + if seconds < 1 or seconds > MAX_UINT_2: |
236 | 239 | raise ValueError( |
237 | 240 | f"Invalid awake duration ({seconds}). It must be between 1 and 255 seconds." |
238 | 241 | ) |
@@ -262,7 +265,7 @@ async def set_clock_interval(self, minutes: int) -> bool: |
262 | 265 | self._battery_config.clock_interval, |
263 | 266 | minutes, |
264 | 267 | ) |
265 | | - if minutes < 1 or minutes > 65535: |
| 268 | + if minutes < 1 or minutes > MAX_UINT_4: |
266 | 269 | raise ValueError( |
267 | 270 | f"Invalid clock interval ({minutes}). It must be between 1 and 65535 minutes." |
268 | 271 | ) |
@@ -315,7 +318,7 @@ async def set_maintenance_interval(self, minutes: int) -> bool: |
315 | 318 | self._battery_config.maintenance_interval, |
316 | 319 | minutes, |
317 | 320 | ) |
318 | | - if minutes < 1 or minutes > 1440: |
| 321 | + if minutes < 1 or minutes > MAX_MINUTE_INTERVAL: |
319 | 322 | raise ValueError( |
320 | 323 | f"Invalid maintenance interval ({minutes}). It must be between 1 and 1440 minutes." |
321 | 324 | ) |
@@ -348,7 +351,7 @@ async def set_sleep_duration(self, minutes: int) -> bool: |
348 | 351 | self._battery_config.sleep_duration, |
349 | 352 | minutes, |
350 | 353 | ) |
351 | | - if minutes < 1 or minutes > 65535: |
| 354 | + if minutes < 1 or minutes > MAX_UINT_4: |
352 | 355 | raise ValueError( |
353 | 356 | f"Invalid sleep duration ({minutes}). It must be between 1 and 65535 minutes." |
354 | 357 | ) |
|
0 commit comments