From 4b449f5f93aa41f7be1d7d23f2223587bb16551f Mon Sep 17 00:00:00 2001 From: Phil Cole Date: Mon, 24 Jul 2017 08:48:20 +0200 Subject: [PATCH] Tado Fix #8606 (#8621) Handle case where 'mode' and 'fanSpeed' are missing JSON. Based on changes in commit https://github.com/wmalgadey/tado_component/commit/adfb608f86b8bf4c1c43e71b4067cbfe1de9ba85 --- homeassistant/components/climate/tado.py | 47 ++++++++++++++---------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/climate/tado.py b/homeassistant/components/climate/tado.py index 8a2e6621af3..459cbec0497 100644 --- a/homeassistant/components/climate/tado.py +++ b/homeassistant/components/climate/tado.py @@ -273,31 +273,38 @@ class TadoClimate(ClimateDevice): else: self._device_is_active = True + overlay = False + overlay_data = None + termination = self._current_operation + cooling = False + fan_speed = CONST_MODE_OFF + + if 'overlay' in data: + overlay_data = data['overlay'] + overlay = overlay_data is not None + + if overlay: + termination = overlay_data['termination']['type'] + + if 'setting' in overlay_data: + setting_data = overlay_data['setting'] + setting = setting is not None + + if setting: + if 'mode' in setting_data: + cooling = setting_data['mode'] == 'COOL' + + if 'fanSpeed' in setting_data: + fan_speed = setting_data['fanSpeed'] + if self._device_is_active: - overlay = False - overlay_data = None - termination = self._current_operation - cooling = False - fan_speed = CONST_MODE_OFF - - if 'overlay' in data: - overlay_data = data['overlay'] - overlay = overlay_data is not None - - if overlay: - termination = overlay_data['termination']['type'] - - if 'setting' in overlay_data: - cooling = overlay_data['setting']['mode'] == 'COOL' - fan_speed = overlay_data['setting']['fanSpeed'] - # If you set mode manualy to off, there will be an overlay # and a termination, but we want to see the mode "OFF" - self._overlay_mode = termination self._current_operation = termination - self._cooling = cooling - self._current_fan = fan_speed + + self._cooling = cooling + self._current_fan = fan_speed def _control_heating(self): """Send new target temperature to mytado."""