1 """Feed Entity Manager Sensor support for GeoNet NZ Quakes Feeds."""
3 from __future__
import annotations
14 from .const
import DOMAIN, FEED
16 _LOGGER = logging.getLogger(__name__)
18 ATTR_STATUS =
"status"
19 ATTR_LAST_UPDATE =
"last_update"
20 ATTR_LAST_UPDATE_SUCCESSFUL =
"last_update_successful"
21 ATTR_LAST_TIMESTAMP =
"last_timestamp"
22 ATTR_CREATED =
"created"
23 ATTR_UPDATED =
"updated"
24 ATTR_REMOVED =
"removed"
26 DEFAULT_ICON =
"mdi:pulse"
27 DEFAULT_UNIT_OF_MEASUREMENT =
"quakes"
34 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
36 """Set up the GeoNet NZ Quakes Feed platform."""
37 manager = hass.data[DOMAIN][FEED][entry.entry_id]
40 _LOGGER.debug(
"Sensor setup done")
44 """Status sensor for the GeoNet NZ Quakes integration."""
46 _attr_should_poll =
False
48 def __init__(self, config_entry_id, config_unique_id, config_title, manager):
49 """Initialize entity."""
65 """Call when entity is added to hass."""
68 f
"geonetnz_quakes_status_{self._config_entry_id}",
71 _LOGGER.debug(
"Waiting for updates %s", self.
_config_entry_id_config_entry_id)
76 """Call when entity will be removed from hass."""
82 """Call status update method."""
83 _LOGGER.debug(
"Received status update for %s", self.
_config_entry_id_config_entry_id)
87 """Update this entity from the data held in the feed manager."""
90 status_info = self.
_manager_manager.status_info()
95 """Update the internal state from the provided information."""
96 self.
_status_status = status_info.status
98 dt_util.as_utc(status_info.last_update)
if status_info.last_update
else None
100 if status_info.last_update_successful:
102 status_info.last_update_successful
107 self.
_total_total = status_info.total
108 self.
_created_created = status_info.created
109 self.
_updated_updated = status_info.updated
110 self.
_removed_removed = status_info.removed
114 """Return the state of the sensor."""
119 """Return a unique ID containing latitude/longitude."""
124 """Return the name of the entity."""
125 return f
"GeoNet NZ Quakes ({self._config_title})"
129 """Return the icon to use in the frontend, if any."""
134 """Return the unit of measurement."""
135 return DEFAULT_UNIT_OF_MEASUREMENT
139 """Return the device state attributes."""
143 (ATTR_STATUS, self.
_status_status),
147 (ATTR_CREATED, self.
_created_created),
148 (ATTR_UPDATED, self.
_updated_updated),
149 (ATTR_REMOVED, self.
_removed_removed),
151 if value
or isinstance(value, bool)
def __init__(self, config_entry_id, config_unique_id, config_title, manager)
None async_will_remove_from_hass(self)
None async_added_to_hass(self)
def native_unit_of_measurement(self)
def _update_status_callback(self)
def _update_from_status_info(self, status_info)
def extra_state_attributes(self)
None async_schedule_update_ha_state(self, bool force_refresh=False)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)