1 """Switch platform for motionEye."""
3 from __future__
import annotations
5 from types
import MappingProxyType
8 from motioneye_client.client
import MotionEyeClient
9 from motioneye_client.const
import (
25 from .
import get_camera_from_cameras, listen_for_new_cameras
26 from .const
import CONF_CLIENT, CONF_COORDINATOR, DOMAIN, TYPE_MOTIONEYE_SWITCH_BASE
27 from .entity
import MotionEyeEntity
29 MOTIONEYE_SWITCHES = [
31 key=KEY_MOTION_DETECTION,
32 translation_key=
"motion_detection",
33 entity_registry_enabled_default=
True,
34 entity_category=EntityCategory.CONFIG,
38 translation_key=
"text_overlay",
39 entity_registry_enabled_default=
False,
40 entity_category=EntityCategory.CONFIG,
43 key=KEY_VIDEO_STREAMING,
44 translation_key=
"video_streaming",
45 entity_registry_enabled_default=
False,
46 entity_category=EntityCategory.CONFIG,
50 translation_key=
"still_images",
51 entity_registry_enabled_default=
True,
52 entity_category=EntityCategory.CONFIG,
56 translation_key=
"movies",
57 entity_registry_enabled_default=
True,
58 entity_category=EntityCategory.CONFIG,
61 key=KEY_UPLOAD_ENABLED,
62 translation_key=
"upload_enabled",
63 entity_registry_enabled_default=
False,
64 entity_category=EntityCategory.CONFIG,
70 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
72 """Set up motionEye from a config entry."""
73 entry_data = hass.data[DOMAIN][entry.entry_id]
76 def camera_add(camera: dict[str, Any]) ->
None:
77 """Add a new motionEye camera."""
83 entry_data[CONF_CLIENT],
84 entry_data[CONF_COORDINATOR],
88 for entity_description
in MOTIONEYE_SWITCHES
96 """MotionEyeSwitch switch class."""
100 config_entry_id: str,
101 camera: dict[str, Any],
102 client: MotionEyeClient,
103 coordinator: DataUpdateCoordinator,
104 options: MappingProxyType[str, str],
105 entity_description: SwitchEntityDescription,
107 """Initialize the switch."""
110 f
"{TYPE_MOTIONEYE_SWITCH_BASE}_{entity_description.key}",
120 """Return true if the switch is on."""
126 """Set a switch value."""
136 """Turn on the switch."""
140 """Turn off the switch."""
145 """Handle updated data from the coordinator."""
None __init__(self, str config_entry_id, dict[str, Any] camera, MotionEyeClient client, DataUpdateCoordinator coordinator, MappingProxyType[str, str] options, SwitchEntityDescription entity_description)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None _async_send_set_camera(self, bool value)
None _handle_coordinator_update(self)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
None listen_for_new_cameras(HomeAssistant hass, ConfigEntry entry, Callable add_func)
dict[str, Any]|None get_camera_from_cameras(int camera_id, dict[str, Any]|None data)