How to use the amcrest.AmcrestError function in amcrest

To help you get started, we’ve selected a few amcrest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github home-assistant / home-assistant / homeassistant / components / amcrest / __init__.py View on Github external
def command(self, cmd, retries=None, timeout_cmd=None, stream=False):
        """amcrest.Http.command wrapper to catch errors."""
        try:
            ret = super().command(cmd, retries, timeout_cmd, stream)
        except AmcrestError:
            with self._wrap_lock:
                was_online = self.available
                self._wrap_errors += 1
                _LOGGER.debug("%s camera errs: %i", self._wrap_name, self._wrap_errors)
                offline = not self.available
            if offline and was_online:
                _LOGGER.error("%s camera offline: Too many errors", self._wrap_name)
                with self._token_lock:
                    self._token = None
                dispatcher_send(
                    self._hass, service_signal(SERVICE_UPDATE, self._wrap_name)
                )
                self._unsub_recheck = track_time_interval(
                    self._hass, self._wrap_test_online, RECHECK_INTERVAL
                )
            raise
github home-assistant / home-assistant / homeassistant / components / amcrest / sensor.py View on Github external
elif self._sensor_type == SENSOR_SDCARD:
                storage = self._api.storage_all
                try:
                    self._attrs["Total"] = "{:.2f} {}".format(*storage["total"])
                except ValueError:
                    self._attrs["Total"] = "{} {}".format(*storage["total"])
                try:
                    self._attrs["Used"] = "{:.2f} {}".format(*storage["used"])
                except ValueError:
                    self._attrs["Used"] = "{} {}".format(*storage["used"])
                try:
                    self._state = "{:.2f}".format(storage["used_percent"])
                except ValueError:
                    self._state = storage["used_percent"]
        except AmcrestError as error:
            log_update_error(_LOGGER, "update", self.name, "sensor", error)
github home-assistant / home-assistant / homeassistant / components / amcrest / binary_sensor.py View on Github external
def update(self):
        """Update entity."""
        if not self.available:
            return
        _LOGGER.debug("Updating %s binary sensor", self._name)

        try:
            if self._sensor_type == BINARY_SENSOR_MOTION_DETECTED:
                self._state = self._api.is_motion_detected

            elif self._sensor_type == BINARY_SENSOR_ONLINE:
                self._state = self._api.available
        except AmcrestError as error:
            log_update_error(_LOGGER, "update", self.name, "binary sensor", error)
github home-assistant / home-assistant / homeassistant / components / amcrest / switch.py View on Github external
def update(self):
        """Update setting state."""
        if not self.available:
            return
        _LOGGER.debug("Updating %s switch", self._name)

        try:
            if self._setting == MOTION_DETECTION:
                detection = self._api.is_motion_detector_on()
            elif self._setting == MOTION_RECORDING:
                detection = self._api.is_record_on_motion_detection()
            self._state = detection
        except AmcrestError as error:
            log_update_error(_LOGGER, "update", self.name, "switch", error)
github home-assistant / home-assistant / homeassistant / components / amcrest / camera.py View on Github external
def _set_color_bw(self, cbw):
        """Set camera color mode."""
        try:
            self._api.day_night_color = _CBW.index(cbw)
        except AmcrestError as error:
            log_update_error(
                _LOGGER, "set", self.name, f"camera color mode to {cbw}", error
            )
        else:
            self._color_bw = cbw
            self.schedule_update_ha_state()

amcrest

Python wrapper implementation for Amcrest cameras.

GPL-2.0
Latest version published 1 year ago

Package Health Score

47 / 100
Full package analysis