Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions homeassistant/components/binary_sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
from homeassistant.helpers.entity import Entity
from homeassistant.const import (STATE_ON, STATE_OFF)
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
from homeassistant.helpers.deprecation import deprecated_substitute

DOMAIN = 'binary_sensor'
SCAN_INTERVAL = timedelta(seconds=30)

ENTITY_ID_FORMAT = DOMAIN + '.{}'
SENSOR_CLASSES = [
None, # Generic on/off
DEVICE_CLASSES = [
'cold', # On means cold (or too cold)
'connectivity', # On means connection present, Off = no connection
'gas', # CO, CO2, etc.
Expand All @@ -38,7 +38,7 @@
'vibration', # On means vibration detected, Off means no vibration
]

SENSOR_CLASSES_SCHEMA = vol.All(vol.Lower, vol.In(SENSOR_CLASSES))
DEVICE_CLASSES_SCHEMA = vol.All(vol.Lower, vol.In(DEVICE_CLASSES))


@asyncio.coroutine
Expand Down Expand Up @@ -66,16 +66,7 @@ def state(self):
return STATE_ON if self.is_on else STATE_OFF

@property
def sensor_class(self):
"""Return the class of this sensor, from SENSOR_CLASSES."""
@deprecated_substitute('sensor_class')
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
return None

@property
def state_attributes(self):
"""Return device specific state attributes."""
attr = {}

if self.sensor_class is not None:
attr['sensor_class'] = self.sensor_class

return attr
20 changes: 11 additions & 9 deletions homeassistant/components/binary_sensor/arest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import voluptuous as vol

from homeassistant.components.binary_sensor import (
BinarySensorDevice, PLATFORM_SCHEMA, SENSOR_CLASSES_SCHEMA)
BinarySensorDevice, PLATFORM_SCHEMA, DEVICE_CLASSES_SCHEMA)
from homeassistant.const import (
CONF_RESOURCE, CONF_PIN, CONF_NAME, CONF_SENSOR_CLASS)
CONF_RESOURCE, CONF_PIN, CONF_NAME, CONF_SENSOR_CLASS, CONF_DEVICE_CLASS)
from homeassistant.util import Throttle
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.deprecation import get_deprecated

_LOGGER = logging.getLogger(__name__)

Expand All @@ -25,15 +26,16 @@
vol.Required(CONF_RESOURCE): cv.url,
vol.Optional(CONF_NAME): cv.string,
vol.Required(CONF_PIN): cv.string,
vol.Optional(CONF_SENSOR_CLASS): SENSOR_CLASSES_SCHEMA,
vol.Optional(CONF_SENSOR_CLASS): DEVICE_CLASSES_SCHEMA,
vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA,
})


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the aREST binary sensor."""
resource = config.get(CONF_RESOURCE)
pin = config.get(CONF_PIN)
sensor_class = config.get(CONF_SENSOR_CLASS)
device_class = get_deprecated(config, CONF_DEVICE_CLASS, CONF_SENSOR_CLASS)

try:
response = requests.get(resource, timeout=10).json()
Expand All @@ -49,18 +51,18 @@ def setup_platform(hass, config, add_devices, discovery_info=None):

add_devices([ArestBinarySensor(
arest, resource, config.get(CONF_NAME, response[CONF_NAME]),
sensor_class, pin)])
device_class, pin)])


class ArestBinarySensor(BinarySensorDevice):
"""Implement an aREST binary sensor for a pin."""

def __init__(self, arest, resource, name, sensor_class, pin):
def __init__(self, arest, resource, name, device_class, pin):
"""Initialize the aREST device."""
self.arest = arest
self._resource = resource
self._name = name
self._sensor_class = sensor_class
self._device_class = device_class
self._pin = pin
self.update()

Expand All @@ -81,9 +83,9 @@ def is_on(self):
return bool(self.arest.data.get('state'))

@property
def sensor_class(self):
def device_class(self):
"""Return the class of this sensor."""
return self._sensor_class
return self._device_class

def update(self):
"""Get the latest data from aREST API."""
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/binary_sensor/bloomsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def unique_id(self):
return self._unique_id

@property
def sensor_class(self):
"""Return the class of this sensor, from SENSOR_CLASSES."""
def device_class(self):
"""Return the class of this sensor, from DEVICE_CLASSES."""
return SENSOR_TYPES.get(self._sensor_name)

@property
Expand Down
20 changes: 11 additions & 9 deletions homeassistant/components/binary_sensor/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
import voluptuous as vol

from homeassistant.components.binary_sensor import (
BinarySensorDevice, SENSOR_CLASSES_SCHEMA, PLATFORM_SCHEMA)
BinarySensorDevice, DEVICE_CLASSES_SCHEMA, PLATFORM_SCHEMA)
from homeassistant.components.sensor.command_line import CommandSensorData
from homeassistant.const import (
CONF_PAYLOAD_OFF, CONF_PAYLOAD_ON, CONF_NAME, CONF_VALUE_TEMPLATE,
CONF_SENSOR_CLASS, CONF_COMMAND)
CONF_SENSOR_CLASS, CONF_COMMAND, CONF_DEVICE_CLASS)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.deprecation import get_deprecated

_LOGGER = logging.getLogger(__name__)

Expand All @@ -30,7 +31,8 @@
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_PAYLOAD_OFF, default=DEFAULT_PAYLOAD_OFF): cv.string,
vol.Optional(CONF_PAYLOAD_ON, default=DEFAULT_PAYLOAD_ON): cv.string,
vol.Optional(CONF_SENSOR_CLASS): SENSOR_CLASSES_SCHEMA,
vol.Optional(CONF_SENSOR_CLASS): DEVICE_CLASSES_SCHEMA,
vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA,
vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
})

Expand All @@ -42,27 +44,27 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
command = config.get(CONF_COMMAND)
payload_off = config.get(CONF_PAYLOAD_OFF)
payload_on = config.get(CONF_PAYLOAD_ON)
sensor_class = config.get(CONF_SENSOR_CLASS)
device_class = get_deprecated(config, CONF_DEVICE_CLASS, CONF_SENSOR_CLASS)
value_template = config.get(CONF_VALUE_TEMPLATE)
if value_template is not None:
value_template.hass = hass
data = CommandSensorData(command)

add_devices([CommandBinarySensor(
hass, data, name, sensor_class, payload_on, payload_off,
hass, data, name, device_class, payload_on, payload_off,
value_template)])


class CommandBinarySensor(BinarySensorDevice):
"""Represent a command line binary sensor."""

def __init__(self, hass, data, name, sensor_class, payload_on,
def __init__(self, hass, data, name, device_class, payload_on,
payload_off, value_template):
"""Initialize the Command line binary sensor."""
self._hass = hass
self.data = data
self._name = name
self._sensor_class = sensor_class
self._device_class = device_class
self._state = False
self._payload_on = payload_on
self._payload_off = payload_off
Expand All @@ -80,9 +82,9 @@ def is_on(self):
return self._state

@ property
def sensor_class(self):
def device_class(self):
"""Return the class of the binary sensor."""
return self._sensor_class
return self._device_class

def update(self):
"""Get the latest data and updates the state."""
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/binary_sensor/concord232.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import voluptuous as vol

from homeassistant.components.binary_sensor import (
BinarySensorDevice, PLATFORM_SCHEMA, SENSOR_CLASSES)
BinarySensorDevice, PLATFORM_SCHEMA, DEVICE_CLASSES)
from homeassistant.const import (CONF_HOST, CONF_PORT)
import homeassistant.helpers.config_validation as cv

Expand All @@ -30,7 +30,7 @@
SCAN_INTERVAL = datetime.timedelta(seconds=1)

ZONE_TYPES_SCHEMA = vol.Schema({
cv.positive_int: vol.In(SENSOR_CLASSES),
cv.positive_int: vol.In(DEVICE_CLASSES),
})

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
Expand Down Expand Up @@ -102,8 +102,8 @@ def __init__(self, hass, client, zone, zone_type):
self.update()

@property
def sensor_class(self):
"""Return the class of this sensor, from SENSOR_CLASSES."""
def device_class(self):
"""Return the class of this sensor, from DEVICE_CLASSES."""
return self._zone_type

@property
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/binary_sensor/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class DemoBinarySensor(BinarySensorDevice):
"""A Demo binary sensor."""

def __init__(self, name, state, sensor_class):
def __init__(self, name, state, device_class):
"""Initialize the demo sensor."""
self._name = name
self._state = state
self._sensor_type = sensor_class
self._sensor_type = device_class

@property
def sensor_class(self):
def device_class(self):
"""Return the class of this sensor."""
return self._sensor_type

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/binary_sensor/digital_ocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def is_on(self):
return self.data.status == 'active'

@property
def sensor_class(self):
def device_class(self):
"""Return the class of this sensor."""
return DEFAULT_SENSOR_CLASS

Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/binary_sensor/ecobee.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, sensor_name, sensor_index):
self.sensor_name = sensor_name
self.index = sensor_index
self._state = None
self._sensor_class = 'occupancy'
self._device_class = 'occupancy'
self.update()

@property
Expand All @@ -57,9 +57,9 @@ def unique_id(self):
return "binary_sensor_ecobee_{}_{}".format(self._name, self.index)

@property
def sensor_class(self):
"""Return the class of this sensor, from SENSOR_CLASSES."""
return self._sensor_class
def device_class(self):
"""Return the class of this sensor, from DEVICE_CLASSES."""
return self._device_class

def update(self):
"""Get the latest state of the sensor."""
Expand Down
21 changes: 12 additions & 9 deletions homeassistant/components/binary_sensor/enocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import voluptuous as vol

from homeassistant.components.binary_sensor import (
BinarySensorDevice, PLATFORM_SCHEMA, SENSOR_CLASSES_SCHEMA)
BinarySensorDevice, PLATFORM_SCHEMA, DEVICE_CLASSES_SCHEMA)
from homeassistant.components import enocean
from homeassistant.const import (CONF_NAME, CONF_ID, CONF_SENSOR_CLASS)
from homeassistant.const import (
CONF_NAME, CONF_ID, CONF_SENSOR_CLASS, CONF_DEVICE_CLASS)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.deprecation import get_deprecated

_LOGGER = logging.getLogger(__name__)

Expand All @@ -22,41 +24,42 @@
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_ID): vol.All(cv.ensure_list, [vol.Coerce(int)]),
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_SENSOR_CLASS, default=None): SENSOR_CLASSES_SCHEMA,
vol.Optional(CONF_SENSOR_CLASS): DEVICE_CLASSES_SCHEMA,
vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA,
})


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Binary Sensor platform fo EnOcean."""
dev_id = config.get(CONF_ID)
devname = config.get(CONF_NAME)
sensor_class = config.get(CONF_SENSOR_CLASS)
device_class = get_deprecated(config, CONF_DEVICE_CLASS, CONF_SENSOR_CLASS)

add_devices([EnOceanBinarySensor(dev_id, devname, sensor_class)])
add_devices([EnOceanBinarySensor(dev_id, devname, device_class)])


class EnOceanBinarySensor(enocean.EnOceanDevice, BinarySensorDevice):
"""Representation of EnOcean binary sensors such as wall switches."""

def __init__(self, dev_id, devname, sensor_class):
def __init__(self, dev_id, devname, device_class):
"""Initialize the EnOcean binary sensor."""
enocean.EnOceanDevice.__init__(self)
self.stype = "listener"
self.dev_id = dev_id
self.which = -1
self.onoff = -1
self.devname = devname
self._sensor_class = sensor_class
self._device_class = device_class

@property
def name(self):
"""The default name for the binary sensor."""
return self.devname

@property
def sensor_class(self):
def device_class(self):
"""Return the class of this sensor."""
return self._sensor_class
return self._device_class

def value_changed(self, value, value2):
"""Fire an event with the data that have changed.
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/binary_sensor/envisalink.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def is_on(self):
return self._info['status']['open']

@property
def sensor_class(self):
"""Return the class of this sensor, from SENSOR_CLASSES."""
def device_class(self):
"""Return the class of this sensor, from DEVICE_CLASSES."""
return self._zone_type

def _update_callback(self, zone):
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/binary_sensor/ffmpeg_motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ def async_start_ffmpeg(self):
)

@property
def sensor_class(self):
"""Return the class of this sensor, from SENSOR_CLASSES."""
def device_class(self):
"""Return the class of this sensor, from DEVICE_CLASSES."""
return "motion"
4 changes: 2 additions & 2 deletions homeassistant/components/binary_sensor/ffmpeg_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ def async_start_ffmpeg(self):
)

@property
def sensor_class(self):
"""Return the class of this sensor, from SENSOR_CLASSES."""
def device_class(self):
"""Return the class of this sensor, from DEVICE_CLASSES."""
return "sound"
7 changes: 2 additions & 5 deletions homeassistant/components/binary_sensor/flic.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,9 @@ def should_poll(self):
return False

@property
def state_attributes(self):
def device_state_attributes(self):
"""Return device specific state attributes."""
attr = super(FlicButton, self).state_attributes
attr["address"] = self.address

return attr
return {"address": self.address}

def _queued_event_check(self, click_type, time_diff):
"""Generate a log message and returns true if timeout exceeded."""
Expand Down
Loading