Use shorthand attributes in GDACS (#98173)
parent
fb56dd0615
commit
604964d5f0
|
@ -1,6 +1,7 @@
|
||||||
"""Feed Entity Manager Sensor support for GDACS Feed."""
|
"""Feed Entity Manager Sensor support for GDACS Feed."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity
|
from homeassistant.components.sensor import SensorEntity
|
||||||
|
@ -33,21 +34,22 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the GDACS Feed platform."""
|
"""Set up the GDACS Feed platform."""
|
||||||
manager = hass.data[DOMAIN][FEED][entry.entry_id]
|
manager = hass.data[DOMAIN][FEED][entry.entry_id]
|
||||||
sensor = GdacsSensor(entry.entry_id, entry.unique_id, entry.title, manager)
|
sensor = GdacsSensor(entry, manager)
|
||||||
async_add_entities([sensor])
|
async_add_entities([sensor])
|
||||||
_LOGGER.debug("Sensor setup done")
|
|
||||||
|
|
||||||
|
|
||||||
class GdacsSensor(SensorEntity):
|
class GdacsSensor(SensorEntity):
|
||||||
"""Status sensor for the GDACS integration."""
|
"""Status sensor for the GDACS integration."""
|
||||||
|
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
_attr_icon = DEFAULT_ICON
|
||||||
|
_attr_native_unit_of_measurement = DEFAULT_UNIT_OF_MEASUREMENT
|
||||||
|
|
||||||
def __init__(self, config_entry_id, config_unique_id, config_title, manager):
|
def __init__(self, config_entry: ConfigEntry, manager) -> None:
|
||||||
"""Initialize entity."""
|
"""Initialize entity."""
|
||||||
self._config_entry_id = config_entry_id
|
self._config_entry_id = config_entry.entry_id
|
||||||
self._config_unique_id = config_unique_id
|
self._attr_unique_id = config_entry.unique_id
|
||||||
self._config_title = config_title
|
self._attr_name = f"GDACS ({config_entry.title})"
|
||||||
self._manager = manager
|
self._manager = manager
|
||||||
self._status = None
|
self._status = None
|
||||||
self._last_update = None
|
self._last_update = None
|
||||||
|
@ -57,7 +59,7 @@ class GdacsSensor(SensorEntity):
|
||||||
self._created = None
|
self._created = None
|
||||||
self._updated = None
|
self._updated = None
|
||||||
self._removed = None
|
self._removed = None
|
||||||
self._remove_signal_status = None
|
self._remove_signal_status: Callable[[], None] | None = None
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Call when entity is added to hass."""
|
"""Call when entity is added to hass."""
|
||||||
|
@ -112,26 +114,6 @@ class GdacsSensor(SensorEntity):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._total
|
return self._total
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self) -> str | None:
|
|
||||||
"""Return a unique ID containing latitude/longitude."""
|
|
||||||
return self._config_unique_id
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str | None:
|
|
||||||
"""Return the name of the entity."""
|
|
||||||
return f"GDACS ({self._config_title})"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Return the icon to use in the frontend, if any."""
|
|
||||||
return DEFAULT_ICON
|
|
||||||
|
|
||||||
@property
|
|
||||||
def native_unit_of_measurement(self):
|
|
||||||
"""Return the unit of measurement."""
|
|
||||||
return DEFAULT_UNIT_OF_MEASUREMENT
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
"""Return the device state attributes."""
|
"""Return the device state attributes."""
|
||||||
|
|
Loading…
Reference in New Issue