Fix statistics for binary sensor (#18764)

* Fix statistics for binary sensor

-) Binary sensors have 'on' and 'off' for state resulting in issue as numbers were expected. Fixed so that it works with non-numeric states as well.
-) Added check to skip unknown states.
-) Updates test so that binary sensor test will use non-numeric values for states.

* Using guard clause and changed debug to error

Changed to use a guard clause for state unknown.
Writing error on value error instead of debug.

* Add docstring
This commit is contained in:
ehendrix23 authored and Fabian Affolter committed 2018-11-29 09:01:56 +01:00
1 parent 48e28843e6
commit aadf72d445
2 files changed
+13 -4

No files matched your search

+1 -1
View File
@@ -40,7 +40,7 @@ class TestStatisticsSensor(unittest.TestCase):
def test_binary_sensor_source(self):
"""Test if source is a sensor."""
values = [1, 0, 1, 0, 1, 0, 1]
values = ['on', 'off', 'on', 'off', 'on', 'off', 'on']
assert setup_component(self.hass, 'sensor', {
'sensor': {
'platform': 'statistics',