@@ -95,8 +95,11 @@ async def async_turn_off(self, **kwargs: Any) -> None:
9595
9696 async def async_update (self ) -> None :
9797 """Update the state of the entity."""
98- await self .device_connection .request_status_output (
99- self .output , SCAN_INTERVAL .seconds
98+ self ._attr_available = (
99+ await self .device_connection .request_status_output (
100+ self .output , SCAN_INTERVAL .seconds
101+ )
102+ is not None
100103 )
101104
102105 def input_received (self , input_obj : InputType ) -> None :
@@ -106,7 +109,7 @@ def input_received(self, input_obj: InputType) -> None:
106109 or input_obj .get_output_id () != self .output .value
107110 ):
108111 return
109-
112+ self . _attr_available = True
110113 self ._attr_is_on = input_obj .get_percent () > 0
111114 self .async_write_ha_state ()
112115
@@ -142,13 +145,16 @@ async def async_turn_off(self, **kwargs: Any) -> None:
142145
143146 async def async_update (self ) -> None :
144147 """Update the state of the entity."""
145- await self .device_connection .request_status_relays (SCAN_INTERVAL .seconds )
148+ self ._attr_available = (
149+ await self .device_connection .request_status_relays (SCAN_INTERVAL .seconds )
150+ is not None
151+ )
146152
147153 def input_received (self , input_obj : InputType ) -> None :
148154 """Set switch state when LCN input object (command) is received."""
149155 if not isinstance (input_obj , pypck .inputs .ModStatusRelays ):
150156 return
151-
157+ self . _attr_available = True
152158 self ._attr_is_on = input_obj .get_state (self .output .value )
153159 self .async_write_ha_state ()
154160
@@ -183,8 +189,11 @@ async def async_turn_off(self, **kwargs: Any) -> None:
183189
184190 async def async_update (self ) -> None :
185191 """Update the state of the entity."""
186- await self .device_connection .request_status_variable (
187- self .setpoint_variable , SCAN_INTERVAL .seconds
192+ self ._attr_available = (
193+ await self .device_connection .request_status_variable (
194+ self .setpoint_variable , SCAN_INTERVAL .seconds
195+ )
196+ is not None
188197 )
189198
190199 def input_received (self , input_obj : InputType ) -> None :
@@ -194,7 +203,7 @@ def input_received(self, input_obj: InputType) -> None:
194203 or input_obj .get_var () != self .setpoint_variable
195204 ):
196205 return
197-
206+ self . _attr_available = True
198207 self ._attr_is_on = input_obj .get_value ().is_locked_regulator ()
199208 self .async_write_ha_state ()
200209
@@ -236,7 +245,12 @@ async def async_turn_off(self, **kwargs: Any) -> None:
236245
237246 async def async_update (self ) -> None :
238247 """Update the state of the entity."""
239- await self .device_connection .request_status_locked_keys (SCAN_INTERVAL .seconds )
248+ self ._attr_available = (
249+ await self .device_connection .request_status_locked_keys (
250+ SCAN_INTERVAL .seconds
251+ )
252+ is not None
253+ )
240254
241255 def input_received (self , input_obj : InputType ) -> None :
242256 """Set switch state when LCN input object (command) is received."""
@@ -245,6 +259,6 @@ def input_received(self, input_obj: InputType) -> None:
245259 or self .key not in pypck .lcn_defs .Key
246260 ):
247261 return
248-
262+ self . _attr_available = True
249263 self ._attr_is_on = input_obj .get_state (self .table_id , self .key_id )
250264 self .async_write_ha_state ()
0 commit comments