1 """Switch platform for FireServiceRota integration."""
12 from .const
import DATA_CLIENT, DATA_COORDINATOR, DOMAIN
as FIRESERVICEROTA_DOMAIN
14 _LOGGER = logging.getLogger(__name__)
18 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
20 """Set up FireServiceRota switch based on a config entry."""
21 client = hass.data[FIRESERVICEROTA_DOMAIN][entry.entry_id][DATA_CLIENT]
23 coordinator = hass.data[FIRESERVICEROTA_DOMAIN][entry.entry_id][DATA_COORDINATOR]
29 """Representation of an FireServiceRota switch."""
31 _attr_should_poll =
False
32 _attr_has_entity_name =
True
33 _attr_translation_key =
"incident_response"
35 def __init__(self, coordinator, client, entry):
48 """Return the icon to use in the frontend."""
52 return "mdi:account-off-outline"
58 """Get the assumed state of the switch."""
63 """Return if switch is available."""
64 return self.
_client_client.on_duty
68 """Return available attributes for switch."""
69 attr: dict[str, Any] = {}
84 "available_at_incident_creation",
85 "active_duty_function_ids",
91 """Send Acknowledge response status."""
95 """Send Reject response status."""
99 """Send response status."""
100 if not self.
_client_client.on_duty:
102 "Cannot send incident response when not on duty",
110 """Register update callback."""
114 f
"{FIRESERVICEROTA_DOMAIN}_{self._entry_id}_update",
124 """Handle updated incident data from the client."""
128 """Update FireServiceRota response data."""
129 data = await self.
_client_client.async_response_update()
131 if not data
or "status" not in data:
134 self.
_state_state = data[
"status"] ==
"acknowledged"
138 _LOGGER.debug(
"Set state of entity 'Response Switch' to '%s'", self.
_state_state)
None async_turn_off(self, **Any kwargs)
None async_added_to_hass(self)
None async_set_response(self, value)
def __init__(self, coordinator, client, entry)
None async_turn_on(self, **Any kwargs)
dict[str, Any] extra_state_attributes(self)
None async_schedule_update_ha_state(self, bool force_refresh=False)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
None async_add_listener(HomeAssistant hass, Callable[[], None] listener)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)