def _get_sensor_by_id(self, id): _, gauge_id = id.split('.', 1) gauge = self._get_gauge_by_id(gauge_id) if not gauge: raise SensorNotFound() for sensor in gauge.sensors: if sensor.id.lower() == id.lower(): return sensor
def iter_sensors(self, gauge, pattern=None): if not isinstance(gauge, Gauge): gauge = self._get_gauge_by_id(gauge) if gauge is None: raise SensorNotFound() if pattern is None: yield from gauge.sensors else: lowpattern = pattern.lower() for sensor in gauge.sensors: if lowpattern in sensor.name.lower(): yield sensor
def get_last_measure(self, sensor): """ Get last measures of a sensor. :param sensor: ID of the sensor. :type sensor: str :rtype: :class:`GaugeMeasure` """ # Note: The lower the value, the higher the perturbations. try: return next(self.browser.get_status(sensor)) except KeyError: return SensorNotFound()
def iter_sensors(self, gauge, pattern=None): if not isinstance(gauge, Gauge): gauge = self._get_gauge_by_id(gauge) if gauge is None: raise SensorNotFound() gauge.sensors = self.browser.get_station_infos(gauge) if pattern is None: for sensor in gauge.sensors: yield sensor else: lowpattern = pattern.lower() for sensor in gauge.sensors: if lowpattern in sensor.name.lower(): yield sensor
def get_last_measure(self, sensor): if not isinstance(sensor, GaugeSensor): sensor = self._get_sensor_by_id(sensor) if sensor is None: raise SensorNotFound() return sensor.lastvalue
def _get_sensor_by_id(self, id): for gauge in self.iter_gauges(): for sensor in gauge.sensors: if id == sensor.id: return sensor raise SensorNotFound()
def _get_sensor_by_id(self, id): for gauge in self.browser.get_rivers_list(): for sensor in gauge.sensors: if id == sensor.id: return sensor raise SensorNotFound()
def iter_gauge_history(self, sensor): if not isinstance(sensor, GaugeSensor): sensor = self._get_sensor_by_id(sensor) if sensor is None: raise SensorNotFound() return self.browser.iter_history(sensor)