def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Ezviz IP Cameras.""" conf_cameras = config[CONF_CAMERAS] account = config[CONF_USERNAME] password = config[CONF_PASSWORD] try: ezviz_client = EzvizClient(account, password) ezviz_client.login() cameras = ezviz_client.load_cameras() except PyEzvizError as exp: _LOGGER.error(exp) return # now, let's build the HASS devices camera_entities = [] # Add the cameras as devices in HASS for camera in cameras: camera_username = DEFAULT_CAMERA_USERNAME camera_password = "" camera_rtsp_stream = "" camera_serial = camera["serial"] # There seem to be a bug related to localRtspPort in Ezviz API... local_rtsp_port = DEFAULT_RTSP_PORT if camera["local_rtsp_port"] and camera["local_rtsp_port"] != 0: local_rtsp_port = camera["local_rtsp_port"] if camera_serial in conf_cameras: camera_username = conf_cameras[camera_serial][CONF_USERNAME] camera_password = conf_cameras[camera_serial][CONF_PASSWORD] camera_rtsp_stream = f"rtsp://{camera_username}:{camera_password}@{camera['local_ip']}:{local_rtsp_port}" _LOGGER.debug("Camera %s source stream: %s", camera["serial"], camera_rtsp_stream) else: _LOGGER.info( "Found camera with serial %s without configuration. Add it to configuration.yaml to see the camera stream", camera_serial, ) camera["username"] = camera_username camera["password"] = camera_password camera["rtsp_stream"] = camera_rtsp_stream camera["ezviz_camera"] = EzvizCamera(ezviz_client, camera_serial) camera_entities.append(HassEzvizCamera(**camera)) add_entities(camera_entities)
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Ezviz IP Cameras.""" conf_cameras = config[ATTR_CAMERAS] account = config[CONF_USERNAME] password = config[CONF_PASSWORD] region = config[CONF_REGION] try: ezviz_client = EzvizClient(account, password, region) ezviz_client.login() cameras = ezviz_client.load_cameras() except PyEzvizError as exp: _LOGGER.error(exp) return # now, let's build the HASS devices camera_entities = [] # Add the cameras as devices in HASS for camera in cameras: camera_username = DEFAULT_CAMERA_USERNAME camera_password = "" camera_rtsp_stream = "" camera_serial = camera["serial"] # There seem to be a bug related to localRtspPort in Ezviz API... local_rtsp_port = DEFAULT_RTSP_PORT if camera["local_rtsp_port"] and camera["local_rtsp_port"] != 0: local_rtsp_port = camera["local_rtsp_port"] if camera_serial in conf_cameras: camera_username = conf_cameras[camera_serial][CONF_USERNAME] camera_password = conf_cameras[camera_serial][CONF_PASSWORD] camera_rtsp_stream = f"rtsp://{camera_username}:{camera_password}@{camera['local_ip']}:{local_rtsp_port}" _LOGGER.debug("Camera %s source stream: %s", camera["serial"], camera_rtsp_stream) else: _LOGGER.info( "Found camera with serial %s without configuration. Add it to configuration.yaml to see the camera stream", camera_serial, ) camera["username"] = camera_username camera["password"] = camera_password camera["rtsp_stream"] = camera_rtsp_stream camera["ezviz_client"] = ezviz_client camera["ezviz_camera"] = EzvizCamera(ezviz_client, camera_serial) camera_entities.append(HassEzvizCamera(hass, **camera)) add_entities(camera_entities) """Setup Services""" def ezviz_wake_device(service): """Basicaly queries device to wake.""" ezviz_client.get_detection_sensibility(str(service.data['serial'])) def ezviz_switch_set(service): """Set camera switch service.""" service_switch = getattr(DeviceSwitchType, service.data[ATTR_SWITCH]) ezviz_client.switch_status(service.data[ATTR_SERIAL], service_switch.value, service.data[ATTR_ENABLE]) def ezviz_alarm_sound(service): """Enable/Disable movement sound alarm.""" ezviz_client.alarm_sound(str(service.data[ATTR_SERIAL]), int(service.data['level']), 1) def ezviz_set_alarm_detection_sensibility(service): """Set camera detection sensibility level service.""" ezviz_client.detection_sensibility(str(service.data[ATTR_SERIAL]), int(service.data['level']), int(service.data['type'])) def ezviz_ptz(service): """Camera PTZ service.""" ezviz_client.ptzControl( str(service.data[ATTR_DIRECTION]).upper(), service.data[ATTR_SERIAL], 'START', service.data[ATTR_SPEED]) ezviz_client.ptzControl( str(service.data[ATTR_DIRECTION]).upper(), service.data[ATTR_SERIAL], 'STOP', service.data[ATTR_SPEED]) hass.services.register(DOMAIN, "ezviz_wake_device", ezviz_wake_device) hass.services.register(DOMAIN, "ezviz_switch_set", ezviz_switch_set, schema=SERVICE_SET_SWITCH_SCHEMA) hass.services.register(DOMAIN, "ezviz_ptz", ezviz_ptz, SERVICE_PTZ_SCHEMA) hass.services.register(DOMAIN, "ezviz_alarm_sound", ezviz_alarm_sound) hass.services.register(DOMAIN, "ezviz_set_alarm_detection_sensibility", ezviz_set_alarm_detection_sensibility)