Add support for a wider variety of EnOcean devices (#22052)

* Implement EnOcean temperature and humidity sensors.

* Bump EnOcean version to 0.50
* Refactor components for more generic device handling
* Move radio packet data interpretation to specific devices

* Update CODEOWNERS

* Implement code review changes
This commit is contained in:
Beat authored and Martin Hjelmare committed 2019-04-25 00:30:46 +02:00
1 parent fef1dc8c54
commit 96735e41af
10 files changed
+305 -153

No files matched your search

@@ -3,16 +3,17 @@ import logging
import voluptuous as vol
from homeassistant.components.binary_sensor import (
BinarySensorDevice, PLATFORM_SCHEMA, DEVICE_CLASSES_SCHEMA)
from homeassistant.components import enocean
from homeassistant.const import (
CONF_NAME, CONF_ID, CONF_DEVICE_CLASS)
from homeassistant.components.binary_sensor import (
DEVICE_CLASSES_SCHEMA, PLATFORM_SCHEMA, BinarySensorDevice)
from homeassistant.const import CONF_DEVICE_CLASS, CONF_ID, CONF_NAME
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
DEFAULT_NAME = 'EnOcean binary sensor'
DEPENDENCIES = ['enocean']
EVENT_BUTTON_PRESSED = 'button_pressed'
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_ID): vol.All(cv.ensure_list, [vol.Coerce(int)]),
@@ -24,61 +25,80 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Binary Sensor platform for EnOcean."""
dev_id = config.get(CONF_ID)
devname = config.get(CONF_NAME)
dev_name = config.get(CONF_NAME)
device_class = config.get(CONF_DEVICE_CLASS)
add_entities([EnOceanBinarySensor(dev_id, devname, device_class)])
add_entities([EnOceanBinarySensor(dev_id, dev_name, device_class)])
class EnOceanBinarySensor(enocean.EnOceanDevice, BinarySensorDevice):
"""Representation of EnOcean binary sensors such as wall switches."""
"""Representation of EnOcean binary sensors such as wall switches.
def __init__(self, dev_id, devname, device_class):
Supported EEPs (EnOcean Equipment Profiles):
- F6-02-01 (Light and Blind Control - Application Style 2)
- F6-02-02 (Light and Blind Control - Application Style 1)
"""
def __init__(self, dev_id, dev_name, device_class):
"""Initialize the EnOcean binary sensor."""
enocean.EnOceanDevice.__init__(self)
self.stype = 'listener'
self.dev_id = dev_id
super().__init__(dev_id, dev_name)
self._device_class = device_class
self.which = -1
self.onoff = -1
self.devname = devname
self._device_class = device_class
@property
def name(self):
"""Return the default name for the binary sensor."""
return self.devname
return self.dev_name
@property
def device_class(self):
"""Return the class of this sensor."""
return self._device_class
def value_changed(self, value, value2):
def value_changed(self, packet):
"""Fire an event with the data that have changed.
This method is called when there is an incoming packet associated
with this platform.
Example packet data:
- 2nd button pressed
['0xf6', '0x10', '0x00', '0x2d', '0xcf', '0x45', '0x30']
- button released
['0xf6', '0x00', '0x00', '0x2d', '0xcf', '0x45', '0x20']
"""
# Energy Bow
pushed = None
if packet.data[6] == 0x30:
pushed = 1
elif packet.data[6] == 0x20:
pushed = 0
self.schedule_update_ha_state()
if value2 == 0x70:
action = packet.data[1]
if action == 0x70:
self.which = 0
self.onoff = 0
elif value2 == 0x50:
elif action == 0x50:
self.which = 0
self.onoff = 1
elif value2 == 0x30:
elif action == 0x30:
self.which = 1
self.onoff = 0
elif value2 == 0x10:
elif action == 0x10:
self.which = 1
self.onoff = 1
elif value2 == 0x37:
elif action == 0x37:
self.which = 10
self.onoff = 0
elif value2 == 0x15:
elif action == 0x15:
self.which = 10
self.onoff = 1
self.hass.bus.fire('button_pressed', {'id': self.dev_id,
'pushed': value,
'which': self.which,
'onoff': self.onoff})
self.hass.bus.fire(EVENT_BUTTON_PRESSED,
{'id': self.dev_id,
'pushed': pushed,
'which': self.which,
'onoff': self.onoff})