Protect against an exception in Shelly climate platform (#77102)

Check if state in HVACMode
This commit is contained in:
Maciej Bieniek 2022-08-22 09:03:32 +02:00 committed by GitHub
parent 8b46174667
commit e03eb238e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -188,7 +188,10 @@ class BlockSleepingClimate(
def hvac_mode(self) -> HVACMode:
"""HVAC current mode."""
if self.device_block is None:
return HVACMode(self.last_state.state) if self.last_state else HVACMode.OFF
if self.last_state and self.last_state.state in list(HVACMode):
return HVACMode(self.last_state.state)
return HVACMode.OFF
if self.device_block.mode is None or self._check_is_off():
return HVACMode.OFF