1 """Support turning on/off motion detection on Hikvision cameras."""
3 from __future__
import annotations
9 from hikvision.error
import HikvisionError, MissingParamError
10 import voluptuous
as vol
13 PLATFORM_SCHEMA
as SWITCH_PLATFORM_SCHEMA,
32 _LOGGING = logging.getLogger(__name__)
34 DEFAULT_NAME =
"Hikvision Camera Motion Detection"
35 DEFAULT_PASSWORD =
"12345"
37 DEFAULT_USERNAME =
"admin"
39 PLATFORM_SCHEMA = SWITCH_PLATFORM_SCHEMA.extend(
41 vol.Required(CONF_HOST): cv.string,
42 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
43 vol.Optional(CONF_PASSWORD, default=DEFAULT_PASSWORD): cv.string,
44 vol.Optional(CONF_PORT): cv.port,
45 vol.Optional(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string,
53 add_entities: AddEntitiesCallback,
54 discovery_info: DiscoveryInfoType |
None =
None,
56 """Set up Hikvision camera."""
57 host = config.get(CONF_HOST)
58 port = config.get(CONF_PORT)
59 name = config.get(CONF_NAME)
60 username = config.get(CONF_USERNAME)
61 password = config.get(CONF_PASSWORD)
64 hikvision_cam = hikvision.api.CreateDevice(
65 host, port=port, username=username, password=password, is_https=
False
67 except MissingParamError
as param_err:
68 _LOGGING.error(
"Missing required param: %s", param_err)
70 except HikvisionError
as conn_err:
71 _LOGGING.error(
"Unable to connect: %s", conn_err)
78 """Representation of a switch to toggle on/off motion detection."""
81 """Initialize the switch."""
88 """Return the name of the device if any."""
89 return self.
_name_name
93 """Return true if device is on."""
94 return self.
_state_state == STATE_ON
97 """Turn the device on."""
98 _LOGGING.info(
"Turning on Motion Detection ")
102 """Turn the device off."""
103 _LOGGING.info(
"Turning off Motion Detection ")
107 """Update Motion Detection state."""
108 enabled = self.
_hikvision_cam_hikvision_cam.is_motion_detection_enabled()
109 _LOGGING.info(
"enabled: %s", enabled)
111 self.
_state_state = STATE_ON
if enabled
else STATE_OFF
None turn_on(self, **Any kwargs)
None turn_off(self, **Any kwargs)
def __init__(self, name, hikvision_cam)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)