Skip to content

Commit 441ab67

Browse files
committed
Update NodeSleepConfigRequest
1 parent 1cec057 commit 441ab67

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

plugwise_usb/messages/requests.py

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,60 +1203,65 @@ class CircleHandlesOnRequest(PlugwiseRequest):
12031203
class NodeSleepConfigRequest(PlugwiseRequest):
12041204
"""Configure timers for SED nodes to minimize battery usage.
12051205
1206-
stay_active : Duration in seconds the SED will be
1207-
awake for receiving commands
1208-
sleep_for : Duration in minutes the SED will be
1209-
in sleeping mode and not able to respond
1210-
any command
1211-
maintenance_interval : Interval in minutes the node will wake up
1212-
and able to receive commands
1213-
clock_sync : Enable/disable clock sync
1214-
clock_interval : Duration in minutes the node synchronize
1215-
its clock
1216-
1217-
Response message: NodeAckResponse with SLEEP_SET
1206+
Description:
1207+
Response message: NodeResponse with SLEEP_SET
1208+
1209+
Args:
1210+
send_fn: Send function
1211+
mac: MAC address of the node
1212+
awake_duration: Duration in seconds the SED will be awake for receiving commands
1213+
sleep_for: Duration in minutes the SED will be in sleeping mode and not able to respond any command
1214+
maintenance_interval: Interval in minutes the node will wake up and able to receive commands
1215+
sync_clock: Enable/disable clock sync
1216+
clock_interval: Duration in minutes the node synchronize its clock
1217+
12181218
"""
12191219

12201220
_identifier = b"0050"
1221-
_reply_identifier = b"0100"
1221+
_reply_identifier = b"0000"
12221222

12231223
def __init__(
12241224
self,
12251225
send_fn: Callable[[PlugwiseRequest, bool], Awaitable[PlugwiseResponse | None]],
12261226
mac: bytes,
1227-
stay_active: int,
1227+
awake_duration: int,
12281228
maintenance_interval: int,
1229-
sleep_for: int,
1229+
sleep_duration: int,
12301230
sync_clock: bool,
12311231
clock_interval: int,
12321232
):
12331233
"""Initialize NodeSleepConfigRequest message object."""
12341234
super().__init__(send_fn, mac)
1235-
stay_active_val = Int(stay_active, length=2)
1236-
sleep_for_val = Int(sleep_for, length=4)
1237-
maintenance_interval_val = Int(maintenance_interval, length=4)
1235+
self.awake_duration_val = Int(awake_duration, length=2)
1236+
self.sleep_duration_val = Int(sleep_duration, length=4)
1237+
self.maintenance_interval_val = Int(maintenance_interval, length=4)
12381238
val = 1 if sync_clock else 0
1239-
clock_sync_val = Int(val, length=2)
1240-
clock_interval_val = Int(clock_interval, length=4)
1239+
self.clock_sync_val = Int(val, length=2)
1240+
self.clock_interval_val = Int(clock_interval, length=4)
12411241
self._args += [
1242-
stay_active_val,
1243-
maintenance_interval_val,
1244-
sleep_for_val,
1245-
clock_sync_val,
1246-
clock_interval_val,
1242+
self.awake_duration_val,
1243+
self.maintenance_interval_val,
1244+
self.sleep_duration_val,
1245+
self.clock_sync_val,
1246+
self.clock_interval_val,
12471247
]
12481248

1249-
async def send(self, suppress_node_errors: bool = False) -> NodeAckResponse | None:
1249+
async def send(self, suppress_node_errors: bool = False) -> NodeResponse | None:
12501250
"""Send request."""
12511251
result = await self._send_request(suppress_node_errors)
1252-
if isinstance(result, NodeAckResponse):
1252+
_LOGGER.warning("NodeSleepConfigRequest result: %s", result)
1253+
if isinstance(result, NodeResponse):
12531254
return result
12541255
if result is None:
12551256
return None
12561257
raise MessageError(
12571258
f"Invalid response message. Received {result.__class__.__name__}, expected NodeAckResponse"
12581259
)
12591260

1261+
def __repr__(self) -> str:
1262+
"""Convert request into writable str."""
1263+
return f"{super().__repr__()[:-1]}, awake_duration={self.awake_duration_val.value}, maintenance_interval={self.maintenance_interval_val.value}, sleep_duration={self.sleep_duration_val.value}, clock_interval={self.clock_interval_val.value}, clock_sync={self.clock_sync_val.value})"
1264+
12601265

12611266
class NodeSelfRemoveRequest(PlugwiseRequest):
12621267
"""TODO: Remove node?.

0 commit comments

Comments
 (0)