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
7 changes: 5 additions & 2 deletions homeassistant/components/enocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def callback(self, temp):
_LOGGER.debug("Received radio packet: %s", temp)
rxtype = None
value = None
channel = 0
if temp.data[6] == 0x30:
rxtype = "wallswitch"
value = 1
Expand All @@ -84,8 +85,9 @@ def callback(self, temp):
elif temp.data[4] == 0x0c:
rxtype = "power"
value = temp.data[3] + (temp.data[2] << 8)
elif temp.data[2] == 0x60:
elif temp.data[2] & 0x60 == 0x60:
rxtype = "switch_status"
channel = temp.data[2] & 0x1F
if temp.data[3] == 0xe4:
value = 1
elif temp.data[3] == 0x80:
Expand All @@ -104,7 +106,8 @@ def callback(self, temp):
if temp.sender_int == self._combine_hex(device.dev_id):
if value > 10:
device.value_changed(1)
if rxtype == "switch_status" and device.stype == "switch":
if rxtype == "switch_status" and device.stype == "switch" and \
channel == device.channel:
if temp.sender_int == self._combine_hex(device.dev_id):
device.value_changed(value)
if rxtype == "dimmerstatus" and device.stype == "dimmer":
Expand Down
12 changes: 8 additions & 4 deletions homeassistant/components/switch/enocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,36 @@

DEFAULT_NAME = 'EnOcean Switch'
DEPENDENCIES = ['enocean']
CONF_CHANNEL = 'channel'

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_CHANNEL, default=0): cv.positive_int,
})


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the EnOcean switch platform."""
dev_id = config.get(CONF_ID)
devname = config.get(CONF_NAME)
channel = config.get(CONF_CHANNEL)

add_devices([EnOceanSwitch(dev_id, devname)])
add_devices([EnOceanSwitch(dev_id, devname, channel)])


class EnOceanSwitch(enocean.EnOceanDevice, ToggleEntity):
"""Representation of an EnOcean switch device."""

def __init__(self, dev_id, devname):
def __init__(self, dev_id, devname, channel):
"""Initialize the EnOcean switch device."""
enocean.EnOceanDevice.__init__(self)
self.dev_id = dev_id
self._devname = devname
self._light = None
self._on_state = False
self._on_state2 = False
self.channel = channel
self.stype = "switch"

@property
Expand All @@ -61,7 +65,7 @@ def turn_on(self, **kwargs):
optional = [0x03, ]
optional.extend(self.dev_id)
optional.extend([0xff, 0x00])
self.send_command(data=[0xD2, 0x01, 0x00, 0x64, 0x00,
self.send_command(data=[0xD2, 0x01, self.channel & 0xFF, 0x64, 0x00,
0x00, 0x00, 0x00, 0x00], optional=optional,
packet_type=0x01)
self._on_state = True
Expand All @@ -71,7 +75,7 @@ def turn_off(self, **kwargs):
optional = [0x03, ]
optional.extend(self.dev_id)
optional.extend([0xff, 0x00])
self.send_command(data=[0xD2, 0x01, 0x00, 0x00, 0x00,
self.send_command(data=[0xD2, 0x01, self.channel & 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00], optional=optional,
packet_type=0x01)
self._on_state = False
Expand Down