mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +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,
|
||||||
ATTR_API_PM25_LIMIT,
|
ATTR_API_PM25_LIMIT,
|
||||||
ATTR_API_PM25_PERCENT,
|
ATTR_API_PM25_PERCENT,
|
||||||
|
DEFAULT_NAME,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
MANUFACTURER,
|
||||||
)
|
)
|
||||||
|
|
||||||
ATTRIBUTION = "Data provided by Airly"
|
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]
|
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities([AirlyAirQuality(coordinator, name)], False)
|
||||||
[AirlyAirQuality(coordinator, name, config_entry.unique_id)], False
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def round_state(func):
|
def round_state(func):
|
||||||
@ -60,11 +60,10 @@ def round_state(func):
|
|||||||
class AirlyAirQuality(AirQualityEntity):
|
class AirlyAirQuality(AirQualityEntity):
|
||||||
"""Define an Airly air quality."""
|
"""Define an Airly air quality."""
|
||||||
|
|
||||||
def __init__(self, coordinator, name, unique_id):
|
def __init__(self, coordinator, name):
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self.coordinator = coordinator
|
self.coordinator = coordinator
|
||||||
self._name = name
|
self._name = name
|
||||||
self._unique_id = unique_id
|
|
||||||
self._icon = "mdi:blur"
|
self._icon = "mdi:blur"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -108,7 +107,19 @@ class AirlyAirQuality(AirQualityEntity):
|
|||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return a unique_id for this entity."""
|
"""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
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
|
@ -15,5 +15,6 @@ ATTR_API_PRESSURE = "PRESSURE"
|
|||||||
ATTR_API_TEMPERATURE = "TEMPERATURE"
|
ATTR_API_TEMPERATURE = "TEMPERATURE"
|
||||||
DEFAULT_NAME = "Airly"
|
DEFAULT_NAME = "Airly"
|
||||||
DOMAIN = "airly"
|
DOMAIN = "airly"
|
||||||
|
MANUFACTURER = "Airly sp. z o.o."
|
||||||
MAX_REQUESTS_PER_DAY = 100
|
MAX_REQUESTS_PER_DAY = 100
|
||||||
NO_AIRLY_SENSORS = "There are no Airly sensors in this area yet."
|
NO_AIRLY_SENSORS = "There are no Airly sensors in this area yet."
|
||||||
|
@ -18,7 +18,9 @@ from .const import (
|
|||||||
ATTR_API_PM1,
|
ATTR_API_PM1,
|
||||||
ATTR_API_PRESSURE,
|
ATTR_API_PRESSURE,
|
||||||
ATTR_API_TEMPERATURE,
|
ATTR_API_TEMPERATURE,
|
||||||
|
DEFAULT_NAME,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
MANUFACTURER,
|
||||||
)
|
)
|
||||||
|
|
||||||
ATTRIBUTION = "Data provided by Airly"
|
ATTRIBUTION = "Data provided by Airly"
|
||||||
@ -65,8 +67,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
|
|
||||||
sensors = []
|
sensors = []
|
||||||
for sensor in SENSOR_TYPES:
|
for sensor in SENSOR_TYPES:
|
||||||
unique_id = f"{config_entry.unique_id}-{sensor.lower()}"
|
sensors.append(AirlySensor(coordinator, name, sensor))
|
||||||
sensors.append(AirlySensor(coordinator, name, sensor, unique_id))
|
|
||||||
|
|
||||||
async_add_entities(sensors, False)
|
async_add_entities(sensors, False)
|
||||||
|
|
||||||
@ -74,11 +75,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
class AirlySensor(Entity):
|
class AirlySensor(Entity):
|
||||||
"""Define an Airly sensor."""
|
"""Define an Airly sensor."""
|
||||||
|
|
||||||
def __init__(self, coordinator, name, kind, unique_id):
|
def __init__(self, coordinator, name, kind):
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self.coordinator = coordinator
|
self.coordinator = coordinator
|
||||||
self._name = name
|
self._name = name
|
||||||
self._unique_id = unique_id
|
|
||||||
self.kind = kind
|
self.kind = kind
|
||||||
self._device_class = None
|
self._device_class = None
|
||||||
self._state = None
|
self._state = None
|
||||||
@ -125,7 +125,19 @@ class AirlySensor(Entity):
|
|||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return a unique_id for this entity."""
|
"""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
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user