Ejemplo n.º 1
0
    def _run_poll_server(self):
        from pyvera import get_controller
        controller = get_controller()
        timestamp = None
        while not self._exiting:
            try:
                device_data, timestamp = (
                    controller.get_changed_devices(timestamp))
                LOG.info("Poll returned")
                if self._exiting:
                    continue
                if not device_data:
                    LOG.info("No changes in poll interval")
                    continue
                self._event(device_data)
                time.sleep(1)
            except requests.RequestException:
                LOG.info("Could not contact Vera - will retry in %ss",
                         SUBSCRIPTION_RETRY)
                time.sleep(SUBSCRIPTION_RETRY)
            except Exception as ex:
                LOG.exception("Vera thread exception %s", ex)
                raise

        LOG.info("Shutdown Vera Poll Thread")
Ejemplo n.º 2
0
    def _run_poll_server(self):
        from pyvera import get_controller
        controller = get_controller()
        timestamp = None
        while not self._exiting:
            try:
                device_data, timestamp = (
                    controller.get_changed_devices(timestamp))
                LOG.debug("Poll returned")
                if self._exiting:
                    continue
                if not device_data:
                    LOG.debug("No changes in poll interval")
                    continue
                self._event(device_data)
                time.sleep(1)
            except requests.RequestException:
                LOG.info("Could not contact Vera - will retry in %ss",
                         SUBSCRIPTION_RETRY)
                time.sleep(SUBSCRIPTION_RETRY)
            except json.decoder.JSONDecodeError:
                LOG.info("Response was malfomed - will retry in %ss",
                         SUBSCRIPTION_RETRY)
                time.sleep(SUBSCRIPTION_RETRY)
            except Exception as ex:
                LOG.exception("Vera thread exception %s", ex)
                raise

        LOG.info("Shutdown Vera Poll Thread")
Ejemplo n.º 3
0
    def _run_poll_server(self):
        from pyvera import get_controller
        from pyvera import VeraController
        controller = self._controller or get_controller()
        timestamp = VeraController.TIMESTAMP_NONE
        device_data = []
        alert_data = []
        data_changed = False
        while not self._exiting:
            try:
                logger.debug("Polling for Vera changes")
                device_data, new_timestamp = (
                    controller.get_changed_devices(timestamp))
                if new_timestamp['dataversion'] != timestamp['dataversion']:
                    alert_data = controller.get_alerts(timestamp)
                    data_changed = True
                else:
                    data_changed = False
                timestamp = new_timestamp
            except requests.RequestException as ex:
                logger.debug("Caught RequestException: %s", str(ex))
                pass
            except PyveraError as ex:
                logger.debug("Non-fatal error in poll: %s", str(ex))
                pass
            except Exception as ex:
                logger.exception("Vera poll thread general exception: %s",
                                 str(ex))
                raise
            else:
                logger.debug("Poll returned")
                if not self._exiting:
                    if data_changed:
                        self._event(device_data, alert_data)
                    else:
                        logger.debug("No changes in poll interval")
                    time.sleep(1)

                continue

            # After error, discard timestamp for fresh update. pyvera issue #89
            timestamp = {'dataversion': 1, 'loadtime': 0}
            logger.info("Could not poll Vera - will retry in %ss",
                        SUBSCRIPTION_RETRY)
            time.sleep(SUBSCRIPTION_RETRY)

        logger.info("Shutdown Vera Poll Thread")
Ejemplo n.º 4
0
    def _run_poll_server(self):
        from pyvera import get_controller
        controller = get_controller()
        timestamp = None
        while not self._exiting:
            try:
                logger.debug("Polling for Vera changes")
                device_data, timestamp = (
                    controller.get_changed_devices(timestamp))
            except requests.RequestException as ex:
                logger.debug("Caught RequestException: %s", str(ex))
                pass
            except PyveraError as ex:
                logger.debug("Non-fatal error in poll: %s", str(ex))
                pass
            except Exception as ex:
                logger.exception("Vera poll thread general exception: %s",
                                 str(ex))
                raise
            else:
                logger.debug("Poll returned")
                if not self._exiting:
                    if device_data:
                        self._event(device_data)
                    else:
                        logger.debug("No changes in poll interval")
                    time.sleep(1)

                continue

            # After error, discard timestamp for fresh update. pyvera issue #89
            timestamp = None
            logger.info("Could not poll Vera - will retry in %ss",
                        SUBSCRIPTION_RETRY)
            time.sleep(SUBSCRIPTION_RETRY)

        logger.info("Shutdown Vera Poll Thread")
Ejemplo n.º 5
0
    def _run_poll_server(self):
        from pyvera import get_controller
        controller = get_controller()
        timestamp = None
        # Wait for code to initialize to avoid callbacks before ready
        # Initial state callbacks are instant!
        time.sleep(10)
        while not self._exiting:
            try:
                device_ids, timestamp = (
                    controller.get_changed_devices(timestamp))
                if self._exiting:
                    continue;
                if device_ids is None:
                    LOG.info("No changes in poll interval")
                    continue;
                devices = [self._devices.get(int(id)) for id in device_ids]
                self._event(devices)
            except requests.RequestException:
                LOG.info("Could not contact Vera - will retry in %ss",
                         SUBSCRIPTION_RETRY)
                time.sleep(SUBSCRIPTION_RETRY)

        LOG.info("Shutdown Vera Poll Thread")