Skip to content

Commit 7ae404a

Browse files
committed
Add constants and use
1 parent 71a8593 commit 7ae404a

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

plugwise_usb/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from .api import NodeEvent, PlugwiseNode, StickEvent
1616
from .connection import StickController
17+
from .const import DEFAULT_CONS_INTERVAL, NO_PRODUCTION_INTERVAL
1718
from .exceptions import MessageError, NodeError, StickError, SubscriptionError
1819
from .network import StickNetwork
1920

@@ -219,7 +220,11 @@ async def energy_reset_request(self, mac: str) -> bool:
219220
raise NodeError(f"{exc}") from exc
220221

221222
# Follow up by an energy-intervals (re)set
222-
if (result := await self.set_energy_intervals(mac, 60, 0)):
223+
if (
224+
result := await self.set_energy_intervals(
225+
mac, DEFAULT_CONS_INTERVAL, NO_PRODUCTION_INTERVAL
226+
)
227+
):
223228
return result
224229

225230
return False

plugwise_usb/constants.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
# Max timeout in seconds
3333
# Stick responds with timeout messages within 10s.
34-
STICK_TIME_OUT: Final = 11
34+
STICK_TIME_OUT: Final = 11
3535
# In bigger networks a response from a Node could take up a while, so lets use 15 seconds.
3636
NODE_TIME_OUT: Final = 15
3737

@@ -99,3 +99,10 @@
9999
8: ("Celsius",),
100100
9: ("Stealth",),
101101
}
102+
103+
# Energy logging intervals
104+
DEFAULT_CONS_INTERVAL: Final[int] = 60
105+
NO_PRODUCTION_INTERVAL: Final[int] = 0
106+
107+
# Energy Node types
108+
ENERGY_NODE_TYPES: tuple[int] = (1, 2, 9)

plugwise_usb/network/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
from ..api import NodeEvent, NodeType, PlugwiseNode, StickEvent
1414
from ..connection import StickController
15-
from ..constants import UTF8
16-
from ..helpers.util import validate_mac
15+
from ..constants import ENERGY_NODE_TYPES, UTF8
1716
from ..exceptions import CacheError, MessageError, NodeError, StickError, StickTimeout
17+
from ..helpers.util import validate_mac
1818
from ..messages.requests import (
1919
CircleClockSetRequest,
2020
CircleMeasureIntervalRequest,
@@ -34,8 +34,6 @@
3434
from ..nodes import get_plugwise_node
3535
from .registry import StickNetworkRegister
3636

37-
ENERGY_NODE_TYPES: tuple[int] = (1, 2, 9)
38-
3937
_LOGGER = logging.getLogger(__name__)
4038
# endregion
4139

@@ -596,10 +594,10 @@ def _validate_energy_node(self, mac: str) -> None:
596594
"""Validate node for energy operations."""
597595
if not validate_mac(mac):
598596
raise NodeError(f"MAC '{mac}' invalid")
599-
597+
600598
if mac not in self._nodes:
601599
raise NodeError(f"Node {mac} not present in network")
602-
600+
603601
if self._nodes[mac].node_info.node_type.value not in ENERGY_NODE_TYPES:
604602
raise NodeError(
605603
f"Energy operations not supported for {self._nodes[mac].node_info.node_type.name}"

0 commit comments

Comments
 (0)