22
33from __future__ import annotations
44
5- from collections .abc import Callable
5+ from collections .abc import Awaitable , Callable
66import logging
77from typing import Any , Final
88
99from ..api import NodeEvent , NodeFeature
10+ from ..connection import StickController
1011from ..exceptions import MessageError , NodeError
1112from ..messages .responses import SENSE_REPORT_ID , PlugwiseResponse , SenseReportResponse
1213from ..nodes .sed import NodeSED
3233class PlugwiseSense (NodeSED ):
3334 """Plugwise Sense node."""
3435
35- _sense_subscription : Callable [[], None ] | None = None
36+ def __init__ (
37+ self ,
38+ mac : str ,
39+ address : int ,
40+ controller : StickController ,
41+ loaded_callback : Callable [[NodeEvent , str ], Awaitable [None ]],
42+ ):
43+ """Initialize Scan Device."""
44+ super ().__init__ (mac , address , controller , loaded_callback )
45+
46+ self ._humidity : float | None = None
47+ self ._temperature : float | None = None
48+
49+ self ._sense_subscription : Callable [[], None ] | None = None
3650
3751 async def load (self ) -> bool :
3852 """Load and activate Sense node features."""
@@ -58,7 +72,7 @@ async def initialize(self) -> bool:
5872 """Initialize Sense node."""
5973 if self ._initialized :
6074 return True
61- self ._sense_subscription = self ._message_subscribe (
75+ self ._sense_subscription = await self ._message_subscribe (
6276 self ._sense_report ,
6377 self ._mac_in_bytes ,
6478 (SENSE_REPORT_ID ,),
@@ -78,7 +92,7 @@ async def _sense_report(self, response: PlugwiseResponse) -> bool:
7892 raise MessageError (
7993 f"Invalid response message type ({ response .__class__ .__name__ } ) received, expected SenseReportResponse"
8094 )
81- await self ._available_update_state (True )
95+ await self ._available_update_state (True , response . timestamp )
8296 if response .temperature .value != 65535 :
8397 self ._temperature = int (
8498 SENSE_TEMPERATURE_MULTIPLIER * (response .temperature .value / 65536 )
@@ -121,6 +135,6 @@ async def get_state(self, features: tuple[NodeFeature]) -> dict[NodeFeature, Any
121135 else :
122136 state_result = await super ().get_state ((feature ,))
123137 states [feature ] = state_result [feature ]
124-
125- states [NodeFeature .AVAILABLE ] = self ._available
138+ if NodeFeature . AVAILABLE not in states :
139+ states [NodeFeature .AVAILABLE ] = self .available_state
126140 return states
0 commit comments