Remove Tuya climate ext. temperature entity option (#42546)
This commit is contained in:
parent
dc89bfe9ce
commit
ebc26c70b9
4 changed files with 7 additions and 68 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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)"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue