1 """Support for EZVIZ Switch sensors."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
8 from pyezviz.constants
import DeviceSwitchType, SupportExt
9 from pyezviz.exceptions
import HTTPError, PyEzvizError
14 SwitchEntityDescription,
21 from .const
import DATA_COORDINATOR, DOMAIN
22 from .coordinator
import EzvizDataUpdateCoordinator
23 from .entity
import EzvizEntity
26 @dataclass(frozen=True, kw_only=True)
28 """Describe a EZVIZ switch."""
30 supported_ext: str |
None
33 SWITCH_TYPES: dict[int, EzvizSwitchEntityDescription] = {
36 translation_key=
"status_light",
37 device_class=SwitchDeviceClass.SWITCH,
42 translation_key=
"privacy",
43 device_class=SwitchDeviceClass.SWITCH,
44 supported_ext=
str(SupportExt.SupportPtzPrivacy.value),
48 translation_key=
"infrared_light",
49 device_class=SwitchDeviceClass.SWITCH,
50 supported_ext=
str(SupportExt.SupportCloseInfraredLight.value),
54 translation_key=
"sleep",
55 device_class=SwitchDeviceClass.SWITCH,
56 supported_ext=
str(SupportExt.SupportSleep.value),
60 translation_key=
"audio",
61 device_class=SwitchDeviceClass.SWITCH,
62 supported_ext=
str(SupportExt.SupportAudioOnoff.value),
66 translation_key=
"motion_tracking",
67 device_class=SwitchDeviceClass.SWITCH,
68 supported_ext=
str(SupportExt.SupportIntelligentTrack.value),
72 translation_key=
"all_day_video_recording",
73 device_class=SwitchDeviceClass.SWITCH,
74 supported_ext=
str(SupportExt.SupportFulldayRecord.value),
78 translation_key=
"auto_sleep",
79 device_class=SwitchDeviceClass.SWITCH,
80 supported_ext=
str(SupportExt.SupportAutoSleep.value),
84 translation_key=
"flicker_light_on_movement",
85 device_class=SwitchDeviceClass.SWITCH,
86 supported_ext=
str(SupportExt.SupportActiveDefense.value),
90 translation_key=
"pir_motion_activated_light",
91 device_class=SwitchDeviceClass.SWITCH,
92 supported_ext=
str(SupportExt.SupportLightRelate.value),
96 translation_key=
"tamper_alarm",
97 device_class=SwitchDeviceClass.SWITCH,
98 supported_ext=
str(SupportExt.SupportTamperAlarm.value),
102 translation_key=
"follow_movement",
103 device_class=SwitchDeviceClass.SWITCH,
104 supported_ext=
str(SupportExt.SupportTracking.value),
110 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
112 """Set up EZVIZ switch based on a config entry."""
113 coordinator: EzvizDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
119 for camera
in coordinator.data
120 for switch_number
in coordinator.data[camera][
"switches"]
121 if switch_number
in SWITCH_TYPES
122 if SWITCH_TYPES[switch_number].supported_ext
123 in coordinator.data[camera][
"supportExt"]
124 or SWITCH_TYPES[switch_number].supported_ext
is None
129 """Representation of a EZVIZ sensor."""
132 self, coordinator: EzvizDataUpdateCoordinator, serial: str, switch_number: int
134 """Initialize the switch."""
135 super().
__init__(coordinator, serial)
138 f
"{serial}_{self._camera_name}.{DeviceSwitchType(switch_number).name}"
144 """Change a device switch on the camera."""
146 if await self.
hasshasshass.async_add_executor_job(
147 self.coordinator.ezviz_client.switch_status,
155 except (HTTPError, PyEzvizError)
as err:
159 """Change a device switch on the camera."""
161 if await self.
hasshasshass.async_add_executor_job(
162 self.coordinator.ezviz_client.switch_status,
170 except (HTTPError, PyEzvizError)
as err:
175 """Handle updated data from the coordinator."""
dict[str, Any] data(self)
None _handle_coordinator_update(self)
None async_turn_off(self, **Any kwargs)
None __init__(self, EzvizDataUpdateCoordinator coordinator, str serial, int switch_number)
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, ConfigEntry entry, AddEntitiesCallback async_add_entities)