diff --git a/homeassistant/components/ecobee/binary_sensor.py b/homeassistant/components/ecobee/binary_sensor.py index 9593fc0e497..0d3174cb5a6 100644 --- a/homeassistant/components/ecobee/binary_sensor.py +++ b/homeassistant/components/ecobee/binary_sensor.py @@ -4,7 +4,7 @@ from homeassistant.components.binary_sensor import ( BinarySensorEntity, ) -from .const import _LOGGER, DOMAIN, ECOBEE_MODEL_TO_NAME, MANUFACTURER +from .const import DOMAIN, ECOBEE_MODEL_TO_NAME, MANUFACTURER async def async_setup_entry(hass, config_entry, async_add_entities): @@ -67,17 +67,11 @@ class EcobeeBinarySensor(BinarySensorEntity): f"{ECOBEE_MODEL_TO_NAME[thermostat['modelNumber']]} Thermostat" ) except KeyError: - _LOGGER.error( - "Model number for ecobee thermostat %s not recognized. " - "Please visit this link and provide the following information: " - "https://github.com/home-assistant/core/issues/27172 " - "Unrecognized model number: %s", - thermostat["name"], - thermostat["modelNumber"], - ) + # Ecobee model is not in our list + model = None break - if identifier is not None and model is not None: + if identifier is not None: return { "identifiers": {(DOMAIN, identifier)}, "name": self.sensor_name, diff --git a/homeassistant/components/ecobee/climate.py b/homeassistant/components/ecobee/climate.py index 9e9e2eff1c8..eeac7ddb224 100644 --- a/homeassistant/components/ecobee/climate.py +++ b/homeassistant/components/ecobee/climate.py @@ -176,10 +176,23 @@ async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the ecobee thermostat.""" data = hass.data[DOMAIN] + entities = [] - devices = [Thermostat(data, index) for index in range(len(data.ecobee.thermostats))] + for index in range(len(data.ecobee.thermostats)): + thermostat = data.ecobee.get_thermostat(index) + if not thermostat["modelNumber"] in ECOBEE_MODEL_TO_NAME: + _LOGGER.error( + "Model number for ecobee thermostat %s not recognized. " + "Please visit this link to open a new issue: " + "https://github.com/home-assistant/core/issues " + "and include the following information: " + "Unrecognized model number: %s", + thermostat["name"], + thermostat["modelNumber"], + ) + entities.append(Thermostat(data, index, thermostat)) - async_add_entities(devices, True) + async_add_entities(entities, True) platform = entity_platform.async_get_current_platform() @@ -187,7 +200,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): """Create a vacation on the target thermostat.""" entity_id = service.data[ATTR_ENTITY_ID] - for thermostat in devices: + for thermostat in entities: if thermostat.entity_id == entity_id: thermostat.create_vacation(service.data) thermostat.schedule_update_ha_state(True) @@ -198,7 +211,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): entity_id = service.data[ATTR_ENTITY_ID] vacation_name = service.data[ATTR_VACATION_NAME] - for thermostat in devices: + for thermostat in entities: if thermostat.entity_id == entity_id: thermostat.delete_vacation(vacation_name) thermostat.schedule_update_ha_state(True) @@ -211,10 +224,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if entity_id: target_thermostats = [ - device for device in devices if device.entity_id in entity_id + entity for entity in entities if entity.entity_id in entity_id ] else: - target_thermostats = devices + target_thermostats = entities for thermostat in target_thermostats: thermostat.set_fan_min_on_time(str(fan_min_on_time)) @@ -228,10 +241,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if entity_id: target_thermostats = [ - device for device in devices if device.entity_id in entity_id + entity for entity in entities if entity.entity_id in entity_id ] else: - target_thermostats = devices + target_thermostats = entities for thermostat in target_thermostats: thermostat.resume_program(resume_all) @@ -291,11 +304,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities): class Thermostat(ClimateEntity): """A thermostat class for Ecobee.""" - def __init__(self, data, thermostat_index): + def __init__(self, data, thermostat_index, thermostat): """Initialize the thermostat.""" self.data = data self.thermostat_index = thermostat_index - self.thermostat = self.data.ecobee.get_thermostat(self.thermostat_index) + self.thermostat = thermostat self._name = self.thermostat["name"] self.vacation = None self._last_active_hvac_mode = HVAC_MODE_HEAT_COOL @@ -358,15 +371,8 @@ class Thermostat(ClimateEntity): try: model = f"{ECOBEE_MODEL_TO_NAME[self.thermostat['modelNumber']]} Thermostat" except KeyError: - _LOGGER.error( - "Model number for ecobee thermostat %s not recognized. " - "Please visit this link and provide the following information: " - "https://github.com/home-assistant/core/issues/27172 " - "Unrecognized model number: %s", - self.name, - self.thermostat["modelNumber"], - ) - return None + # Ecobee model is not in our list + model = None return { "identifiers": {(DOMAIN, self.thermostat["identifier"])}, diff --git a/homeassistant/components/ecobee/humidifier.py b/homeassistant/components/ecobee/humidifier.py index f39fb7acc68..fadaa83155a 100644 --- a/homeassistant/components/ecobee/humidifier.py +++ b/homeassistant/components/ecobee/humidifier.py @@ -60,7 +60,7 @@ class EcobeeHumidifier(HumidifierEntity): model = f"{ECOBEE_MODEL_TO_NAME[self.thermostat['modelNumber']]} Thermostat" except KeyError: # Ecobee model is not in our list - return None + model = None return { "identifiers": {(DOMAIN, self.thermostat["identifier"])}, diff --git a/homeassistant/components/ecobee/sensor.py b/homeassistant/components/ecobee/sensor.py index 5abe809e59d..7cf04e12718 100644 --- a/homeassistant/components/ecobee/sensor.py +++ b/homeassistant/components/ecobee/sensor.py @@ -9,7 +9,7 @@ from homeassistant.const import ( TEMP_FAHRENHEIT, ) -from .const import _LOGGER, DOMAIN, ECOBEE_MODEL_TO_NAME, MANUFACTURER +from .const import DOMAIN, ECOBEE_MODEL_TO_NAME, MANUFACTURER SENSOR_TYPES = { "temperature": ["Temperature", TEMP_FAHRENHEIT], @@ -79,14 +79,8 @@ class EcobeeSensor(SensorEntity): f"{ECOBEE_MODEL_TO_NAME[thermostat['modelNumber']]} Thermostat" ) except KeyError: - _LOGGER.error( - "Model number for ecobee thermostat %s not recognized. " - "Please visit this link and provide the following information: " - "https://github.com/home-assistant/core/issues/27172 " - "Unrecognized model number: %s", - thermostat["name"], - thermostat["modelNumber"], - ) + # Ecobee model is not in our list + model = None break if identifier is not None and model is not None: diff --git a/homeassistant/components/ecobee/weather.py b/homeassistant/components/ecobee/weather.py index fc93ebffb95..8e3de2be90a 100644 --- a/homeassistant/components/ecobee/weather.py +++ b/homeassistant/components/ecobee/weather.py @@ -17,7 +17,6 @@ from homeassistant.util import dt as dt_util from homeassistant.util.pressure import convert as pressure_convert from .const import ( - _LOGGER, DOMAIN, ECOBEE_MODEL_TO_NAME, ECOBEE_WEATHER_SYMBOL_TO_HASS, @@ -72,15 +71,8 @@ class EcobeeWeather(WeatherEntity): try: model = f"{ECOBEE_MODEL_TO_NAME[thermostat['modelNumber']]} Thermostat" except KeyError: - _LOGGER.error( - "Model number for ecobee thermostat %s not recognized. " - "Please visit this link and provide the following information: " - "https://github.com/home-assistant/core/issues/27172 " - "Unrecognized model number: %s", - thermostat["name"], - thermostat["modelNumber"], - ) - return None + # Ecobee model is not in our list + model = None return { "identifiers": {(DOMAIN, thermostat["identifier"])}, diff --git a/tests/components/ecobee/test_climate.py b/tests/components/ecobee/test_climate.py index da6017a71a1..cc394a1f63f 100644 --- a/tests/components/ecobee/test_climate.py +++ b/tests/components/ecobee/test_climate.py @@ -13,6 +13,7 @@ def ecobee_fixture(): """Set up ecobee mock.""" vals = { "name": "Ecobee", + "modelNumber": "athenaSmart", "program": { "climates": [ {"name": "Climate1", "climateRef": "c1"}, @@ -64,7 +65,8 @@ def data_fixture(ecobee_fixture): @pytest.fixture(name="thermostat") def thermostat_fixture(data): """Set up ecobee thermostat object.""" - return ecobee.Thermostat(data, 1) + thermostat = data.ecobee.get_thermostat(1) + return ecobee.Thermostat(data, 1, thermostat) async def test_name(thermostat):