Rename Luftdaten -> Sensor.Community (#62865)
This commit is contained in:
parent
4edf6163f7
commit
4fe62a251d
8 changed files with 36 additions and 35 deletions
|
@ -1,4 +1,8 @@
|
||||||
"""Support for Luftdaten stations."""
|
"""Support for Sensor.Community stations.
|
||||||
|
|
||||||
|
Sensor.Community was previously called Luftdaten, hence the domain differs from
|
||||||
|
the integration name.
|
||||||
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
@ -23,7 +27,7 @@ CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up Luftdaten as config entry."""
|
"""Set up Sensor.Community as config entry."""
|
||||||
|
|
||||||
# For backwards compat, set unique ID
|
# For backwards compat, set unique ID
|
||||||
if entry.unique_id is None:
|
if entry.unique_id is None:
|
||||||
|
@ -31,26 +35,26 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
entry, unique_id=str(entry.data[CONF_SENSOR_ID])
|
entry, unique_id=str(entry.data[CONF_SENSOR_ID])
|
||||||
)
|
)
|
||||||
|
|
||||||
luftdaten = Luftdaten(entry.data[CONF_SENSOR_ID])
|
sensor_community = Luftdaten(entry.data[CONF_SENSOR_ID])
|
||||||
|
|
||||||
async def async_update() -> dict[str, float | int]:
|
async def async_update() -> dict[str, float | int]:
|
||||||
"""Update sensor/binary sensor data."""
|
"""Update sensor/binary sensor data."""
|
||||||
try:
|
try:
|
||||||
await luftdaten.get_data()
|
await sensor_community.get_data()
|
||||||
except LuftdatenError as err:
|
except LuftdatenError as err:
|
||||||
raise UpdateFailed("Unable to retrieve data from luftdaten.info") from err
|
raise UpdateFailed("Unable to retrieve data from Sensor.Community") from err
|
||||||
|
|
||||||
if not luftdaten.values:
|
if not sensor_community.values:
|
||||||
raise UpdateFailed("Did not receive sensor data from luftdaten.info")
|
raise UpdateFailed("Did not receive sensor data from Sensor.Community")
|
||||||
|
|
||||||
data: dict[str, float | int] = luftdaten.values
|
data: dict[str, float | int] = sensor_community.values
|
||||||
data.update(luftdaten.meta)
|
data.update(sensor_community.meta)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
coordinator: DataUpdateCoordinator[dict[Any, Any]] = DataUpdateCoordinator(
|
coordinator: DataUpdateCoordinator[dict[Any, Any]] = DataUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
name=f"{DOMAIN}_{luftdaten.sensor_id}",
|
name=f"{DOMAIN}_{sensor_community.sensor_id}",
|
||||||
update_interval=DEFAULT_SCAN_INTERVAL,
|
update_interval=DEFAULT_SCAN_INTERVAL,
|
||||||
update_method=async_update,
|
update_method=async_update,
|
||||||
)
|
)
|
||||||
|
@ -63,8 +67,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload an Luftdaten config entry."""
|
"""Unload an Sensor.Community config entry."""
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||||
if unload_ok:
|
|
||||||
del hass.data[DOMAIN][entry.entry_id]
|
del hass.data[DOMAIN][entry.entry_id]
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
"""Config flow to configure the Luftdaten component."""
|
"""Config flow to configure the Sensor.Community integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
@ -16,8 +16,8 @@ import homeassistant.helpers.config_validation as cv
|
||||||
from .const import CONF_SENSOR_ID, DOMAIN
|
from .const import CONF_SENSOR_ID, DOMAIN
|
||||||
|
|
||||||
|
|
||||||
class LuftDatenFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
class SensorCommunityFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
"""Handle a Luftdaten config flow."""
|
"""Handle a Sensor.Community config flow."""
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
|
@ -45,10 +45,10 @@ class LuftDatenFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
await self.async_set_unique_id(str(user_input[CONF_SENSOR_ID]))
|
await self.async_set_unique_id(str(user_input[CONF_SENSOR_ID]))
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
luftdaten = Luftdaten(user_input[CONF_SENSOR_ID])
|
sensor_community = Luftdaten(user_input[CONF_SENSOR_ID])
|
||||||
try:
|
try:
|
||||||
await luftdaten.get_data()
|
await sensor_community.get_data()
|
||||||
valid = await luftdaten.validate_sensor()
|
valid = await sensor_community.validate_sensor()
|
||||||
except LuftdatenConnectionError:
|
except LuftdatenConnectionError:
|
||||||
return self._show_form({CONF_SENSOR_ID: "cannot_connect"})
|
return self._show_form({CONF_SENSOR_ID: "cannot_connect"})
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
"""Define constants for the Luftdaten component."""
|
"""Define constants for the Sensor.Community integration."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
ATTR_SENSOR_ID = "sensor_id"
|
ATTR_SENSOR_ID = "sensor_id"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"domain": "luftdaten",
|
"domain": "luftdaten",
|
||||||
"name": "Luftdaten",
|
"name": "Sensor.Community",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/luftdaten",
|
"documentation": "https://www.home-assistant.io/integrations/luftdaten",
|
||||||
"requirements": ["luftdaten==0.7.1"],
|
"requirements": ["luftdaten==0.7.1"],
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
"""Support for Luftdaten sensors."""
|
"""Support for Sensor.Community sensors."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import cast
|
from typing import cast
|
||||||
|
@ -79,11 +79,11 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up a Luftdaten sensor based on a config entry."""
|
"""Set up a Sensor.Community sensor based on a config entry."""
|
||||||
coordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
LuftdatenSensor(
|
SensorCommunitySensor(
|
||||||
coordinator=coordinator,
|
coordinator=coordinator,
|
||||||
description=description,
|
description=description,
|
||||||
sensor_id=entry.data[CONF_SENSOR_ID],
|
sensor_id=entry.data[CONF_SENSOR_ID],
|
||||||
|
@ -94,10 +94,10 @@ async def async_setup_entry(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class LuftdatenSensor(CoordinatorEntity, SensorEntity):
|
class SensorCommunitySensor(CoordinatorEntity, SensorEntity):
|
||||||
"""Implementation of a Luftdaten sensor."""
|
"""Implementation of a Sensor.Community sensor."""
|
||||||
|
|
||||||
_attr_attribution = "Data provided by luftdaten.info"
|
_attr_attribution = "Data provided by Sensor.Community"
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -108,7 +108,7 @@ class LuftdatenSensor(CoordinatorEntity, SensorEntity):
|
||||||
sensor_id: int,
|
sensor_id: int,
|
||||||
show_on_map: bool,
|
show_on_map: bool,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the Luftdaten sensor."""
|
"""Initialize the Sensor.Community sensor."""
|
||||||
super().__init__(coordinator=coordinator)
|
super().__init__(coordinator=coordinator)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_unique_id = f"{sensor_id}_{description.key}"
|
self._attr_unique_id = f"{sensor_id}_{description.key}"
|
||||||
|
@ -119,7 +119,7 @@ class LuftdatenSensor(CoordinatorEntity, SensorEntity):
|
||||||
configuration_url=f"https://devices.sensor.community/sensors/{sensor_id}/settings",
|
configuration_url=f"https://devices.sensor.community/sensors/{sensor_id}/settings",
|
||||||
identifiers={(DOMAIN, str(sensor_id))},
|
identifiers={(DOMAIN, str(sensor_id))},
|
||||||
name=f"Sensor {sensor_id}",
|
name=f"Sensor {sensor_id}",
|
||||||
manufacturer="Luftdaten.info",
|
manufacturer="Sensor.Community",
|
||||||
)
|
)
|
||||||
|
|
||||||
if show_on_map:
|
if show_on_map:
|
||||||
|
|
|
@ -2,9 +2,8 @@
|
||||||
"config": {
|
"config": {
|
||||||
"step": {
|
"step": {
|
||||||
"user": {
|
"user": {
|
||||||
"title": "Define Luftdaten",
|
|
||||||
"data": {
|
"data": {
|
||||||
"station_id": "Luftdaten Sensor ID",
|
"station_id": "Sensor ID",
|
||||||
"show_on_map": "Show on map"
|
"show_on_map": "Show on map"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,8 @@
|
||||||
"user": {
|
"user": {
|
||||||
"data": {
|
"data": {
|
||||||
"show_on_map": "Show on map",
|
"show_on_map": "Show on map",
|
||||||
"station_id": "Luftdaten Sensor ID"
|
"station_id": "Sensor ID"
|
||||||
},
|
}
|
||||||
"title": "Define Luftdaten"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ async def test_luftdaten_sensors(
|
||||||
device_entry = device_registry.async_get(entry.device_id)
|
device_entry = device_registry.async_get(entry.device_id)
|
||||||
assert device_entry
|
assert device_entry
|
||||||
assert device_entry.identifiers == {(DOMAIN, "12345")}
|
assert device_entry.identifiers == {(DOMAIN, "12345")}
|
||||||
assert device_entry.manufacturer == "Luftdaten.info"
|
assert device_entry.manufacturer == "Sensor.Community"
|
||||||
assert device_entry.name == "Sensor 12345"
|
assert device_entry.name == "Sensor 12345"
|
||||||
assert (
|
assert (
|
||||||
device_entry.configuration_url
|
device_entry.configuration_url
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue