From a6006b1835d53292c48050f32ec61118369ece86 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Fri, 20 Nov 2015 14:58:49 +0100 Subject: [PATCH] Move state --- homeassistant/components/binary_sensor/__init__.py | 10 ++++++++-- homeassistant/components/binary_sensor/demo.py | 10 ++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/binary_sensor/__init__.py b/homeassistant/components/binary_sensor/__init__.py index b02d38a9f81..2ef9e83cc30 100644 --- a/homeassistant/components/binary_sensor/__init__.py +++ b/homeassistant/components/binary_sensor/__init__.py @@ -11,6 +11,7 @@ import logging from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity import Entity +from homeassistant.const import (STATE_ON, STATE_OFF) DOMAIN = 'binary_sensor' DEPENDENCIES = [] @@ -31,12 +32,17 @@ def setup(hass, config): # pylint: disable=no-self-use class BinarySensorDevice(Entity): - """ Represents a binary sensor.. """ + """ Represents a binary sensor. """ @property def is_on(self): """ True if the binary sensor is on. """ - return False + return None + + @property + def state(self): + """ Returns the state of the binary sensor. """ + return STATE_ON if self.is_on else STATE_OFF @property def friendly_state(self): diff --git a/homeassistant/components/binary_sensor/demo.py b/homeassistant/components/binary_sensor/demo.py index 266b46b7e17..a24b893c610 100644 --- a/homeassistant/components/binary_sensor/demo.py +++ b/homeassistant/components/binary_sensor/demo.py @@ -4,7 +4,6 @@ homeassistant.components.binary_sensor.demo Demo platform that has two fake binary sensors. """ from homeassistant.components.binary_sensor import BinarySensorDevice -from homeassistant.const import (STATE_ON, STATE_OFF, DEVICE_DEFAULT_NAME) def setup_platform(hass, config, add_devices, discovery_info=None): @@ -19,7 +18,7 @@ class DemoBinarySensor(BinarySensorDevice): """ A Demo binary sensor. """ def __init__(self, name, state, icon=None): - self._name = name or DEVICE_DEFAULT_NAME + self._name = name self._state = state self._icon = icon @@ -40,10 +39,5 @@ class DemoBinarySensor(BinarySensorDevice): @property def is_on(self): - """ True if the sensor is on. """ + """ True if the binary sensor is on. """ return self._state - - @property - def state(self): - """ Returns the state of the binary sensor. """ - return STATE_ON if self.is_on else STATE_OFF