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
|
||||
|
||||
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:
|
||||
"""Set up Luftdaten as config entry."""
|
||||
"""Set up Sensor.Community as config entry."""
|
||||
|
||||
# For backwards compat, set unique ID
|
||||
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])
|
||||
)
|
||||
|
||||
luftdaten = Luftdaten(entry.data[CONF_SENSOR_ID])
|
||||
sensor_community = Luftdaten(entry.data[CONF_SENSOR_ID])
|
||||
|
||||
async def async_update() -> dict[str, float | int]:
|
||||
"""Update sensor/binary sensor data."""
|
||||
try:
|
||||
await luftdaten.get_data()
|
||||
await sensor_community.get_data()
|
||||
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:
|
||||
raise UpdateFailed("Did not receive sensor data from luftdaten.info")
|
||||
if not sensor_community.values:
|
||||
raise UpdateFailed("Did not receive sensor data from Sensor.Community")
|
||||
|
||||
data: dict[str, float | int] = luftdaten.values
|
||||
data.update(luftdaten.meta)
|
||||
data: dict[str, float | int] = sensor_community.values
|
||||
data.update(sensor_community.meta)
|
||||
return data
|
||||
|
||||
coordinator: DataUpdateCoordinator[dict[Any, Any]] = DataUpdateCoordinator(
|
||||
hass,
|
||||
_LOGGER,
|
||||
name=f"{DOMAIN}_{luftdaten.sensor_id}",
|
||||
name=f"{DOMAIN}_{sensor_community.sensor_id}",
|
||||
update_interval=DEFAULT_SCAN_INTERVAL,
|
||||
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:
|
||||
"""Unload an Luftdaten config entry."""
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
"""Unload an Sensor.Community config entry."""
|
||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||
del hass.data[DOMAIN][entry.entry_id]
|
||||
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 typing import Any
|
||||
|
@ -16,8 +16,8 @@ import homeassistant.helpers.config_validation as cv
|
|||
from .const import CONF_SENSOR_ID, DOMAIN
|
||||
|
||||
|
||||
class LuftDatenFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a Luftdaten config flow."""
|
||||
class SensorCommunityFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a Sensor.Community config flow."""
|
||||
|
||||
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]))
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
luftdaten = Luftdaten(user_input[CONF_SENSOR_ID])
|
||||
sensor_community = Luftdaten(user_input[CONF_SENSOR_ID])
|
||||
try:
|
||||
await luftdaten.get_data()
|
||||
valid = await luftdaten.validate_sensor()
|
||||
await sensor_community.get_data()
|
||||
valid = await sensor_community.validate_sensor()
|
||||
except LuftdatenConnectionError:
|
||||
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
|
||||
|
||||
ATTR_SENSOR_ID = "sensor_id"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"domain": "luftdaten",
|
||||
"name": "Luftdaten",
|
||||
"name": "Sensor.Community",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/luftdaten",
|
||||
"requirements": ["luftdaten==0.7.1"],
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
"""Support for Luftdaten sensors."""
|
||||
"""Support for Sensor.Community sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import cast
|
||||
|
@ -79,11 +79,11 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> 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]
|
||||
|
||||
async_add_entities(
|
||||
LuftdatenSensor(
|
||||
SensorCommunitySensor(
|
||||
coordinator=coordinator,
|
||||
description=description,
|
||||
sensor_id=entry.data[CONF_SENSOR_ID],
|
||||
|
@ -94,10 +94,10 @@ async def async_setup_entry(
|
|||
)
|
||||
|
||||
|
||||
class LuftdatenSensor(CoordinatorEntity, SensorEntity):
|
||||
"""Implementation of a Luftdaten sensor."""
|
||||
class SensorCommunitySensor(CoordinatorEntity, SensorEntity):
|
||||
"""Implementation of a Sensor.Community sensor."""
|
||||
|
||||
_attr_attribution = "Data provided by luftdaten.info"
|
||||
_attr_attribution = "Data provided by Sensor.Community"
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(
|
||||
|
@ -108,7 +108,7 @@ class LuftdatenSensor(CoordinatorEntity, SensorEntity):
|
|||
sensor_id: int,
|
||||
show_on_map: bool,
|
||||
) -> None:
|
||||
"""Initialize the Luftdaten sensor."""
|
||||
"""Initialize the Sensor.Community sensor."""
|
||||
super().__init__(coordinator=coordinator)
|
||||
self.entity_description = description
|
||||
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",
|
||||
identifiers={(DOMAIN, str(sensor_id))},
|
||||
name=f"Sensor {sensor_id}",
|
||||
manufacturer="Luftdaten.info",
|
||||
manufacturer="Sensor.Community",
|
||||
)
|
||||
|
||||
if show_on_map:
|
||||
|
|
|
@ -2,9 +2,8 @@
|
|||
"config": {
|
||||
"step": {
|
||||
"user": {
|
||||
"title": "Define Luftdaten",
|
||||
"data": {
|
||||
"station_id": "Luftdaten Sensor ID",
|
||||
"station_id": "Sensor ID",
|
||||
"show_on_map": "Show on map"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,8 @@
|
|||
"user": {
|
||||
"data": {
|
||||
"show_on_map": "Show on map",
|
||||
"station_id": "Luftdaten Sensor ID"
|
||||
},
|
||||
"title": "Define Luftdaten"
|
||||
"station_id": "Sensor ID"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ async def test_luftdaten_sensors(
|
|||
device_entry = device_registry.async_get(entry.device_id)
|
||||
assert device_entry
|
||||
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.configuration_url
|
||||
|
|
Loading…
Add table
Reference in a new issue