def _get_ezviz_client_instance(entry: ConfigEntry) -> EzvizClient: """Initialize a new instance of EzvizClientApi.""" ezviz_client = EzvizClient( entry.data[CONF_USERNAME], entry.data[CONF_PASSWORD], entry.data[CONF_REGION] ) # , entry.options.get(CONF_TIMEOUT, DEFAULT_TIMEOUT) ezviz_client.login() return ezviz_client
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 _get_ezviz_client_instance(data): """Initialize a new instance of EzvizClientApi.""" ezviz_client = EzvizClient( data[CONF_USERNAME], data[CONF_PASSWORD], data.get(CONF_URL, EU_URL), data.get(CONF_TIMEOUT, DEFAULT_TIMEOUT), ) ezviz_client.login() return ezviz_client
def _validate_and_create_auth(data: dict) -> dict[str, Any]: """Try to login to ezviz cloud account and return token.""" # Verify cloud credentials by attempting a login request with username and password. # Return login token. ezviz_client = EzvizClient( data[CONF_USERNAME], data[CONF_PASSWORD], data[CONF_URL], data.get(CONF_TIMEOUT, DEFAULT_TIMEOUT), ) ezviz_token = ezviz_client.login() auth_data = { CONF_SESSION_ID: ezviz_token[CONF_SESSION_ID], CONF_RFSESSION_ID: ezviz_token[CONF_RFSESSION_ID], CONF_URL: ezviz_token["api_url"], CONF_TYPE: ATTR_TYPE_CLOUD, } return auth_data
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)