def __init__(self, device): """Initialize a camera for a Skybell device.""" SkybellDevice.__init__(self, device) Camera.__init__(self) self._name = self._device.name self._url = None self._response = None
def __init__(self, device, camera_type, name=None): """Initialize a camera for a Skybell device.""" self._type = camera_type SkybellDevice.__init__(self, device) Camera.__init__(self) if name is not None: self._name = "{} {}".format(self._device.name, name) else: self._name = self._device.name self._url = None self._response = None
def __init__(self, config, discovery_hash): """Initialize the MQTT Camera.""" self._config = config self._unique_id = config.get(CONF_UNIQUE_ID) self._sub_state = None self._qos = 0 self._last_image = None Camera.__init__(self) MqttDiscoveryUpdate.__init__(self, discovery_hash, self.discovery_update)
def __init__(self, data, device, event): """Initialize the Abode device.""" AbodeDevice.__init__(self, data, device) Camera.__init__(self) self._event = event self._response = None
def __init__(self, hass, config, config_entry, discovery_data): """Initialize the MQTT Camera.""" self._last_image = None Camera.__init__(self) MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
def __init__(self, entry_id: str, component_key: str, key: int): """Initialize.""" Camera.__init__(self) EsphomeBaseEntity.__init__(self, entry_id, component_key, key) self._image_cond = asyncio.Condition()
def __init__(self, hass, connection, deviceID, alias=None): Camera.__init__(self) BrowserModEntity.__init__(self, hass, connection, deviceID, alias) self.last_seen = None
def __init__(self, coordinator: JobUpdateCoordinator) -> None: """Initialize a PrusaLink camera entity.""" super().__init__(coordinator) Camera.__init__(self) self._attr_unique_id = f"{self.coordinator.config_entry.entry_id}_job_preview"
def __init__(self, *args, **kwargs) -> None: """Initialize.""" Camera.__init__(self) EsphomeBaseEntity.__init__(self, *args, **kwargs) self._image_cond = asyncio.Condition()
def __init__(self, data: AbodeSystem, device: AbodeDev, event: Event) -> None: """Initialize the Abode device.""" AbodeDevice.__init__(self, data, device) Camera.__init__(self) self._event = event self._response: Response | None = None
def __init__(self, entry_id: str, component_key: str, key: int): """Initialize.""" Camera.__init__(self) EsphomeEntity.__init__(self, entry_id, component_key, key) self._image_cond = asyncio.Condition()
class ReolinkCamera(Camera): """An implementation of a Reolink IP camera.""" def __init__(self, hass, config): """Initialize a Reolink camera.""" from custom_components.reolink.ReolinkCamera import Camera super().__init__() self._host = config.get(CONF_HOST) self._username = config.get(CONF_USERNAME) self._password = config.get(CONF_PASSWORD) self._name = config.get(CONF_NAME) self._hass = hass self._auth = aiohttp.BasicAuth(self._username, password=self._password) self._stream = None self._protocol = None self._reolink_session = Camera(self._host, self._username, self._password) self._last_image = None self._last_motion = 0 self._ftp = None self._email = None self._ir_lights = None self._device_info = None self._netports = None self._state = STATE_IDLE self._emailHandler = None self._smtp_server = None self._smtp_port = None hass.bus.async_listen(EVENT_HOMEASSISTANT_STOP, self.disconnect) hass.loop.create_task(self.connect()) @property def state_attributes(self): """Return the camera state attributes.""" attrs = {"access_token": self.access_tokens[-1]} if self.model: attrs["model_name"] = self.model if self.brand: attrs["brand"] = self.brand if self.sw_version: attrs["sw_version"] = self.sw_version if self.motion_detection_enabled: attrs["motion_detection"] = self.motion_detection_enabled if self._last_motion: attrs["last_motion"] = self._last_motion attrs["ftp_enabled"] = self._ftp_enabled attrs["email_enabled"] = self._email_enabled attrs["ir_lights_enabled"] = self._ir_lights_enabled return attrs @property def supported_features(self): """Return supported features.""" return SUPPORT_STREAM @property def brand(self): """Return the camera brand.""" return DEFAULT_BRAND @property def model(self): """Return the camera model.""" return self._device_info[0]["value"]["DevInfo"]["model"] @property def sw_version(self): """Return the camera model.""" return self._device_info[0]["value"]["DevInfo"]["firmVer"] async def connect(self): await self.get_camera_settings() await self.start_smtp() async def stream_source(self): """Return the source of the stream.""" if self._protocol == 'rtsp': stream_source = "rtsp://{}:{}@{}:{}/h264Preview_01_{}".format( self._username, self._password, self._host, self._rtspport, self._stream ) else: stream_source = "rtmp://{}:{}@{}:{}/bcs/channel0_{}.bcs?channel=0&stream=0".format( self._username, self._password, self._host, self._rtmpport, self._stream ) return stream_source async def get_camera_settings(self): self._ftp = self._reolink_session.get_ftp() self._email = self._reolink_session.get_email() self._device_info = self._reolink_session.get_device_info() self._netports = self._reolink_session.get_net_ports() self._ir_lights = self._reolink_session.get_ir_lights() if self._ftp == None: _LOGGER.error("Error retrieving FTP settings for Reolink camera" + self._name) return False if self._email == None: _LOGGER.error("Error retrieving email settings for Reolink camera" + self._name) return False if self._device_info == None: _LOGGER.error("Error retrieving device info for Reolink camera" + self._name) return False if self._netports == None: _LOGGER.error("Error retrieving port settings for Reolink camera" + self._name) return False if self._ir_lights == None: _LOGGER.error("Error retrieving IR light settings for Reolink camera" + self._name) return False if (self._ftp[0]["value"]["Ftp"]["schedule"]["enable"] == 1): self._ftp_enabled = True else: self._ftp_enabled = False if (self._email[0]["value"]["Email"]["schedule"]["enable"] == 1): self._email_enabled = True else: self._email_enabled = False if (self._ir_lights[0]["value"]["IrLights"]["state"] == "Auto"): self._ir_lights_enabled = True else: self._ir_lights_enabled = False self._rtspport = self._netports[0]["value"]["NetPort"]["rtspPort"] self._rtmpport = self._netports[0]["value"]["NetPort"]["rtmpPort"] self.smtp_server = self._email[0]["value"]["Email"]["smtpServer"] self.smtp_port = self._email[0]["value"]["Email"]["smtpPort"] if not self._stream: self._stream = 'main' if not self._protocol: self._protocol = 'rtsp' return True def camera_image(self): """Return bytes of camera image.""" return run_coroutine_threadsafe(self.async_camera_image(), self._hass.loop).result() async def async_camera_image(self): """Return a still image response from the camera.""" still_image_url = "http://{}/cgi-bin/api.cgi?cmd=Snap&channel=0&user={}&password={}".format( self._host, self._username, self._password ) try: websession = async_get_clientsession(self._hass, verify_ssl=False) with async_timeout.timeout(10): response = await websession.get(still_image_url, auth=self._auth) self._last_image = await response.read() except asyncio.TimeoutError: _LOGGER.error("Timeout getting image from: %s", self._name) return self._last_image except aiohttp.ClientError as err: _LOGGER.error("Error getting new camera image: %s", err) return self._last_image return self._last_image @property def ftp_upload_enabled(self): """Camera Motion recording Status.""" return self._ftp_enabled @property def email_enabled(self): """Camera email Status.""" return self._email_enabled def enable_ftp_upload(self): """Enable motion recording in camera.""" if self._reolink_session.set_ftp(True): self._ftp_enabled = True self._hass.states.set(self.entity_id, self.state, self.state_attributes) def disable_ftp_upload(self): """Disable motion recording.""" if self._reolink_session.set_ftp(False): self._ftp_enabled = False self._hass.states.set(self.entity_id, self.state, self.state_attributes) def enable_email(self): """Enable email motion detection in camera.""" if self._reolink_session.set_email(True): self._email_enabled = True self._hass.states.set(self.entity_id, self.state, self.state_attributes) def disable_email(self): """Disable email motion detection.""" if self._reolink_session.set_email(False): self._email_enabled = False self._hass.states.set(self.entity_id, self.state, self.state_attributes) def enable_ir_lights(self): """Enable IR lights.""" if self._reolink_session.set_ir_lights(True): self._ir_lights_enabled = True self._hass.states.set(self.entity_id, self.state, self.state_attributes) def disable_ir_lights(self): """Disable IR lights.""" if self._reolink_session.set_ir_lights(False): self._ir_lights_enabled = False self._hass.states.set(self.entity_id, self.state, self.state_attributes) @property def name(self): """Return the name of this camera.""" return self._name @property def should_poll(self): """Polling needed for the device status.""" return True @property def state(self): """Return the state of the sensor.""" # _LOGGER.info(str(datetime.datetime.now() - self._last_motion).total_seconds() >= 60) if (self._last_motion == 0 or (datetime.datetime.now() - self._last_motion).total_seconds() >= 60): # Time elapsed, reset state if (self._email_enabled != None and self._email_enabled == True): self._state = STATE_NO_MOTION else: self._state = STATE_IDLE return self._state # @Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): """Update the data from the camera.""" self._hass.loop.create_task(self.get_camera_settings()) def disconnect(self, event): _LOGGER.info("Disconnecting from Reolink camera") self._reolink_session.logout() if self._emailHandler != None: self._emailHandler.stop() async def start_smtp(self): # Test if the server can be setup if (self._email[0]["value"]["Email"]['addr1'] != "" and self._email[0]["value"]["Email"]['smtpPort'] != "" and self._email[0]["value"]["Email"]['smtpServer'] != ""): # Instantiate the SMTP server, if not already available emailHandler = self._hass.data.get(DOMAIN + 'SMTPServer') if emailHandler == None: self._emailHandler = ReolinkEmailHandler(self._hass, self.smtp_server, self.smtp_port) # Store the mailserver self._hass.data[DOMAIN + 'SMTPServer'] = self._emailHandler