diff --git a/custom_components/versatile_thermostat/commons.py b/custom_components/versatile_thermostat/commons.py index 45f5758c..7d58aa97 100644 --- a/custom_components/versatile_thermostat/commons.py +++ b/custom_components/versatile_thermostat/commons.py @@ -55,12 +55,16 @@ def device_info(self) -> DeviceInfo: def find_my_versatile_thermostat(self) -> VersatileThermostat: """Find the underlying climate entity""" - component: EntityComponent[ClimateEntity] = self.hass.data[CLIMATE_DOMAIN] - for entity in component.entities: - _LOGGER.debug("Device_info is %s", entity.device_info) - if entity.device_info == self.device_info: - _LOGGER.debug("Found %s!", entity) - return entity + try: + component: EntityComponent[ClimateEntity] = self.hass.data[CLIMATE_DOMAIN] + for entity in component.entities: + _LOGGER.debug("Device_info is %s", entity.device_info) + if entity.device_info == self.device_info: + _LOGGER.debug("Found %s!", entity) + return entity + except KeyError: + pass + return None @callback diff --git a/custom_components/versatile_thermostat/sensor.py b/custom_components/versatile_thermostat/sensor.py index e33d395c..381f000f 100644 --- a/custom_components/versatile_thermostat/sensor.py +++ b/custom_components/versatile_thermostat/sensor.py @@ -4,10 +4,13 @@ from homeassistant.core import HomeAssistant, callback, Event -from homeassistant.const import STATE_ON, UnitOfTime +from homeassistant.const import UnitOfTime -from homeassistant.components.sensor import SensorEntity -from homeassistant.components.sensor.const import SensorDeviceClass, SensorStateClass +from homeassistant.components.sensor import ( + SensorEntity, + SensorDeviceClass, + SensorStateClass, +) from homeassistant.config_entries import ConfigEntry from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -15,10 +18,6 @@ from .commons import VersatileThermostatBaseEntity from .const import ( CONF_NAME, - CONF_USE_POWER_FEATURE, - CONF_USE_PRESENCE_FEATURE, - CONF_USE_MOTION_FEATURE, - CONF_USE_WINDOW_FEATURE, CONF_DEVICE_POWER, CONF_PROP_FUNCTION, PROPORTIONAL_FUNCTION_TPI, @@ -55,12 +54,6 @@ async def async_setup_entry( entities.append(OnPercentSensor(hass, unique_id, name, entry.data)) entities.append(OnTimeSensor(hass, unique_id, name, entry.data)) entities.append(OffTimeSensor(hass, unique_id, name, entry.data)) - # if entry.data.get(CONF_USE_WINDOW_FEATURE): - # entities.append(WindowBinarySensor(hass, unique_id, name, entry.data)) - # if entry.data.get(CONF_USE_PRESENCE_FEATURE): - # entities.append(PresenceBinarySensor(hass, unique_id, name, entry.data)) - # if entry.data.get(CONF_USE_POWER_FEATURE): - # entities.append(OverpoweringBinarySensor(hass, unique_id, name, entry.data)) async_add_entities(entities, True)