Add a 'last' mode and attribute to min_max sensor (#11037)

* Add 'last' type to min/max sensor

Now supports types: min, max, mean, last
'last' is the most recently received value from all tracked entities.

* Min/max sensor 'last' type test

* Fix min/max sensor 'last' test
This commit is contained in:
markferry authored and Fabian Affolter committed 2018-01-18 23:03:41 +01:00
1 parent 536424b0c8
commit 526405c83b
2 files changed
+35 -1

No files matched your search

+30
View File
@@ -260,3 +260,33 @@ class TestMinMaxSensor(unittest.TestCase):
self.assertEqual(STATE_UNKNOWN, state.state)
self.assertEqual('ERR', state.attributes.get('unit_of_measurement'))
def test_last_sensor(self):
"""Test the last sensor."""
config = {
'sensor': {
'platform': 'min_max',
'name': 'test_last',
'type': 'last',
'entity_ids': [
'sensor.test_1',
'sensor.test_2',
'sensor.test_3',
]
}
}
assert setup_component(self.hass, 'sensor', config)
entity_ids = config['sensor']['entity_ids']
state = self.hass.states.get('sensor.test_last')
for entity_id, value in dict(zip(entity_ids, self.values)).items():
self.hass.states.set(entity_id, value)
self.hass.block_till_done()
state = self.hass.states.get('sensor.test_last')
self.assertEqual(str(float(value)), state.state)
self.assertEqual(self.min, state.attributes.get('min_value'))
self.assertEqual(self.max, state.attributes.get('max_value'))
self.assertEqual(self.mean, state.attributes.get('mean'))