File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed
custom_components/teslemetry Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -259,7 +259,10 @@ async def async_added_to_hass(self) -> None:
259259 """Handle entity which will be added."""
260260 await super ().async_added_to_hass ()
261261 if (state := await self .async_get_last_state ()) is not None :
262- self ._attr_hvac_mode = HVACMode (state .state ) if (state .state and state .state != "unknown" ) else None
262+ try :
263+ self ._attr_hvac_mode = HVACMode (state .state )
264+ except ValueError :
265+ self ._attr_hvac_mode = None
263266 self ._attr_current_temperature = state .attributes .get ('current_temperature' )
264267 self ._attr_target_temperature = state .attributes .get ('target_temperature' )
265268 #self._attr_fan_mode = state.attributes.get('fan_mode')
Original file line number Diff line number Diff line change @@ -185,7 +185,10 @@ async def async_added_to_hass(self) -> None:
185185
186186 await super ().async_added_to_hass ()
187187 if (state := await self .async_get_last_state ()) is not None :
188- self ._attr_state = None if state .state == "Unknown" else MediaPlayerState (state .state )
188+ try :
189+ self ._attr_state = MediaPlayerState (state .state )
190+ except ValueError :
191+ self ._attr_state = None
189192 self ._attr_volume_level = state .attributes .get ("volume_level" )
190193 self ._attr_media_title = state .attributes .get ("media_title" )
191194 self ._attr_media_artist = state .attributes .get ("media_artist" )
You can’t perform that action at this time.
0 commit comments