mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Add device_info property and simplify generation of unique_id for Airly integration (#38479)
This commit is contained in:
parent
56f8ced267
commit
8258dcf41d
@ -18,7 +18,9 @@ from .const import (
|
||||
ATTR_API_PM25,
|
||||
ATTR_API_PM25_LIMIT,
|
||||
ATTR_API_PM25_PERCENT,
|
||||
DEFAULT_NAME,
|
||||
DOMAIN,
|
||||
MANUFACTURER,
|
||||
)
|
||||
|
||||
ATTRIBUTION = "Data provided by Airly"
|
||||
@ -40,9 +42,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
|
||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
async_add_entities(
|
||||
[AirlyAirQuality(coordinator, name, config_entry.unique_id)], False
|
||||
)
|
||||
async_add_entities([AirlyAirQuality(coordinator, name)], False)
|
||||
|
||||
|
||||
def round_state(func):
|
||||
@ -60,11 +60,10 @@ def round_state(func):
|
||||
class AirlyAirQuality(AirQualityEntity):
|
||||
"""Define an Airly air quality."""
|
||||
|
||||
def __init__(self, coordinator, name, unique_id):
|
||||
def __init__(self, coordinator, name):
|
||||
"""Initialize."""
|
||||
self.coordinator = coordinator
|
||||
self._name = name
|
||||
self._unique_id = unique_id
|
||||
self._icon = "mdi:blur"
|
||||
|
||||
@property
|
||||
@ -108,7 +107,19 @@ class AirlyAirQuality(AirQualityEntity):
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return a unique_id for this entity."""
|
||||
return self._unique_id
|
||||
return f"{self.coordinator.latitude}-{self.coordinator.longitude}"
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device info."""
|
||||
return {
|
||||
"identifiers": {
|
||||
(DOMAIN, self.coordinator.latitude, self.coordinator.longitude)
|
||||
},
|
||||
"name": DEFAULT_NAME,
|
||||
"manufacturer": MANUFACTURER,
|
||||
"entry_type": "service",
|
||||
}
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
|
@ -15,5 +15,6 @@ ATTR_API_PRESSURE = "PRESSURE"
|
||||
ATTR_API_TEMPERATURE = "TEMPERATURE"
|
||||
DEFAULT_NAME = "Airly"
|
||||
DOMAIN = "airly"
|
||||
MANUFACTURER = "Airly sp. z o.o."
|
||||
MAX_REQUESTS_PER_DAY = 100
|
||||
NO_AIRLY_SENSORS = "There are no Airly sensors in this area yet."
|
||||
|
@ -18,7 +18,9 @@ from .const import (
|
||||
ATTR_API_PM1,
|
||||
ATTR_API_PRESSURE,
|
||||
ATTR_API_TEMPERATURE,
|
||||
DEFAULT_NAME,
|
||||
DOMAIN,
|
||||
MANUFACTURER,
|
||||
)
|
||||
|
||||
ATTRIBUTION = "Data provided by Airly"
|
||||
@ -65,8 +67,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
|
||||
sensors = []
|
||||
for sensor in SENSOR_TYPES:
|
||||
unique_id = f"{config_entry.unique_id}-{sensor.lower()}"
|
||||
sensors.append(AirlySensor(coordinator, name, sensor, unique_id))
|
||||
sensors.append(AirlySensor(coordinator, name, sensor))
|
||||
|
||||
async_add_entities(sensors, False)
|
||||
|
||||
@ -74,11 +75,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
class AirlySensor(Entity):
|
||||
"""Define an Airly sensor."""
|
||||
|
||||
def __init__(self, coordinator, name, kind, unique_id):
|
||||
def __init__(self, coordinator, name, kind):
|
||||
"""Initialize."""
|
||||
self.coordinator = coordinator
|
||||
self._name = name
|
||||
self._unique_id = unique_id
|
||||
self.kind = kind
|
||||
self._device_class = None
|
||||
self._state = None
|
||||
@ -125,7 +125,19 @@ class AirlySensor(Entity):
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return a unique_id for this entity."""
|
||||
return self._unique_id
|
||||
return f"{self.coordinator.latitude}-{self.coordinator.longitude}-{self.kind.lower()}"
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device info."""
|
||||
return {
|
||||
"identifiers": {
|
||||
(DOMAIN, self.coordinator.latitude, self.coordinator.longitude)
|
||||
},
|
||||
"name": DEFAULT_NAME,
|
||||
"manufacturer": MANUFACTURER,
|
||||
"entry_type": "service",
|
||||
}
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user