Small cleanup of Luftdaten constants (#61757)

This commit is contained in:
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 = "luftdaten"
DATA_LUFTDATEN_CLIENT = "data_luftdaten_client" DATA_LUFTDATEN_CLIENT = "data_luftdaten_client"
DATA_LUFTDATEN_LISTENER = "data_luftdaten_listener" DATA_LUFTDATEN_LISTENER = "data_luftdaten_listener"
DEFAULT_ATTRIBUTION = "Data provided by luftdaten.info"
PLATFORMS = [Platform.SENSOR] 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" TOPIC_UPDATE = f"{DOMAIN}_data_update"
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription( SensorEntityDescription(
key=SENSOR_TEMPERATURE, key="temperature",
name="Temperature", name="Temperature",
native_unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=TEMP_CELSIUS,
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
), ),
SensorEntityDescription( SensorEntityDescription(
key=SENSOR_HUMIDITY, key="humidity",
name="Humidity", name="Humidity",
icon="mdi:water-percent", icon="mdi:water-percent",
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
device_class=SensorDeviceClass.HUMIDITY, device_class=SensorDeviceClass.HUMIDITY,
), ),
SensorEntityDescription( SensorEntityDescription(
key=SENSOR_PRESSURE, key="pressure",
name="Pressure", name="Pressure",
icon="mdi:arrow-down-bold", icon="mdi:arrow-down-bold",
native_unit_of_measurement=PRESSURE_PA, native_unit_of_measurement=PRESSURE_PA,
device_class=SensorDeviceClass.PRESSURE, device_class=SensorDeviceClass.PRESSURE,
), ),
SensorEntityDescription( SensorEntityDescription(
key=SENSOR_PRESSURE_AT_SEALEVEL, key="pressure_at_sealevel",
name="Pressure at sealevel", name="Pressure at sealevel",
icon="mdi:download", icon="mdi:download",
native_unit_of_measurement=PRESSURE_PA, native_unit_of_measurement=PRESSURE_PA,
device_class=SensorDeviceClass.PRESSURE, device_class=SensorDeviceClass.PRESSURE,
), ),
SensorEntityDescription( SensorEntityDescription(
key=SENSOR_PM10, key="P1",
name="PM10", name="PM10",
icon="mdi:thought-bubble", icon="mdi:thought-bubble",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
), ),
SensorEntityDescription( SensorEntityDescription(
key=SENSOR_PM2_5, key="P2",
name="PM2.5", name="PM2.5",
icon="mdi:thought-bubble-outline", icon="mdi:thought-bubble-outline",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,

View File

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