diff --git a/homeassistant/components/daikin/climate.py b/homeassistant/components/daikin/climate.py index 284776bc671..25bddc29b46 100644 --- a/homeassistant/components/daikin/climate.py +++ b/homeassistant/components/daikin/climate.py @@ -1,21 +1,17 @@ """Support for the Daikin HVAC.""" import logging -import re import voluptuous as vol from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateDevice +from homeassistant.components.climate.const import ( + ATTR_FAN_MODE, ATTR_HVAC_MODE, ATTR_PRESET_MODE, ATTR_SWING_MODE, + HVAC_MODE_COOL, HVAC_MODE_DRY, HVAC_MODE_FAN_ONLY, HVAC_MODE_HEAT, + HVAC_MODE_HEAT_COOL, HVAC_MODE_OFF, PRESET_AWAY, PRESET_NONE, + SUPPORT_FAN_MODE, SUPPORT_PRESET_MODE, SUPPORT_SWING_MODE, + SUPPORT_TARGET_TEMPERATURE) from homeassistant.const import ( ATTR_TEMPERATURE, CONF_HOST, CONF_NAME, TEMP_CELSIUS) -from homeassistant.components.climate.const import ( - SUPPORT_TARGET_TEMPERATURE, SUPPORT_FAN_MODE, SUPPORT_PRESET_MODE, - SUPPORT_SWING_MODE, - HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_HEAT_COOL, - HVAC_MODE_DRY, HVAC_MODE_FAN_ONLY, - PRESET_AWAY, PRESET_NONE, - ATTR_CURRENT_TEMPERATURE, ATTR_FAN_MODE, - ATTR_HVAC_MODE, ATTR_SWING_MODE, - ATTR_PRESET_MODE) import homeassistant.helpers.config_validation as cv from . import DOMAIN as DAIKIN_DOMAIN @@ -110,57 +106,6 @@ class DaikinClimate(ClimateDevice): if self._api.device.support_swing_mode: self._supported_features |= SUPPORT_SWING_MODE - def get(self, key): - """Retrieve device settings from API library cache.""" - value = None - cast_to_float = False - - if key in [ATTR_TEMPERATURE, ATTR_INSIDE_TEMPERATURE, - ATTR_CURRENT_TEMPERATURE]: - key = ATTR_INSIDE_TEMPERATURE - - daikin_attr = HA_ATTR_TO_DAIKIN.get(key) - - if key == ATTR_INSIDE_TEMPERATURE: - value = self._api.device.values.get(daikin_attr) - cast_to_float = True - elif key == ATTR_TARGET_TEMPERATURE: - value = self._api.device.values.get(daikin_attr) - cast_to_float = True - elif key == ATTR_OUTSIDE_TEMPERATURE: - value = self._api.device.values.get(daikin_attr) - cast_to_float = True - elif key == ATTR_FAN_MODE: - value = self._api.device.represent(daikin_attr)[1].title() - elif key == ATTR_SWING_MODE: - value = self._api.device.represent(daikin_attr)[1].title() - elif key == ATTR_HVAC_MODE: - # Daikin can return also internal states auto-1 or auto-7 - # and we need to translate them as AUTO - daikin_mode = re.sub( - '[^a-z]', '', - self._api.device.represent(daikin_attr)[1]) - ha_mode = DAIKIN_TO_HA_STATE.get(daikin_mode) - value = ha_mode - elif key == ATTR_PRESET_MODE: - if self._api.device.represent( - daikin_attr)[1] == HA_PRESET_TO_DAIKIN[PRESET_AWAY]: - return PRESET_AWAY - return PRESET_NONE - - if value is None: - _LOGGER.error("Invalid value requested for key %s", key) - else: - if value in ("-", "--"): - value = None - elif cast_to_float: - try: - value = float(value) - except ValueError: - value = None - - return value - async def _set(self, settings): """Set device settings using API.""" values = {} @@ -183,7 +128,8 @@ class DaikinClimate(ClimateDevice): # temperature elif attr == ATTR_TEMPERATURE: try: - values['stemp'] = str(int(value)) + values[HA_ATTR_TO_DAIKIN[ATTR_TARGET_TEMPERATURE]] = \ + str(int(value)) except ValueError: _LOGGER.error("Invalid temperature %s", value) @@ -213,12 +159,12 @@ class DaikinClimate(ClimateDevice): @property def current_temperature(self): """Return the current temperature.""" - return self.get(ATTR_CURRENT_TEMPERATURE) + return self._api.device.inside_temperature @property def target_temperature(self): """Return the temperature we try to reach.""" - return self.get(ATTR_TARGET_TEMPERATURE) + return self._api.device.target_temperature @property def target_temperature_step(self): @@ -232,7 +178,9 @@ class DaikinClimate(ClimateDevice): @property def hvac_mode(self): """Return current operation ie. heat, cool, idle.""" - return self.get(ATTR_HVAC_MODE) + daikin_mode = self._api.device.represent( + HA_ATTR_TO_DAIKIN[ATTR_HVAC_MODE])[1] + return DAIKIN_TO_HA_STATE.get(daikin_mode, HVAC_MODE_HEAT_COOL) @property def hvac_modes(self): @@ -246,7 +194,8 @@ class DaikinClimate(ClimateDevice): @property def fan_mode(self): """Return the fan setting.""" - return self.get(ATTR_FAN_MODE) + return self._api.device.represent( + HA_ATTR_TO_DAIKIN[ATTR_FAN_MODE])[1].title() async def async_set_fan_mode(self, fan_mode): """Set fan mode.""" @@ -260,7 +209,8 @@ class DaikinClimate(ClimateDevice): @property def swing_mode(self): """Return the fan setting.""" - return self.get(ATTR_SWING_MODE) + return self._api.device.represent( + HA_ATTR_TO_DAIKIN[ATTR_SWING_MODE])[1].title() async def async_set_swing_mode(self, swing_mode): """Set new target temperature.""" @@ -274,7 +224,10 @@ class DaikinClimate(ClimateDevice): @property def preset_mode(self): """Return the preset_mode.""" - return self.get(ATTR_PRESET_MODE) + if self._api.device.represent(HA_ATTR_TO_DAIKIN[ATTR_PRESET_MODE] + )[1] == HA_PRESET_TO_DAIKIN[PRESET_AWAY]: + return PRESET_AWAY + return PRESET_NONE async def async_set_preset_mode(self, preset_mode): """Set preset mode.""" diff --git a/homeassistant/components/daikin/manifest.json b/homeassistant/components/daikin/manifest.json index f41faa42091..a60355efa0b 100644 --- a/homeassistant/components/daikin/manifest.json +++ b/homeassistant/components/daikin/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/components/daikin", "requirements": [ - "pydaikin==1.5.1" + "pydaikin==1.6.1" ], "dependencies": [], "codeowners": [ diff --git a/homeassistant/components/daikin/sensor.py b/homeassistant/components/daikin/sensor.py index 8196acc5cf7..d11f1039d6e 100644 --- a/homeassistant/components/daikin/sensor.py +++ b/homeassistant/components/daikin/sensor.py @@ -57,30 +57,6 @@ class DaikinClimateSensor(Entity): """Return a unique ID.""" return "{}-{}".format(self._api.mac, self._device_attribute) - def get(self, key): - """Retrieve device settings from API library cache.""" - value = None - cast_to_float = False - - if key == ATTR_INSIDE_TEMPERATURE: - value = self._api.device.values.get('htemp') - cast_to_float = True - elif key == ATTR_OUTSIDE_TEMPERATURE: - value = self._api.device.values.get('otemp') - - if value is None: - _LOGGER.warning("Invalid value requested for key %s", key) - else: - if value in ("-", "--"): - value = None - elif cast_to_float: - try: - value = float(value) - except ValueError: - value = None - - return value - @property def icon(self): """Icon to use in the frontend, if any.""" @@ -94,7 +70,11 @@ class DaikinClimateSensor(Entity): @property def state(self): """Return the state of the sensor.""" - return self.get(self._device_attribute) + if self._device_attribute == ATTR_INSIDE_TEMPERATURE: + return self._api.device.inside_temperature + if self._device_attribute == ATTR_OUTSIDE_TEMPERATURE: + return self._api.device.outside_temperature + return None @property def unit_of_measurement(self): diff --git a/requirements_all.txt b/requirements_all.txt index 4043d46629a..b3f84399389 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1090,7 +1090,7 @@ pycsspeechtts==1.0.2 # pycups==1.9.73 # homeassistant.components.daikin -pydaikin==1.5.1 +pydaikin==1.6.1 # homeassistant.components.danfoss_air pydanfossair==0.1.0