1 """Fully Kiosk Browser switch."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
9 from fullykiosk
import FullyKiosk
16 from .
import FullyKioskConfigEntry
17 from .coordinator
import FullyKioskDataUpdateCoordinator
18 from .entity
import FullyKioskEntity
21 @dataclass(frozen=True, kw_only=True)
23 """Fully Kiosk Browser switch entity description."""
25 on_action: Callable[[FullyKiosk], Any]
26 off_action: Callable[[FullyKiosk], Any]
27 is_on_fn: Callable[[dict[str, Any]], Any]
28 mqtt_on_event: str |
None
29 mqtt_off_event: str |
None
32 SWITCHES: tuple[FullySwitchEntityDescription, ...] = (
35 translation_key=
"screensaver",
36 on_action=
lambda fully: fully.startScreensaver(),
37 off_action=
lambda fully: fully.stopScreensaver(),
38 is_on_fn=
lambda data: data.get(
"isInScreensaver"),
39 mqtt_on_event=
"onScreensaverStart",
40 mqtt_off_event=
"onScreensaverStop",
44 translation_key=
"maintenance",
45 entity_category=EntityCategory.CONFIG,
46 on_action=
lambda fully: fully.enableLockedMode(),
47 off_action=
lambda fully: fully.disableLockedMode(),
48 is_on_fn=
lambda data: data.get(
"maintenanceMode"),
54 translation_key=
"kiosk",
55 entity_category=EntityCategory.CONFIG,
56 on_action=
lambda fully: fully.lockKiosk(),
57 off_action=
lambda fully: fully.unlockKiosk(),
58 is_on_fn=
lambda data: data.get(
"kioskLocked"),
63 key=
"motion-detection",
64 translation_key=
"motion_detection",
65 entity_category=EntityCategory.CONFIG,
66 on_action=
lambda fully: fully.enableMotionDetection(),
67 off_action=
lambda fully: fully.disableMotionDetection(),
68 is_on_fn=
lambda data: data[
"settings"].
get(
"motionDetection"),
74 translation_key=
"screen_on",
75 on_action=
lambda fully: fully.screenOn(),
76 off_action=
lambda fully: fully.screenOff(),
77 is_on_fn=
lambda data: data.get(
"screenOn"),
78 mqtt_on_event=
"screenOn",
79 mqtt_off_event=
"screenOff",
86 config_entry: FullyKioskConfigEntry,
87 async_add_entities: AddEntitiesCallback,
89 """Set up the Fully Kiosk Browser switch."""
90 coordinator = config_entry.runtime_data
98 """Fully Kiosk Browser switch entity."""
100 entity_description: FullySwitchEntityDescription
104 coordinator: FullyKioskDataUpdateCoordinator,
105 description: FullySwitchEntityDescription,
107 """Initialize the Fully Kiosk Browser switch entity."""
110 self.
_attr_unique_id_attr_unique_id = f
"{coordinator.data['deviceID']}-{description.key}"
115 """When entity is added to hass."""
119 description.mqtt_off_event, self.
_turn_off_turn_off
122 description.mqtt_on_event, self.
_turn_on_turn_on
126 """Close MQTT subscriptions when removed."""
134 """Turn the entity on."""
139 """Turn the entity off."""
144 """Optimistically turn off."""
149 """Optimistically turn on."""
155 """Handle updated data from the coordinator."""
CALLBACK_TYPE|None mqtt_subscribe(self, str|None event, CALLBACK_TYPE event_callback)
None async_turn_off(self, **Any kwargs)
None async_will_remove_from_hass(self)
None async_added_to_hass(self)
None _turn_on(self, **Any kwargs)
None _handle_coordinator_update(self)
None _turn_off(self, **Any kwargs)
None __init__(self, FullyKioskDataUpdateCoordinator coordinator, FullySwitchEntityDescription description)
None async_turn_on(self, **Any kwargs)
None async_write_ha_state(self)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, FullyKioskConfigEntry config_entry, AddEntitiesCallback async_add_entities)