Skip to content

Commit 38808f9

Browse files
committed
And implement
1 parent 8b34bc8 commit 38808f9

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

plugwise_usb/nodes/node.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,10 @@ def switch(self) -> bool:
315315
@raise_not_loaded
316316
def sense(self) -> SenseStatistics:
317317
"""Sense statistics."""
318-
if NodeFeature.TEMPERATURE not in self._features:
318+
if NodeFeature.SENSE not in self._features:
319319
raise FeatureError(
320-
f"Temperature state is not supported for node {self.mac}"
320+
f"Sense statistics is not supported for node {self.mac}"
321321
)
322-
if NodeFeature.HUMIDITY not in self._features:
323-
raise FeatureError(f"Humidity state is not supported for node {self.mac}")
324-
raise NotImplementedError()
325322

326323
# endregion
327324

plugwise_usb/nodes/sense.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525

2626
SENSE_FEATURES: Final = (
2727
NodeFeature.INFO,
28-
NodeFeature.TEMPERATURE,
29-
NodeFeature.HUMIDITY,
28+
NodeFeature.SENSE,
3029
)
3130

3231

@@ -61,7 +60,7 @@ async def load(self) -> bool:
6160
self._loaded = True
6261
self._setup_protocol(
6362
SENSE_FIRMWARE_SUPPORT,
64-
(NodeFeature.INFO, NodeFeature.TEMPERATURE, NodeFeature.HUMIDITY),
63+
(NodeFeature.INFO, NodeFeature.SENSE),
6564
)
6665
if await self.initialize():
6766
await self._loaded_callback(NodeEvent.LOADED, self.mac)
@@ -114,29 +113,26 @@ async def _sense_report(self, response: PlugwiseResponse) -> bool:
114113
raise MessageError(
115114
f"Invalid response message type ({response.__class__.__name__}) received, expected SenseReportResponse"
116115
)
117-
report_received = False
116+
report_received_1 = report_received_2 = False
118117
await self._available_update_state(True, response.timestamp)
119118
if response.temperature.value != 65535:
120119
self._sense_statistics.temperature = float(
121120
SENSE_TEMPERATURE_MULTIPLIER * (response.temperature.value / 65536)
122121
- SENSE_TEMPERATURE_OFFSET
123122
)
124-
await self.publish_feature_update_to_subscribers(
125-
NodeFeature.TEMPERATURE, self._sense_statistics
126-
)
127-
report_received = True
123+
report_received_1 = True
128124

129125
if response.humidity.value != 65535:
130126
self._sense_statistics.humidity = float(
131127
SENSE_HUMIDITY_MULTIPLIER * (response.humidity.value / 65536)
132128
- SENSE_HUMIDITY_OFFSET
133129
)
134130
await self.publish_feature_update_to_subscribers(
135-
NodeFeature.HUMIDITY, self._sense_statistics
131+
NodeFeature.SENSE, self._sense_statistics
136132
)
137-
report_received = True
133+
report_received_2 = True
138134

139-
return report_received
135+
return report_received_1 and report_received_2
140136

141137
@raise_not_loaded
142138
async def get_state(self, features: tuple[NodeFeature]) -> dict[NodeFeature, Any]:
@@ -154,12 +150,10 @@ async def get_state(self, features: tuple[NodeFeature]) -> dict[NodeFeature, Any
154150
)
155151

156152
match feature:
157-
case NodeFeature.TEMPERATURE:
158-
states[NodeFeature.TEMPERATURE] = self._sense_statistics
159-
case NodeFeature.HUMIDITY:
160-
states[NodeFeature.HUMIDITY] = self._sense_statistics
161153
case NodeFeature.PING:
162154
states[NodeFeature.PING] = await self.ping_update()
155+
case NodeFeature.SENSE:
156+
states[NodeFeature.TEMPERATURE] = self._sense_statistics
163157
case _:
164158
state_result = await super().get_state((feature,))
165159
states[feature] = state_result[feature]

0 commit comments

Comments
 (0)