From 4c538c718ba90522e0600e4f9214d1873c69efae Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 19 Feb 2016 22:23:25 -0800 Subject: [PATCH] Clean up binary_sensor --- homeassistant/components/binary_sensor/__init__.py | 14 ++++++-------- .../components/binary_sensor/test_binary_sensor.py | 3 +-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/binary_sensor/__init__.py b/homeassistant/components/binary_sensor/__init__.py index 3934feae179..0eefd853538 100644 --- a/homeassistant/components/binary_sensor/__init__.py +++ b/homeassistant/components/binary_sensor/__init__.py @@ -61,11 +61,6 @@ class BinarySensorDevice(Entity): """Return the state of the binary sensor.""" return STATE_ON if self.is_on else STATE_OFF - @property - def friendly_state(self): - """Return the friendly state of the binary sensor.""" - return None - @property def sensor_class(self): """Return the class of this sensor, from SENSOR_CASSES.""" @@ -74,6 +69,9 @@ class BinarySensorDevice(Entity): @property def state_attributes(self): """Return device specific state attributes.""" - return { - 'sensor_class': self.sensor_class, - } + attr = {} + + if self.sensor_class is not None: + attr['sensor_class'] = self.sensor_class + + return attr diff --git a/tests/components/binary_sensor/test_binary_sensor.py b/tests/components/binary_sensor/test_binary_sensor.py index 9079b208204..db5f09fdf6d 100644 --- a/tests/components/binary_sensor/test_binary_sensor.py +++ b/tests/components/binary_sensor/test_binary_sensor.py @@ -31,8 +31,7 @@ class TestBinarySensor(unittest.TestCase): def test_attributes(self): """Test binary sensor attributes.""" sensor = binary_sensor.BinarySensorDevice() - self.assertEqual({'sensor_class': None}, - sensor.state_attributes) + self.assertEqual({}, sensor.state_attributes) with mock.patch('homeassistant.components.binary_sensor.' 'BinarySensorDevice.sensor_class', new='motion'):