Remove binary sensor platforms implementing state property (#7371)

* Remove binary sensor platforms implementing state property

* Fix workday inheritance
This commit is contained in:
Paulus Schoutsen 2017-04-29 20:36:50 -07:00 committed by GitHub
parent 55731b759f
commit ce3d8be72b
2 changed files with 10 additions and 20 deletions

View File

@ -9,8 +9,7 @@ import logging
import requests
import voluptuous as vol
from homeassistant.const import (
CONF_NAME, STATE_ON, STATE_OFF, CONF_MONITORED_CONDITIONS)
from homeassistant.const import CONF_NAME, CONF_MONITORED_CONDITIONS
from homeassistant.components.binary_sensor import (
BinarySensorDevice, PLATFORM_SCHEMA)
from homeassistant.loader import get_component
@ -85,18 +84,10 @@ class OctoPrintBinarySensor(BinarySensorDevice):
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Return the state of the sensor."""
return self.is_on
@property
def is_on(self):
"""Return true if binary sensor is on."""
if self._state:
return STATE_ON
else:
return STATE_OFF
return bool(self._state)
@property
def device_class(self):

View File

@ -11,10 +11,9 @@ import datetime
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import (
STATE_ON, STATE_OFF, STATE_UNKNOWN, CONF_NAME, WEEKDAYS)
from homeassistant.const import CONF_NAME, WEEKDAYS
import homeassistant.util.dt as dt_util
from homeassistant.helpers.entity import Entity
from homeassistant.components.binary_sensor import BinarySensorDevice
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
@ -92,7 +91,7 @@ def day_to_string(day):
return None
class IsWorkdaySensor(Entity):
class IsWorkdaySensor(BinarySensorDevice):
"""Implementation of a Workday sensor."""
def __init__(self, obj_holidays, workdays, excludes, name):
@ -101,7 +100,7 @@ class IsWorkdaySensor(Entity):
self._obj_holidays = obj_holidays
self._workdays = workdays
self._excludes = excludes
self._state = STATE_UNKNOWN
self._state = None
@property
def name(self):
@ -109,7 +108,7 @@ class IsWorkdaySensor(Entity):
return self._name
@property
def state(self):
def is_on(self):
"""Return the state of the device."""
return self._state
@ -135,14 +134,14 @@ class IsWorkdaySensor(Entity):
def async_update(self):
"""Get date and look whether it is a holiday."""
# Default is no workday
self._state = STATE_OFF
self._state = False
# Get iso day of the week (1 = Monday, 7 = Sunday)
day = datetime.datetime.today().isoweekday() - 1
day_of_week = day_to_string(day)
if self.is_include(day_of_week, dt_util.now()):
self._state = STATE_ON
self._state = True
if self.is_exclude(day_of_week, dt_util.now()):
self._state = STATE_OFF
self._state = False