1 """Support for Amcrest Switches."""
3 from __future__
import annotations
5 from typing
import TYPE_CHECKING, Any
13 from .const
import DATA_AMCREST, DEVICES
16 from .
import AmcrestDevice
18 PRIVACY_MODE_KEY =
"privacy_mode"
20 SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = (
28 SWITCH_KEYS: list[str] = [desc.key
for desc
in SWITCH_TYPES]
34 async_add_entities: AddEntitiesCallback,
35 discovery_info: DiscoveryInfoType |
None =
None,
37 """Set up amcrest platform switches."""
38 if discovery_info
is None:
41 name = discovery_info[CONF_NAME]
42 device = hass.data[DATA_AMCREST][DEVICES][name]
43 switches = discovery_info[CONF_SWITCHES]
47 for description
in SWITCH_TYPES
48 if description.key
in switches
55 """Representation of an Amcrest Camera Switch."""
60 device: AmcrestDevice,
61 entity_description: SwitchEntityDescription,
63 """Initialize switch."""
66 self.
_attr_name_attr_name = f
"{name} {entity_description.name}"
70 """Return True if entity is available."""
71 return self.
_api_api.available
74 """Turn the switch on."""
78 """Turn the switch off."""
82 """Set privacy mode."""
83 lower_str =
str(mode).lower()
84 await self.
_api_api.async_command(
85 f
"configManager.cgi?action=setConfig&LeLensMask[0].Enable={lower_str}"
90 io_res = (await self.
_api_api.async_privacy_config()).splitlines()[0].split(
"=")[1]
None _async_turn_switch(self, bool mode)
None __init__(self, str name, AmcrestDevice device, SwitchEntityDescription entity_description)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)