From ebc26c70b95b9e924fa6f8d672afb1f7b1695cdc Mon Sep 17 00:00:00 2001 From: ollo69 <60491700+ollo69@users.noreply.github.com> Date: Mon, 9 Nov 2020 22:57:04 +0100 Subject: [PATCH] Remove Tuya climate ext. temperature entity option (#42546) --- homeassistant/components/tuya/climate.py | 48 +------------------- homeassistant/components/tuya/config_flow.py | 23 ++-------- homeassistant/components/tuya/const.py | 1 - homeassistant/components/tuya/strings.json | 3 +- 4 files changed, 7 insertions(+), 68 deletions(-) diff --git a/homeassistant/components/tuya/climate.py b/homeassistant/components/tuya/climate.py index b5725e6faf6..6da15b0d29e 100644 --- a/homeassistant/components/tuya/climate.py +++ b/homeassistant/components/tuya/climate.py @@ -23,19 +23,17 @@ from homeassistant.const import ( ATTR_TEMPERATURE, CONF_PLATFORM, CONF_UNIT_OF_MEASUREMENT, - ENTITY_MATCH_NONE, PRECISION_TENTHS, PRECISION_WHOLE, TEMP_CELSIUS, TEMP_FAHRENHEIT, ) -from homeassistant.core import callback, valid_entity_id +from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from . import TuyaDevice from .const import ( CONF_CURR_TEMP_DIVIDER, - CONF_EXT_TEMP_SENSOR, CONF_MAX_TEMP, CONF_MIN_TEMP, CONF_TEMP_DIVIDER, @@ -112,8 +110,6 @@ class TuyaClimateEntity(TuyaDevice, ClimateEntity): self._def_hvac_mode = HVAC_MODE_AUTO self._min_temp = None self._max_temp = None - self._temp_entity = None - self._temp_entity_error = False @callback def _process_config(self): @@ -133,7 +129,6 @@ class TuyaClimateEntity(TuyaDevice, ClimateEntity): else: self._min_temp = min_temp self._max_temp = max_temp - self._temp_entity = config.get(CONF_EXT_TEMP_SENSOR) async def async_added_to_hass(self): """Create operation list when add to hass.""" @@ -196,10 +191,7 @@ class TuyaClimateEntity(TuyaDevice, ClimateEntity): @property def current_temperature(self): """Return the current temperature.""" - curr_temp = self._tuya.current_temperature() - if curr_temp is None: - return self._get_ext_temperature() - return curr_temp + return self._tuya.current_temperature() @property def target_temperature(self): @@ -271,39 +263,3 @@ class TuyaClimateEntity(TuyaDevice, ClimateEntity): if max_temp is not None: return max_temp return super().max_temp - - def _set_and_log_temp_error(self, error_msg): - if not self._temp_entity_error: - _LOGGER.warning( - "Error on Tuya external temperature sensor %s: %s", - self._temp_entity, - error_msg, - ) - self._temp_entity_error = True - - def _get_ext_temperature(self): - """Get external temperature entity current state.""" - if not self._temp_entity or self._temp_entity == ENTITY_MATCH_NONE: - return None - - entity_name = self._temp_entity - if not valid_entity_id(entity_name): - self._set_and_log_temp_error("entity name is invalid") - return None - - state_obj = self.hass.states.get(entity_name) - if state_obj: - temperature = state_obj.state - try: - float(temperature) - except (TypeError, ValueError): - self._set_and_log_temp_error( - "entity state is not available or is not a number" - ) - return None - - self._temp_entity_error = False - return temperature - - self._set_and_log_temp_error("entity not found") - return None diff --git a/homeassistant/components/tuya/config_flow.py b/homeassistant/components/tuya/config_flow.py index b457749ddfc..e2048aaf7bf 100644 --- a/homeassistant/components/tuya/config_flow.py +++ b/homeassistant/components/tuya/config_flow.py @@ -24,7 +24,6 @@ from .const import ( CONF_COUNTRYCODE, CONF_CURR_TEMP_DIVIDER, CONF_DISCOVERY_INTERVAL, - CONF_EXT_TEMP_SENSOR, CONF_MAX_KELVIN, CONF_MAX_TEMP, CONF_MIN_KELVIN, @@ -229,7 +228,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow): device_id, self.config_entry.options.get(device_id, {}) ) - config_schema = await self._get_device_schema(device_type, curr_conf, device) + config_schema = self._get_device_schema(device_type, curr_conf, device) if not config_schema: self._form_error = ERROR_DEV_NOT_CONFIG return await self.async_step_init() @@ -312,13 +311,12 @@ class OptionsFlowHandler(config_entries.OptionsFlow): return await self.async_step_init() - async def _get_device_schema(self, device_type, curr_conf, device): + def _get_device_schema(self, device_type, curr_conf, device): """Return option schema for device.""" if device_type == "light": return self._get_light_schema(curr_conf, device) if device_type == "climate": - entities_list = await _get_entities_matching_domains(self.hass, ["sensor"]) - return self._get_climate_schema(curr_conf, device, entities_list) + return self._get_climate_schema(curr_conf, device) return None @staticmethod @@ -362,11 +360,10 @@ class OptionsFlowHandler(config_entries.OptionsFlow): return config_schema @staticmethod - def _get_climate_schema(curr_conf, device, entities_list): + def _get_climate_schema(curr_conf, device): """Create option schema for climate device.""" unit = device.temperature_unit() def_unit = TEMP_FAHRENHEIT if unit == "FAHRENHEIT" else TEMP_CELSIUS - entities_list.insert(0, ENTITY_MATCH_NONE) config_schema = vol.Schema( { @@ -390,19 +387,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow): CONF_MAX_TEMP, default=curr_conf.get(CONF_MAX_TEMP, 0), ): int, - vol.Optional( - CONF_EXT_TEMP_SENSOR, - default=curr_conf.get(CONF_EXT_TEMP_SENSOR, ENTITY_MATCH_NONE), - ): vol.In(entities_list), } ) return config_schema - - -async def _get_entities_matching_domains(hass, domains): - """List entities in the given domains.""" - included_domains = set(domains) - entity_ids = hass.states.async_entity_ids(included_domains) - entity_ids.sort() - return entity_ids diff --git a/homeassistant/components/tuya/const.py b/homeassistant/components/tuya/const.py index f931fd1a410..4f4ec342b15 100644 --- a/homeassistant/components/tuya/const.py +++ b/homeassistant/components/tuya/const.py @@ -4,7 +4,6 @@ CONF_BRIGHTNESS_RANGE_MODE = "brightness_range_mode" CONF_COUNTRYCODE = "country_code" CONF_CURR_TEMP_DIVIDER = "curr_temp_divider" CONF_DISCOVERY_INTERVAL = "discovery_interval" -CONF_EXT_TEMP_SENSOR = "ext_temp_sensor" CONF_MAX_KELVIN = "max_kelvin" CONF_MAX_TEMP = "max_temp" CONF_MIN_KELVIN = "min_kelvin" diff --git a/homeassistant/components/tuya/strings.json b/homeassistant/components/tuya/strings.json index 5939dfb05f2..84575906010 100644 --- a/homeassistant/components/tuya/strings.json +++ b/homeassistant/components/tuya/strings.json @@ -47,8 +47,7 @@ "temp_divider": "Temperature values divider (0 = use default)", "curr_temp_divider": "Current Temperature value divider (0 = use default)", "min_temp": "Min target temperature (use min and max = 0 for default)", - "max_temp": "Max target temperature (use min and max = 0 for default)", - "ext_temp_sensor": "Sensor for current temperature" + "max_temp": "Max target temperature (use min and max = 0 for default)" } } },