Skip to content

Commit

Permalink
Add exception check to read climate data
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Dec 17, 2020
1 parent 99ac63b commit b150b98
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions custom_components/xiaomi_gateway3/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from . import DOMAIN, Gateway3Device
from .core.gateway3 import Gateway3

_LOGGER = logging.getLogger(__name__)

HVAC_MODES = [HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_OFF]
FAN_MODES = [FAN_LOW, FAN_MEDIUM, FAN_HIGH, FAN_AUTO]

Expand Down Expand Up @@ -76,18 +78,22 @@ def supported_features(self):
return SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE

def update(self, data: dict = None):
if 'power' in data: # 0 - off, 1 - on
self._is_on = data['power']
if 'mode' in data: # 0 - heat, 1 - cool
self._hvac_mode = HVAC_MODES[data['mode']]
if 'fan_mode' in data: # 0 - low, 3 - auto
self._fan_mode = FAN_MODES[data['fan_mode']]
if 'current_temperature' in data:
self._current_temp = data['current_temperature']
if 'target_temperature' in data:
self._target_temp = data['target_temperature']
if self._attr in data:
self._state = bytearray(data[self._attr].to_bytes(4, 'big'))
try:
if 'power' in data: # 0 - off, 1 - on
self._is_on = data['power']
if 'mode' in data: # 0 - heat, 1 - cool
self._hvac_mode = HVAC_MODES[data['mode']]
if 'fan_mode' in data: # 0 - low, 3 - auto
self._fan_mode = FAN_MODES[data['fan_mode']]
if 'current_temperature' in data:
self._current_temp = data['current_temperature']
if 'target_temperature' in data:
self._target_temp = data['target_temperature']
if self._attr in data:
self._state = bytearray(data[self._attr].to_bytes(4, 'big'))
except:
_LOGGER.exception(f"Can't read climate data: {data}")

self.async_write_ha_state()

def set_temperature(self, **kwargs) -> None:
Expand Down

0 comments on commit b150b98

Please sign in to comment.