diff --git a/homeassistant/components/binary_sensor/octoprint.py b/homeassistant/components/binary_sensor/octoprint.py index 3fd92d1ceb1941dd50ef2e65aef04533826c8aab..d1cc1d8e8a4fd9b6cff1db18fa7fde42be31a0e3 100644 --- a/homeassistant/components/binary_sensor/octoprint.py +++ b/homeassistant/components/binary_sensor/octoprint.py @@ -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): diff --git a/homeassistant/components/binary_sensor/workday.py b/homeassistant/components/binary_sensor/workday.py index c25ea81922ba2377bcfdef770732342d748dddc8..57c4533fb5d5632b615b7dd01c6bdee7dfbb0522 100644 --- a/homeassistant/components/binary_sensor/workday.py +++ b/homeassistant/components/binary_sensor/workday.py @@ -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