Skip to content

Commit 06a544a

Browse files
committed
More fixes and improvements
1 parent 4fb4872 commit 06a544a

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

plugwise_usb/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ async def set_accept_join_request(self, state: bool) -> bool:
212212

213213
async def energy_reset_request(self, mac: str) -> bool:
214214
"""Send an energy-reset request to a Node."""
215+
_LOGGER.debug("Resetting energy logs for %s", mac)
215216
try:
216217
await self._network.energy_reset_request(mac)
217218
except (MessageError, NodeError) as exc:

plugwise_usb/messages/requests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ def __init__(
764764
day_of_week = Int(dt.weekday(), 2)
765765
if reset:
766766
self._args += [
767-
this_date,
767+
this_date,
768768
LogAddr(0, 8, False),
769769
this_time,
770770
day_of_week,

plugwise_usb/network/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from ..api import NodeEvent, NodeType, PlugwiseNode, StickEvent
1414
from ..connection import StickController
1515
from ..constants import UTF8
16+
from ..helpers.util import validate_mac
1617
from ..exceptions import CacheError, MessageError, NodeError, StickError, StickTimeout
1718
from ..messages.requests import (
1819
CircleClockSetRequest,
@@ -546,6 +547,12 @@ async def allow_join_requests(self, state: bool) -> None:
546547

547548
async def energy_reset_request(self, mac: str) -> None:
548549
"""Send an energy-reset to a Node."""
550+
if not validate_mac(mac):
551+
raise NodeError(f"MAC '{mac}' invalid")
552+
553+
if mac not in self._nodes:
554+
raise NodeError(f"Node {mac} not present in network")
555+
549556
if self._nodes[mac].node_info.node_type.value not in ENERGY_NODE_TYPES:
550557
raise NodeError(
551558
f"Energy-resetting not supported for {self._nodes[mac].node_info.node_type.name}"
@@ -575,6 +582,12 @@ async def set_energy_intervals(
575582
Default: consumption = 60, production = 0.
576583
For logging energy in both directions set both to 60.
577584
"""
585+
if not validate_mac(mac):
586+
raise NodeError(f"MAC '{mac}' invalid")
587+
588+
if mac not in self._nodes:
589+
raise NodeError(f"Node {mac} not present in network")
590+
578591
if self._nodes[mac].node_info.node_type.value not in ENERGY_NODE_TYPES:
579592
raise NodeError(
580593
f"Setting energy-intervals not supported for {self._nodes[mac].node_info.node_type.name}"

0 commit comments

Comments
 (0)