1 """Sensor platform for FireServiceRota integration."""
13 from .const
import DATA_CLIENT, DOMAIN
as FIRESERVICEROTA_DOMAIN
15 _LOGGER = logging.getLogger(__name__)
19 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
21 """Set up FireServiceRota sensor based on a config entry."""
22 client = hass.data[FIRESERVICEROTA_DOMAIN][entry.entry_id][DATA_CLIENT]
29 """Representation of FireServiceRota incidents sensor."""
31 _attr_should_poll =
False
32 _attr_has_entity_name =
True
33 _attr_translation_key =
"incidents"
45 """Return the icon to use in the frontend."""
50 return "mdi:ambulance"
52 return "mdi:fire-truck"
56 """Return the state of the sensor."""
61 """Return available attributes for sensor."""
62 attr: dict[str, Any] = {}
71 "message_to_speech_url",
79 attr[value] = data[value]
81 if "address" not in data:
84 for address_value
in (
90 if address_value
in data[
"address"]:
91 attr[address_value] = data[
"address"][address_value]
96 """Run when about to be added to hass."""
100 self.
_state_state = state.state
104 _LOGGER.debug(
"Restored entity 'Incidents' to: %s", self.
_state_state)
109 f
"{FIRESERVICEROTA_DOMAIN}_{self._entry_id}_update",
116 """Handle updated data from the data client."""
117 data = self.
_client_client.websocket.incident_data
118 if not data
or "body" not in data:
121 self.
_state_state = data[
"body"]
def __init__(self, client)
None async_added_to_hass(self)
dict[str, Any] extra_state_attributes(self)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
State|None async_get_last_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)