Ecobee logging cleanup (#51754)

This commit is contained in:
Brent Petit 2021-06-17 03:59:13 -05:00 committed by GitHub
parent b2aa55cea2
commit 016ba39dfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 50 deletions

View File

@ -4,7 +4,7 @@ from homeassistant.components.binary_sensor import (
BinarySensorEntity, 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): 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" f"{ECOBEE_MODEL_TO_NAME[thermostat['modelNumber']]} Thermostat"
) )
except KeyError: except KeyError:
_LOGGER.error( # Ecobee model is not in our list
"Model number for ecobee thermostat %s not recognized. " model = None
"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"],
)
break break
if identifier is not None and model is not None: if identifier is not None:
return { return {
"identifiers": {(DOMAIN, identifier)}, "identifiers": {(DOMAIN, identifier)},
"name": self.sensor_name, "name": self.sensor_name,

View File

@ -176,10 +176,23 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the ecobee thermostat.""" """Set up the ecobee thermostat."""
data = hass.data[DOMAIN] 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() 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.""" """Create a vacation on the target thermostat."""
entity_id = service.data[ATTR_ENTITY_ID] entity_id = service.data[ATTR_ENTITY_ID]
for thermostat in devices: for thermostat in entities:
if thermostat.entity_id == entity_id: if thermostat.entity_id == entity_id:
thermostat.create_vacation(service.data) thermostat.create_vacation(service.data)
thermostat.schedule_update_ha_state(True) 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] entity_id = service.data[ATTR_ENTITY_ID]
vacation_name = service.data[ATTR_VACATION_NAME] vacation_name = service.data[ATTR_VACATION_NAME]
for thermostat in devices: for thermostat in entities:
if thermostat.entity_id == entity_id: if thermostat.entity_id == entity_id:
thermostat.delete_vacation(vacation_name) thermostat.delete_vacation(vacation_name)
thermostat.schedule_update_ha_state(True) thermostat.schedule_update_ha_state(True)
@ -211,10 +224,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
if entity_id: if entity_id:
target_thermostats = [ 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: else:
target_thermostats = devices target_thermostats = entities
for thermostat in target_thermostats: for thermostat in target_thermostats:
thermostat.set_fan_min_on_time(str(fan_min_on_time)) 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: if entity_id:
target_thermostats = [ 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: else:
target_thermostats = devices target_thermostats = entities
for thermostat in target_thermostats: for thermostat in target_thermostats:
thermostat.resume_program(resume_all) thermostat.resume_program(resume_all)
@ -291,11 +304,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
class Thermostat(ClimateEntity): class Thermostat(ClimateEntity):
"""A thermostat class for Ecobee.""" """A thermostat class for Ecobee."""
def __init__(self, data, thermostat_index): def __init__(self, data, thermostat_index, thermostat):
"""Initialize the thermostat.""" """Initialize the thermostat."""
self.data = data self.data = data
self.thermostat_index = thermostat_index self.thermostat_index = thermostat_index
self.thermostat = self.data.ecobee.get_thermostat(self.thermostat_index) self.thermostat = thermostat
self._name = self.thermostat["name"] self._name = self.thermostat["name"]
self.vacation = None self.vacation = None
self._last_active_hvac_mode = HVAC_MODE_HEAT_COOL self._last_active_hvac_mode = HVAC_MODE_HEAT_COOL
@ -358,15 +371,8 @@ class Thermostat(ClimateEntity):
try: try:
model = f"{ECOBEE_MODEL_TO_NAME[self.thermostat['modelNumber']]} Thermostat" model = f"{ECOBEE_MODEL_TO_NAME[self.thermostat['modelNumber']]} Thermostat"
except KeyError: except KeyError:
_LOGGER.error( # Ecobee model is not in our list
"Model number for ecobee thermostat %s not recognized. " model = None
"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
return { return {
"identifiers": {(DOMAIN, self.thermostat["identifier"])}, "identifiers": {(DOMAIN, self.thermostat["identifier"])},

View File

@ -60,7 +60,7 @@ class EcobeeHumidifier(HumidifierEntity):
model = f"{ECOBEE_MODEL_TO_NAME[self.thermostat['modelNumber']]} Thermostat" model = f"{ECOBEE_MODEL_TO_NAME[self.thermostat['modelNumber']]} Thermostat"
except KeyError: except KeyError:
# Ecobee model is not in our list # Ecobee model is not in our list
return None model = None
return { return {
"identifiers": {(DOMAIN, self.thermostat["identifier"])}, "identifiers": {(DOMAIN, self.thermostat["identifier"])},

View File

@ -9,7 +9,7 @@ from homeassistant.const import (
TEMP_FAHRENHEIT, TEMP_FAHRENHEIT,
) )
from .const import _LOGGER, DOMAIN, ECOBEE_MODEL_TO_NAME, MANUFACTURER from .const import DOMAIN, ECOBEE_MODEL_TO_NAME, MANUFACTURER
SENSOR_TYPES = { SENSOR_TYPES = {
"temperature": ["Temperature", TEMP_FAHRENHEIT], "temperature": ["Temperature", TEMP_FAHRENHEIT],
@ -79,14 +79,8 @@ class EcobeeSensor(SensorEntity):
f"{ECOBEE_MODEL_TO_NAME[thermostat['modelNumber']]} Thermostat" f"{ECOBEE_MODEL_TO_NAME[thermostat['modelNumber']]} Thermostat"
) )
except KeyError: except KeyError:
_LOGGER.error( # Ecobee model is not in our list
"Model number for ecobee thermostat %s not recognized. " model = None
"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"],
)
break break
if identifier is not None and model is not None: if identifier is not None and model is not None:

View File

@ -17,7 +17,6 @@ from homeassistant.util import dt as dt_util
from homeassistant.util.pressure import convert as pressure_convert from homeassistant.util.pressure import convert as pressure_convert
from .const import ( from .const import (
_LOGGER,
DOMAIN, DOMAIN,
ECOBEE_MODEL_TO_NAME, ECOBEE_MODEL_TO_NAME,
ECOBEE_WEATHER_SYMBOL_TO_HASS, ECOBEE_WEATHER_SYMBOL_TO_HASS,
@ -72,15 +71,8 @@ class EcobeeWeather(WeatherEntity):
try: try:
model = f"{ECOBEE_MODEL_TO_NAME[thermostat['modelNumber']]} Thermostat" model = f"{ECOBEE_MODEL_TO_NAME[thermostat['modelNumber']]} Thermostat"
except KeyError: except KeyError:
_LOGGER.error( # Ecobee model is not in our list
"Model number for ecobee thermostat %s not recognized. " model = None
"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
return { return {
"identifiers": {(DOMAIN, thermostat["identifier"])}, "identifiers": {(DOMAIN, thermostat["identifier"])},

View File

@ -13,6 +13,7 @@ def ecobee_fixture():
"""Set up ecobee mock.""" """Set up ecobee mock."""
vals = { vals = {
"name": "Ecobee", "name": "Ecobee",
"modelNumber": "athenaSmart",
"program": { "program": {
"climates": [ "climates": [
{"name": "Climate1", "climateRef": "c1"}, {"name": "Climate1", "climateRef": "c1"},
@ -64,7 +65,8 @@ def data_fixture(ecobee_fixture):
@pytest.fixture(name="thermostat") @pytest.fixture(name="thermostat")
def thermostat_fixture(data): def thermostat_fixture(data):
"""Set up ecobee thermostat object.""" """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): async def test_name(thermostat):