Use entity class attributes for atag (#52686)

pull/53274/head
Robert Hillis 2021-07-21 05:33:44 -04:00 committed by GitHub
parent 81c4d95afe
commit 02a7a2464a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 72 deletions

View File

@ -75,27 +75,16 @@ class AtagEntity(CoordinatorEntity):
super().__init__(coordinator)
self._id = atag_id
self._name = DOMAIN.title()
self._attr_name = DOMAIN.title()
self._attr_unique_id = f"{coordinator.data.id}-{atag_id}"
@property
def device_info(self) -> DeviceInfo:
"""Return info for device registry."""
device = self.coordinator.data.id
version = self.coordinator.data.apiversion
return {
"identifiers": {(DOMAIN, device)},
"identifiers": {(DOMAIN, self.coordinator.data.id)},
"name": "Atag Thermostat",
"model": "Atag One",
"sw_version": version,
"sw_version": self.coordinator.data.apiversion,
"manufacturer": "Atag",
}
@property
def name(self) -> str:
"""Return the name of the entity."""
return self._name
@property
def unique_id(self):
"""Return a unique ID to use for this entity."""
return f"{self.coordinator.data.id}-{self._id}"

View File

@ -37,10 +37,14 @@ async def async_setup_entry(hass, entry, async_add_entities):
class AtagThermostat(AtagEntity, ClimateEntity):
"""Atag climate device."""
@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_FLAGS
_attr_hvac_modes = HVAC_MODES
_attr_preset_modes = list(PRESET_MAP.keys())
_attr_supported_features = SUPPORT_FLAGS
def __init__(self, coordinator, atag_id):
"""Initialize an Atag climate device."""
super().__init__(coordinator, atag_id)
self._attr_temperature_unit = coordinator.data.climate.temp_unit
@property
def hvac_mode(self) -> str | None:
@ -49,22 +53,12 @@ class AtagThermostat(AtagEntity, ClimateEntity):
return self.coordinator.data.climate.hvac_mode
return None
@property
def hvac_modes(self) -> list[str]:
"""Return the list of available hvac operation modes."""
return HVAC_MODES
@property
def hvac_action(self) -> str | None:
"""Return the current running hvac operation."""
is_active = self.coordinator.data.climate.status
return CURRENT_HVAC_HEAT if is_active else CURRENT_HVAC_IDLE
@property
def temperature_unit(self) -> str | None:
"""Return the unit of measurement."""
return self.coordinator.data.climate.temp_unit
@property
def current_temperature(self) -> float | None:
"""Return the current temperature."""
@ -81,11 +75,6 @@ class AtagThermostat(AtagEntity, ClimateEntity):
preset = self.coordinator.data.climate.preset_mode
return PRESET_INVERTED.get(preset)
@property
def preset_modes(self) -> list[str] | None:
"""Return a list of available preset modes."""
return list(PRESET_MAP.keys())
async def async_set_temperature(self, **kwargs) -> None:
"""Set new target temperature."""
await self.coordinator.data.climate.set_temp(kwargs.get(ATTR_TEMPERATURE))

View File

@ -36,7 +36,20 @@ class AtagSensor(AtagEntity, SensorEntity):
def __init__(self, coordinator, sensor):
"""Initialize Atag sensor."""
super().__init__(coordinator, SENSORS[sensor])
self._name = sensor
self._attr_name = sensor
if coordinator.data.report[self._id].sensorclass in [
DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE,
]:
self._attr_device_class = coordinator.data.report[self._id].sensorclass
if coordinator.data.report[self._id].measure in [
PRESSURE_BAR,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
PERCENTAGE,
TIME_HOURS,
]:
self._attr_unit_of_measurement = coordinator.data.report[self._id].measure
@property
def state(self):
@ -47,26 +60,3 @@ class AtagSensor(AtagEntity, SensorEntity):
def icon(self):
"""Return icon."""
return self.coordinator.data.report[self._id].icon
@property
def device_class(self):
"""Return deviceclass."""
if self.coordinator.data.report[self._id].sensorclass in [
DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE,
]:
return self.coordinator.data.report[self._id].sensorclass
return None
@property
def unit_of_measurement(self):
"""Return measure."""
if self.coordinator.data.report[self._id].measure in [
PRESSURE_BAR,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
PERCENTAGE,
TIME_HOURS,
]:
return self.coordinator.data.report[self._id].measure
return None

View File

@ -22,15 +22,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
class AtagWaterHeater(AtagEntity, WaterHeaterEntity):
"""Representation of an ATAG water heater."""
@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_FLAGS_HEATER
@property
def temperature_unit(self):
"""Return the unit of measurement."""
return TEMP_CELSIUS
_attr_operation_list = OPERATION_LIST
_attr_supported_features = SUPPORT_FLAGS_HEATER
_attr_temperature_unit = TEMP_CELSIUS
@property
def current_temperature(self):
@ -43,11 +37,6 @@ class AtagWaterHeater(AtagEntity, WaterHeaterEntity):
operation = self.coordinator.data.dhw.current_operation
return operation if operation in self.operation_list else STATE_OFF
@property
def operation_list(self):
"""List of available operation modes."""
return OPERATION_LIST
async def async_set_temperature(self, **kwargs):
"""Set new target temperature."""
if await self.coordinator.data.dhw.set_temp(kwargs.get(ATTR_TEMPERATURE)):