Beispiel #1
0
 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
Beispiel #2
0
    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
Beispiel #3
0
    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()
Beispiel #4
0
    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
Beispiel #5
0
 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
Beispiel #6
0
 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()
Beispiel #7
0
 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()
Beispiel #8
0
 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)