Use attrs instead of properties in Airly integration (#51712)
This commit is contained in:
parent
453da10b62
commit
9d64b64d34
2 changed files with 14 additions and 53 deletions
|
@ -64,18 +64,9 @@ class AirlyAirQuality(CoordinatorEntity, AirQualityEntity):
|
||||||
def __init__(self, coordinator: AirlyDataUpdateCoordinator, name: str) -> None:
|
def __init__(self, coordinator: AirlyDataUpdateCoordinator, name: str) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._name = name
|
self._attr_icon = "mdi:blur"
|
||||||
self._icon = "mdi:blur"
|
self._attr_name = name
|
||||||
|
self._attr_unique_id = f"{coordinator.latitude}-{coordinator.longitude}"
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self) -> str:
|
|
||||||
"""Return the icon."""
|
|
||||||
return self._icon
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def air_quality_index(self) -> float | None:
|
def air_quality_index(self) -> float | None:
|
||||||
|
@ -97,11 +88,6 @@ class AirlyAirQuality(CoordinatorEntity, AirQualityEntity):
|
||||||
"""Return the attribution."""
|
"""Return the attribution."""
|
||||||
return ATTRIBUTION
|
return ATTRIBUTION
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self) -> str:
|
|
||||||
"""Return a unique_id for this entity."""
|
|
||||||
return f"{self.coordinator.latitude}-{self.coordinator.longitude}"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self) -> DeviceInfo:
|
def device_info(self) -> DeviceInfo:
|
||||||
"""Return the device info."""
|
"""Return the device info."""
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""Support for the Airly sensor service."""
|
"""Support for the Airly sensor service."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any, cast
|
from typing import cast
|
||||||
|
|
||||||
from homeassistant.components.sensor import ATTR_STATE_CLASS, SensorEntity
|
from homeassistant.components.sensor import ATTR_STATE_CLASS, SensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
@ -60,18 +60,18 @@ class AirlySensor(CoordinatorEntity, SensorEntity):
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._name = name
|
description = SENSOR_TYPES[kind]
|
||||||
self._description = SENSOR_TYPES[kind]
|
self._attr_device_class = description[ATTR_DEVICE_CLASS]
|
||||||
|
self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
|
||||||
|
self._attr_icon = description[ATTR_ICON]
|
||||||
|
self._attr_name = f"{name} {description[ATTR_LABEL]}"
|
||||||
|
self._attr_state_class = description[ATTR_STATE_CLASS]
|
||||||
|
self._attr_unique_id = (
|
||||||
|
f"{coordinator.latitude}-{coordinator.longitude}-{kind.lower()}"
|
||||||
|
)
|
||||||
|
self._attr_unit_of_measurement = description[ATTR_UNIT]
|
||||||
self.kind = kind
|
self.kind = kind
|
||||||
self._state = None
|
self._state = None
|
||||||
self._unit_of_measurement = None
|
|
||||||
self._attrs = {ATTR_ATTRIBUTION: ATTRIBUTION}
|
|
||||||
self._attr_state_class = self._description[ATTR_STATE_CLASS]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name."""
|
|
||||||
return f"{self._name} {self._description[ATTR_LABEL]}"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self) -> StateType:
|
def state(self) -> StateType:
|
||||||
|
@ -81,26 +81,6 @@ class AirlySensor(CoordinatorEntity, SensorEntity):
|
||||||
return round(cast(float, self._state))
|
return round(cast(float, self._state))
|
||||||
return round(cast(float, self._state), 1)
|
return round(cast(float, self._state), 1)
|
||||||
|
|
||||||
@property
|
|
||||||
def extra_state_attributes(self) -> dict[str, Any]:
|
|
||||||
"""Return the state attributes."""
|
|
||||||
return self._attrs
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self) -> str | None:
|
|
||||||
"""Return the icon."""
|
|
||||||
return self._description[ATTR_ICON]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self) -> str | None:
|
|
||||||
"""Return the device_class."""
|
|
||||||
return self._description[ATTR_DEVICE_CLASS]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self) -> str:
|
|
||||||
"""Return a unique_id for this entity."""
|
|
||||||
return f"{self.coordinator.latitude}-{self.coordinator.longitude}-{self.kind.lower()}"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self) -> DeviceInfo:
|
def device_info(self) -> DeviceInfo:
|
||||||
"""Return the device info."""
|
"""Return the device info."""
|
||||||
|
@ -115,8 +95,3 @@ class AirlySensor(CoordinatorEntity, SensorEntity):
|
||||||
"manufacturer": MANUFACTURER,
|
"manufacturer": MANUFACTURER,
|
||||||
"entry_type": "service",
|
"entry_type": "service",
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
|
||||||
def unit_of_measurement(self) -> str | None:
|
|
||||||
"""Return the unit the value is expressed in."""
|
|
||||||
return self._description[ATTR_UNIT]
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue