Small cleanup of Luftdaten constants (#61757)

pull/62147/head
Franck Nijhof 2021-12-16 21:25:24 +01:00 committed by GitHub
parent 0409665907
commit 4de4cc7bd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 30 deletions

View File

@ -32,55 +32,47 @@ _LOGGER = logging.getLogger(__name__)
DATA_LUFTDATEN = "luftdaten"
DATA_LUFTDATEN_CLIENT = "data_luftdaten_client"
DATA_LUFTDATEN_LISTENER = "data_luftdaten_listener"
DEFAULT_ATTRIBUTION = "Data provided by luftdaten.info"
PLATFORMS = [Platform.SENSOR]
SENSOR_HUMIDITY = "humidity"
SENSOR_PM10 = "P1"
SENSOR_PM2_5 = "P2"
SENSOR_PRESSURE = "pressure"
SENSOR_PRESSURE_AT_SEALEVEL = "pressure_at_sealevel"
SENSOR_TEMPERATURE = "temperature"
TOPIC_UPDATE = f"{DOMAIN}_data_update"
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key=SENSOR_TEMPERATURE,
key="temperature",
name="Temperature",
native_unit_of_measurement=TEMP_CELSIUS,
device_class=SensorDeviceClass.TEMPERATURE,
),
SensorEntityDescription(
key=SENSOR_HUMIDITY,
key="humidity",
name="Humidity",
icon="mdi:water-percent",
native_unit_of_measurement=PERCENTAGE,
device_class=SensorDeviceClass.HUMIDITY,
),
SensorEntityDescription(
key=SENSOR_PRESSURE,
key="pressure",
name="Pressure",
icon="mdi:arrow-down-bold",
native_unit_of_measurement=PRESSURE_PA,
device_class=SensorDeviceClass.PRESSURE,
),
SensorEntityDescription(
key=SENSOR_PRESSURE_AT_SEALEVEL,
key="pressure_at_sealevel",
name="Pressure at sealevel",
icon="mdi:download",
native_unit_of_measurement=PRESSURE_PA,
device_class=SensorDeviceClass.PRESSURE,
),
SensorEntityDescription(
key=SENSOR_PM10,
key="P1",
name="PM10",
icon="mdi:thought-bubble",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
),
SensorEntityDescription(
key=SENSOR_PM2_5,
key="P2",
name="PM2.5",
icon="mdi:thought-bubble-outline",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,

View File

@ -1,22 +1,10 @@
"""Support for Luftdaten sensors."""
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
from homeassistant.const import (
ATTR_ATTRIBUTION,
ATTR_LATITUDE,
ATTR_LONGITUDE,
CONF_SHOW_ON_MAP,
)
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, CONF_SHOW_ON_MAP
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from . import (
DATA_LUFTDATEN,
DATA_LUFTDATEN_CLIENT,
DEFAULT_ATTRIBUTION,
DOMAIN,
SENSOR_TYPES,
TOPIC_UPDATE,
)
from . import DATA_LUFTDATEN, DATA_LUFTDATEN_CLIENT, DOMAIN, SENSOR_TYPES, TOPIC_UPDATE
from .const import ATTR_SENSOR_ID
@ -36,6 +24,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
class LuftdatenSensor(SensorEntity):
"""Implementation of a Luftdaten sensor."""
_attr_attribution = "Data provided by luftdaten.info"
_attr_should_poll = False
def __init__(self, luftdaten, description: SensorEntityDescription, show):
@ -68,8 +57,6 @@ class LuftdatenSensor(SensorEntity):
@property
def extra_state_attributes(self):
"""Return the state attributes."""
self._attrs[ATTR_ATTRIBUTION] = DEFAULT_ATTRIBUTION
if self._data is not None:
try:
self._attrs[ATTR_SENSOR_ID] = self._data["sensor_id"]