Use instance attributes in evohome (#74996)

This commit is contained in:
epenet 2022-07-11 17:24:35 +02:00 committed by GitHub
parent c2fefe03b2
commit fa51a39f1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 62 deletions

View file

@ -20,7 +20,6 @@ from homeassistant.const import (
CONF_PASSWORD,
CONF_SCAN_INTERVAL,
CONF_USERNAME,
TEMP_CELSIUS,
Platform,
)
from homeassistant.core import HomeAssistant, ServiceCall, callback
@ -519,13 +518,14 @@ class EvoDevice(Entity):
DHW controller.
"""
_attr_should_poll = False
def __init__(self, evo_broker, evo_device) -> None:
"""Initialize the evohome entity."""
self._evo_device = evo_device
self._evo_broker = evo_broker
self._evo_tcs = evo_broker.tcs
self._unique_id = self._name = self._icon = self._precision = None
self._device_state_attrs = {}
async def async_refresh(self, payload: dict | None = None) -> None:
@ -533,7 +533,7 @@ class EvoDevice(Entity):
if payload is None:
self.async_schedule_update_ha_state(force_refresh=True)
return
if payload["unique_id"] != self._unique_id:
if payload["unique_id"] != self._attr_unique_id:
return
if payload["service"] in (SVC_SET_ZONE_OVERRIDE, SVC_RESET_ZONE_OVERRIDE):
await self.async_zone_svc_request(payload["service"], payload["data"])
@ -548,21 +548,6 @@ class EvoDevice(Entity):
"""Process a service request (setpoint override) for a zone."""
raise NotImplementedError
@property
def should_poll(self) -> bool:
"""Evohome entities should not be polled."""
return False
@property
def unique_id(self) -> str | None:
"""Return a unique ID."""
return self._unique_id
@property
def name(self) -> str:
"""Return the name of the evohome entity."""
return self._name
@property
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the evohome-specific state attributes."""
@ -576,25 +561,10 @@ class EvoDevice(Entity):
return {"status": convert_dict(status)}
@property
def icon(self) -> str:
"""Return the icon to use in the frontend UI."""
return self._icon
async def async_added_to_hass(self) -> None:
"""Run when entity about to be added to hass."""
async_dispatcher_connect(self.hass, DOMAIN, self.async_refresh)
@property
def precision(self) -> float:
"""Return the temperature precision to use in the frontend UI."""
return self._precision
@property
def temperature_unit(self) -> str:
"""Return the temperature unit to use in the frontend UI."""
return TEMP_CELSIUS
class EvoChild(EvoDevice):
"""Base for any evohome child.

View file

@ -13,7 +13,7 @@ from homeassistant.components.climate.const import (
ClimateEntityFeature,
HVACMode,
)
from homeassistant.const import PRECISION_TENTHS
from homeassistant.const import PRECISION_TENTHS, TEMP_CELSIUS
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -151,19 +151,19 @@ class EvoZone(EvoChild, EvoClimateEntity):
if evo_device.modelType.startswith("VisionProWifi"):
# this system does not have a distinct ID for the zone
self._unique_id = f"{evo_device.zoneId}z"
self._attr_unique_id = f"{evo_device.zoneId}z"
else:
self._unique_id = evo_device.zoneId
self._attr_unique_id = evo_device.zoneId
self._name = evo_device.name
self._icon = "mdi:radiator"
self._attr_name = evo_device.name
if evo_broker.client_v1:
self._precision = PRECISION_TENTHS
self._attr_precision = PRECISION_TENTHS
else:
self._precision = self._evo_device.setpointCapabilities["valueResolution"]
self._attr_precision = self._evo_device.setpointCapabilities[
"valueResolution"
]
self._preset_modes = list(HA_PRESET_TO_EVO)
self._attr_supported_features = (
ClimateEntityFeature.PRESET_MODE | ClimateEntityFeature.TARGET_TEMPERATURE
)
@ -313,22 +313,23 @@ class EvoController(EvoClimateEntity):
It is assumed there is only one TCS per location, and they are thus synonymous.
"""
_attr_icon = "mdi:thermostat"
_attr_precision = PRECISION_TENTHS
_attr_temperature_unit = TEMP_CELSIUS
def __init__(self, evo_broker, evo_device) -> None:
"""Initialize a Honeywell TCC Controller/Location."""
super().__init__(evo_broker, evo_device)
self._unique_id = evo_device.systemId
self._name = evo_device.location.name
self._icon = "mdi:thermostat"
self._precision = PRECISION_TENTHS
self._attr_unique_id = evo_device.systemId
self._attr_name = evo_device.location.name
modes = [m["systemMode"] for m in evo_broker.config["allowedSystemModes"]]
self._preset_modes = [
self._attr_preset_modes = [
TCS_PRESET_TO_HA[m] for m in modes if m in list(TCS_PRESET_TO_HA)
]
self._attr_supported_features = (
ClimateEntityFeature.PRESET_MODE if self._preset_modes else 0
ClimateEntityFeature.PRESET_MODE if self._attr_preset_modes else 0
)
async def async_tcs_svc_request(self, service: dict, data: dict) -> None:

View file

@ -7,7 +7,13 @@ from homeassistant.components.water_heater import (
WaterHeaterEntity,
WaterHeaterEntityFeature,
)
from homeassistant.const import PRECISION_TENTHS, PRECISION_WHOLE, STATE_OFF, STATE_ON
from homeassistant.const import (
PRECISION_TENTHS,
PRECISION_WHOLE,
STATE_OFF,
STATE_ON,
TEMP_CELSIUS,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -51,15 +57,20 @@ async def async_setup_platform(
class EvoDHW(EvoChild, WaterHeaterEntity):
"""Base for a Honeywell TCC DHW controller (aka boiler)."""
_attr_name = "DHW controller"
_attr_icon = "mdi:thermometer-lines"
_attr_operation_list = list(HA_STATE_TO_EVO)
_attr_temperature_unit = TEMP_CELSIUS
def __init__(self, evo_broker, evo_device) -> None:
"""Initialize an evohome DHW controller."""
super().__init__(evo_broker, evo_device)
self._unique_id = evo_device.dhwId
self._name = "DHW controller"
self._icon = "mdi:thermometer-lines"
self._attr_unique_id = evo_device.dhwId
self._precision = PRECISION_TENTHS if evo_broker.client_v1 else PRECISION_WHOLE
self._attr_precision = (
PRECISION_TENTHS if evo_broker.client_v1 else PRECISION_WHOLE
)
self._attr_supported_features = (
WaterHeaterEntityFeature.AWAY_MODE | WaterHeaterEntityFeature.OPERATION_MODE
)
@ -71,11 +82,6 @@ class EvoDHW(EvoChild, WaterHeaterEntity):
return STATE_AUTO
return EVO_STATE_TO_HA[self._evo_device.stateStatus["state"]]
@property
def operation_list(self) -> list[str]:
"""Return the list of available operations."""
return list(HA_STATE_TO_EVO)
@property
def is_away_mode_on(self):
"""Return True if away mode is on."""

View file

@ -2672,9 +2672,6 @@ ignore_errors = true
[mypy-homeassistant.components.evohome.climate]
ignore_errors = true
[mypy-homeassistant.components.evohome.water_heater]
ignore_errors = true
[mypy-homeassistant.components.icloud]
ignore_errors = true

View file

@ -25,7 +25,6 @@ IGNORED_MODULES: Final[list[str]] = [
"homeassistant.components.conversation.default_agent",
"homeassistant.components.evohome",
"homeassistant.components.evohome.climate",
"homeassistant.components.evohome.water_heater",
"homeassistant.components.icloud",
"homeassistant.components.icloud.account",
"homeassistant.components.icloud.device_tracker",