Beispiel #1
0
    def _read_analog_sensor(self, analog_sensor):
        value = analog_sensor.read_analog_sensor()

        analog_reading = AnalogSensorReading()
        analog_reading.name = analog_sensor.sensor_name
        analog_reading.value = value
        analog_reading.unit = analog_sensor.unit
        analog_reading.timestamp = datetime.now()
        self.sensor_persistence.create(analog_reading)

        if value != analog_sensor.error_sentinel:
            if value < analog_sensor.min_normal or \
                    value > analog_sensor.max_normal:
                logger.info(analog_reading.name + ' Analog Sensor Value: ' +
                            str(analog_reading.value) + analog_reading.unit +
                            ' - Out of Normal Range')
                self._send_notification(analog_sensor, analog_reading)
            else:
                logger.info(analog_reading.name + ' Analog Sensor Value: ' +
                            str(analog_reading.value) + analog_reading.unit +
                            ' - Within Normal Range')
        else:
            logger.info(analog_reading.name + ' Analog Sensor Value: ' +
                        str(analog_reading.value) + analog_reading.unit +
                        ' - Error Sentinel - Ignoring')
Beispiel #2
0
    def test_update_updates_single_model_object(self, sqlalchemy):
        service = SensorReadingPersistenceService()

        original_reading = AnalogSensorReading()
        original_reading.name = 'original'
        original_reading.value = 1
        original_reading.unit = 'original'

        service.create(original_reading)

        persisted_reading = service.get(original_reading.id)

        persisted_reading.name = 'new'
        persisted_reading.value = 2
        persisted_reading.unit = 'new'

        service.update(persisted_reading)

        updated_reading = service.get(original_reading.id)

        assert updated_reading.name == 'new'
        assert updated_reading.value == 2
        assert updated_reading.unit == 'new'
Beispiel #3
0
    def test_update_updates_single_model_object(self, sqlalchemy):
        service = SensorReadingPersistenceService()

        original_reading = AnalogSensorReading()
        original_reading.name = 'original'
        original_reading.value = 1
        original_reading.unit = 'original'

        service.create(original_reading)

        persisted_reading = service.get(original_reading.id)

        persisted_reading.name = 'new'
        persisted_reading.value = 2
        persisted_reading.unit = 'new'

        service.update(persisted_reading)

        updated_reading = service.get(original_reading.id)

        assert updated_reading.name == 'new'
        assert updated_reading.value == 2
        assert updated_reading.unit == 'new'
Beispiel #4
0
    def test_index_analog_sensor_reading(self, sqlalchemy):
        service = SensorReadingPersistenceService()

        timestamp = datetime.now()

        reading = AnalogSensorReading()
        reading.name = "testsensor"
        reading.unit = "testunit"
        reading.value = 0
        reading.timestamp = timestamp

        service.create(reading)

        client = web.app.test_client()

        rv = client.get("/")

        assert b"testsensor" in rv.data
        assert b"Analog" in rv.data
        assert b"0 (testunit)" in rv.data
        assert str.encode(str(timestamp)) in rv.data
        assert b"newer" not in rv.data
        assert b"older" not in rv.data
Beispiel #5
0
    def test_index_analog_sensor_reading(self, sqlalchemy):
        service = SensorReadingPersistenceService()

        timestamp = datetime.now()

        reading = AnalogSensorReading()
        reading.name = 'testsensor'
        reading.unit = 'testunit'
        reading.value = 0
        reading.timestamp = timestamp

        service.create(reading)

        client = web.app.test_client()

        rv = client.get('/')

        assert b'testsensor' in rv.data
        assert b'Analog' in rv.data
        assert b'0 (testunit)' in rv.data
        assert str.encode(str(timestamp)) in rv.data
        assert b'newer' not in rv.data
        assert b'older' not in rv.data