Skip to content

Commit

Permalink
FIX error on startup when my_climate is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Marc Collin committed Mar 3, 2023
1 parent 7c87175 commit ea7b6a0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
16 changes: 10 additions & 6 deletions custom_components/versatile_thermostat/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 6 additions & 13 deletions custom_components/versatile_thermostat/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@

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

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,
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit ea7b6a0

Please sign in to comment.