mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Remove binary sensor platforms implementing state property (#7371)
* Remove binary sensor platforms implementing state property * Fix workday inheritance
This commit is contained in:
parent
55731b759f
commit
ce3d8be72b
@ -9,8 +9,7 @@ import logging
|
|||||||
import requests
|
import requests
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import CONF_NAME, CONF_MONITORED_CONDITIONS
|
||||||
CONF_NAME, STATE_ON, STATE_OFF, CONF_MONITORED_CONDITIONS)
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorDevice, PLATFORM_SCHEMA)
|
BinarySensorDevice, PLATFORM_SCHEMA)
|
||||||
from homeassistant.loader import get_component
|
from homeassistant.loader import get_component
|
||||||
@ -85,18 +84,10 @@ class OctoPrintBinarySensor(BinarySensorDevice):
|
|||||||
"""Return the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
|
||||||
def state(self):
|
|
||||||
"""Return the state of the sensor."""
|
|
||||||
return self.is_on
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if binary sensor is on."""
|
"""Return true if binary sensor is on."""
|
||||||
if self._state:
|
return bool(self._state)
|
||||||
return STATE_ON
|
|
||||||
else:
|
|
||||||
return STATE_OFF
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
|
@ -11,10 +11,9 @@ import datetime
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
from homeassistant.const import (
|
from homeassistant.const import CONF_NAME, WEEKDAYS
|
||||||
STATE_ON, STATE_OFF, STATE_UNKNOWN, CONF_NAME, WEEKDAYS)
|
|
||||||
import homeassistant.util.dt as dt_util
|
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
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -92,7 +91,7 @@ def day_to_string(day):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class IsWorkdaySensor(Entity):
|
class IsWorkdaySensor(BinarySensorDevice):
|
||||||
"""Implementation of a Workday sensor."""
|
"""Implementation of a Workday sensor."""
|
||||||
|
|
||||||
def __init__(self, obj_holidays, workdays, excludes, name):
|
def __init__(self, obj_holidays, workdays, excludes, name):
|
||||||
@ -101,7 +100,7 @@ class IsWorkdaySensor(Entity):
|
|||||||
self._obj_holidays = obj_holidays
|
self._obj_holidays = obj_holidays
|
||||||
self._workdays = workdays
|
self._workdays = workdays
|
||||||
self._excludes = excludes
|
self._excludes = excludes
|
||||||
self._state = STATE_UNKNOWN
|
self._state = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -109,7 +108,7 @@ class IsWorkdaySensor(Entity):
|
|||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def is_on(self):
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@ -135,14 +134,14 @@ class IsWorkdaySensor(Entity):
|
|||||||
def async_update(self):
|
def async_update(self):
|
||||||
"""Get date and look whether it is a holiday."""
|
"""Get date and look whether it is a holiday."""
|
||||||
# Default is no workday
|
# Default is no workday
|
||||||
self._state = STATE_OFF
|
self._state = False
|
||||||
|
|
||||||
# Get iso day of the week (1 = Monday, 7 = Sunday)
|
# Get iso day of the week (1 = Monday, 7 = Sunday)
|
||||||
day = datetime.datetime.today().isoweekday() - 1
|
day = datetime.datetime.today().isoweekday() - 1
|
||||||
day_of_week = day_to_string(day)
|
day_of_week = day_to_string(day)
|
||||||
|
|
||||||
if self.is_include(day_of_week, dt_util.now()):
|
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()):
|
if self.is_exclude(day_of_week, dt_util.now()):
|
||||||
self._state = STATE_OFF
|
self._state = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user