Skip to content

Commit

Permalink
Fix sensors to respond to All-Link Broadcast messages correctly (#60)
Browse files Browse the repository at this point in the history
* Fix sensors to respond correctly to all-link broadcast messages.

* Bump version to 0.8.6
  • Loading branch information
teharris1 authored Apr 4, 2018
1 parent 347e6a3 commit ff99bd2
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 40 deletions.
85 changes: 60 additions & 25 deletions insteonplm/states/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,46 +40,34 @@ def __init__(self, address, statename, group, send_message_method,
template_on_broadcast = StandardReceive.template(
commandtuple=COMMAND_LIGHT_ON_0X11_NONE,
address=self._address,
flags=MessageFlags.template(MESSAGE_TYPE_BROADCAST_MESSAGE, None))
template_off_broadcast = StandardReceive.template(
commandtuple=COMMAND_LIGHT_OFF_0X13_0X00,
address=self._address,
target=bytearray([0x00, 0x00, self._group]),
flags=MessageFlags.template(MESSAGE_TYPE_BROADCAST_MESSAGE, None),
cmd2=None)

template_on_cleanup = StandardReceive.template(
commandtuple=COMMAND_LIGHT_ON_0X11_NONE,
address=self._address,
flags=MessageFlags.template(MESSAGE_TYPE_ALL_LINK_CLEANUP, None))
template_off_cleanup = StandardReceive.template(
template_off_broadcast = StandardReceive.template(
commandtuple=COMMAND_LIGHT_OFF_0X13_0X00,
address=self._address,
flags=MessageFlags.template(MESSAGE_TYPE_ALL_LINK_CLEANUP, None),
target=bytearray([0x00, 0x00, self._group]),
flags=MessageFlags.template(MESSAGE_TYPE_BROADCAST_MESSAGE, None),
cmd2=None)

template_on_group = StandardReceive.template(
commandtuple=COMMAND_LIGHT_ON_0X11_NONE,
address=self._address,
target=bytearray([0x00, 0x00, self._group]),
flags=MessageFlags.template(MESSAGE_TYPE_ALL_LINK_BROADCAST, None),
cmd2=self._group)
cmd2=None)
template_off_group = StandardReceive.template(
commandtuple=COMMAND_LIGHT_OFF_0X13_0X00,
address=self._address,
target=bytearray([0x00, 0x00, self._group]),
flags=MessageFlags.template(MESSAGE_TYPE_ALL_LINK_BROADCAST, None),
cmd2=self._group)
cmd2=None)

self._message_callbacks.add(template_on_broadcast,
self._sensor_on_command_received)
self._message_callbacks.add(template_off_broadcast,
self._sensor_off_command_received)

self._message_callbacks.add(template_on_cleanup,
self._sensor_on_command_received)
self._message_callbacks.add(template_off_cleanup,
self._sensor_off_command_received)

self._message_callbacks.add(template_on_group,
self._sensor_on_command_received)
self._message_callbacks.add(template_off_group,
Expand Down Expand Up @@ -171,7 +159,6 @@ def __init__(self, address, statename, group, send_message_method,
template_group = StandardReceive.template(
commandtuple=COMMAND_LIGHT_ON_0X11_NONE,
address=self._address,
target=bytearray([0x00, 0x00, self._group]),
flags=MessageFlags.template(MESSAGE_TYPE_ALL_LINK_BROADCAST, None))

self._message_callbacks.add(template_broadcast,
Expand Down Expand Up @@ -295,13 +282,31 @@ def __init__(self, address, statename, group, send_message_method,
self._dry_wet_type = dry_wet
self._dry_wet_callbacks = []

dry_wet_template = StandardReceive.template(
template_broadcast = StandardReceive.template(
commandtuple=COMMAND_LIGHT_ON_0X11_NONE,
address=self._address,
target=bytearray([0x00, 0x00, self._group]),
flags=MessageFlags.template(MESSAGE_TYPE_BROADCAST_MESSAGE, None))

self._message_callbacks.add(dry_wet_template,
template_all_link = StandardReceive.template(
commandtuple=COMMAND_LIGHT_ON_0X11_NONE,
address=self._address,
target=bytearray([0x00, 0x00, self._group]),
flags=MessageFlags.template(MESSAGE_TYPE_ALL_LINK_BROADCAST, None))

template_cleanup= StandardReceive.template(
commandtuple=COMMAND_LIGHT_ON_0X11_NONE,
address=self._address,
target=bytearray([0x00, 0x00, self._group]),
flags=MessageFlags.template(MESSAGE_TYPE_ALL_LINK_CLEANUP, None))

self._message_callbacks.add(template_broadcast,
self._dry_wet_message_received)

self._message_callbacks.add(template_all_link,
self._dry_wet_message_received)

self._message_callbacks.add(template_cleanup,
self._dry_wet_message_received)

def register_dry_wet_callback(self, callback):
Expand Down Expand Up @@ -343,21 +348,51 @@ def __init__(self, address, statename, group, send_message_method,

self._dry_wet_callbacks = []

dry_template = StandardReceive.template(
template_dry_broadcast = StandardReceive.template(
commandtuple=COMMAND_LIGHT_ON_0X11_NONE,
cmd2=self._group,
address=self._address,
target=bytearray([0x00, 0x00, self._group]),
flags=MessageFlags.template(MESSAGE_TYPE_BROADCAST_MESSAGE, None))

wet_template = StandardReceive.template(
template_wet_broadcast = StandardReceive.template(
commandtuple={'cmd1': 0x13, 'cmd2': self._group},
address=self._address,
target=bytearray([0x00, 0x00, self._group]),
flags=MessageFlags.template(MESSAGE_TYPE_BROADCAST_MESSAGE, None))

self._message_callbacks.add(dry_template, self._dry_message_received)
self._message_callbacks.add(wet_template, self._wet_message_received)
template_dry_all_link = StandardReceive.template(
commandtuple=COMMAND_LIGHT_ON_0X11_NONE,
cmd2=self._group,
address=self._address,
target=bytearray([0x00, 0x00, self._group]),
flags=MessageFlags.template(MESSAGE_TYPE_ALL_LINK_BROADCAST, None))

template_wet_all_link = StandardReceive.template(
commandtuple={'cmd1': 0x13, 'cmd2': self._group},
address=self._address,
target=bytearray([0x00, 0x00, self._group]),
flags=MessageFlags.template(MESSAGE_TYPE_ALL_LINK_BROADCAST, None))

template_dry_cleanup = StandardReceive.template(
commandtuple=COMMAND_LIGHT_ON_0X11_NONE,
cmd2=self._group,
address=self._address,
target=bytearray([0x00, 0x00, self._group]),
flags=MessageFlags.template(MESSAGE_TYPE_ALL_LINK_CLEANUP, None))

template_wet_cleanup = StandardReceive.template(
commandtuple={'cmd1': 0x13, 'cmd2': self._group},
address=self._address,
target=bytearray([0x00, 0x00, self._group]),
flags=MessageFlags.template(MESSAGE_TYPE_ALL_LINK_CLEANUP, None))

self._message_callbacks.add(template_dry_broadcast, self._dry_message_received)
self._message_callbacks.add(template_wet_broadcast, self._wet_message_received)
self._message_callbacks.add(template_dry_all_link, self._dry_message_received)
self._message_callbacks.add(template_wet_all_link, self._wet_message_received)
self._message_callbacks.add(template_dry_cleanup, self._dry_message_received)
self._message_callbacks.add(template_wet_cleanup, self._wet_message_received)

def register_dry_wet_callback(self, callback):
"""Register the callback for the wet and dry state callbacks."""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

setup(
name='insteonplm',
version='0.8.5',
version='0.8.6',
author='David McNett',
author_email='nugget@macnugget.org',
url='https://github.com/nugget/python-insteonplm',
Expand Down
30 changes: 16 additions & 14 deletions tests/test_securityHealthSafety.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

from insteonplm.constants import (COMMAND_LIGHT_OFF_0X13_0X00,
COMMAND_LIGHT_ON_0X11_NONE,
MESSAGE_FLAG_BROADCAST_0X80,
MESSAGE_TYPE_BROADCAST_MESSAGE,
MESSAGE_TYPE_ALL_LINK_BROADCAST,
MESSAGE_TYPE_ALL_LINK_CLEANUP)

from insteonplm.devices.securityHealthSafety import (
SecurityHealthSafety, SecurityHealthSafety_2842_222,
SecurityHealthSafety_2845_222, SecurityHealthSafety_2852_222,
Expand All @@ -20,8 +22,8 @@ def _onOffSenorTest(onOffClass, loop):
"""Test on/off sensor."""
plm = MockPLM()
address = '1a2b3c'
target = '4d5e6f'
cmd2 = 0x04
target = bytearray([0x00, 0x00, 0x01])
cmd2 = 0x01

cat = 0x10
subcat = 0x00
Expand All @@ -36,7 +38,7 @@ def _onOffSenorTest(onOffClass, loop):
device.states[0x01].register_updates(callbacks.callbackmethod1)
msg = StandardReceive(
address, target, COMMAND_LIGHT_ON_0X11_NONE, cmd2=cmd2,
flags=MessageFlags.create(MESSAGE_TYPE_ALL_LINK_CLEANUP, 0, 3, 3))
flags=MessageFlags.create(MESSAGE_TYPE_ALL_LINK_BROADCAST, 0, 3, 3))
plm.message_received(msg)
yield from asyncio.sleep(.1, loop=loop)
assert callbacks.callbackvalue1 == 1
Expand All @@ -46,7 +48,7 @@ def _onOffSenorTest(onOffClass, loop):
device.states[0x01].register_updates(callbacks.callbackmethod1)
msg = StandardReceive(
address, target, COMMAND_LIGHT_OFF_0X13_0X00,
flags=MessageFlags.create(MESSAGE_TYPE_ALL_LINK_CLEANUP, 0, 3, 3))
flags=MessageFlags.create(MESSAGE_TYPE_ALL_LINK_BROADCAST, 0, 3, 3))
plm.message_received(msg)
yield from asyncio.sleep(.1, loop=loop)
assert callbacks.callbackvalue1 == 0
Expand All @@ -68,8 +70,8 @@ def sensor_status_callback(self, device_id, state, value):

plm = MockPLM()
address = '1a2b3c'
target = '4d5e6f'
cmd2 = 0x04
target = bytearray([0x00, 0x00, 0x01])
cmd2 = 0x01

cat = 0x10
subcat = 0x00
Expand All @@ -84,7 +86,7 @@ def sensor_status_callback(self, device_id, state, value):
device.states[0x01].register_updates(callbacks.callbackmethod1)
msg = StandardReceive(
address, target, COMMAND_LIGHT_ON_0X11_NONE, cmd2=cmd2,
flags=MessageFlags.create(MESSAGE_TYPE_ALL_LINK_CLEANUP, 0, 3, 3))
flags=MessageFlags.create(MESSAGE_TYPE_ALL_LINK_BROADCAST, 0, 3, 3))
plm.message_received(msg)
yield from asyncio.sleep(.1, loop=loop)
assert callbacks.callbackvalue1 == cmd2
Expand All @@ -94,7 +96,7 @@ def sensor_status_callback(self, device_id, state, value):
device.states[0x01].register_updates(callbacks.callbackmethod1)
msg = StandardReceive(
address, target, COMMAND_LIGHT_OFF_0X13_0X00,
flags=MessageFlags.create(MESSAGE_TYPE_ALL_LINK_CLEANUP, 0, 3, 3))
flags=MessageFlags.create(MESSAGE_TYPE_ALL_LINK_BROADCAST, 0, 3, 3))
plm.message_received(msg)
yield from asyncio.sleep(.1, loop=loop)
assert callbacks.callbackvalue1 == 0x00
Expand Down Expand Up @@ -123,7 +125,7 @@ def test_securityhealthsafety_2982_222():
device.states[0x01].register_updates(callbacks.callbackmethod1)
msg = StandardReceive(
address, target, COMMAND_LIGHT_ON_0X11_NONE, cmd2=cmd2,
flags=MessageFlags.create(MESSAGE_FLAG_BROADCAST_0X80, 0, 0, 0))
flags=MessageFlags.create(MESSAGE_TYPE_ALL_LINK_BROADCAST, 0, 0, 0))
plm.message_received(msg)
# target hiByte
assert callbacks.callbackvalue1 == 0x6f
Expand Down Expand Up @@ -171,7 +173,7 @@ def _run_test(loop):
address=address,
target=bytearray([0x00, 0x00, 0x01]),
commandtuple=COMMAND_LIGHT_ON_0X11_NONE, cmd2=0x01,
flags=MessageFlags.create(MESSAGE_FLAG_BROADCAST_0X80, 0, 3, 3))
flags=MessageFlags.create(MESSAGE_TYPE_ALL_LINK_BROADCAST, 0, 3, 3))
plm.message_received(msg)
yield from asyncio.sleep(.1, loop=loop)
assert callbacks.callbackvalue1 == 1
Expand All @@ -183,7 +185,7 @@ def _run_test(loop):
address=address,
target=bytearray([0x00, 0x00, 0x02]),
commandtuple=COMMAND_LIGHT_ON_0X11_NONE, cmd2=0x02,
flags=MessageFlags.create(MESSAGE_FLAG_BROADCAST_0X80, 0, 3, 3))
flags=MessageFlags.create(MESSAGE_TYPE_ALL_LINK_BROADCAST, 0, 3, 3))
plm.message_received(msg)
yield from asyncio.sleep(.1, loop=loop)
assert callbacks.callbackvalue1 == 0
Expand All @@ -195,7 +197,7 @@ def _run_test(loop):
address=address,
target=bytearray([0x00, 0x00, 0x04]),
commandtuple=COMMAND_LIGHT_ON_0X11_NONE, cmd2=0x04,
flags=MessageFlags.create(MESSAGE_FLAG_BROADCAST_0X80, 0, 3, 3))
flags=MessageFlags.create(MESSAGE_TYPE_ALL_LINK_BROADCAST, 0, 3, 3))
plm.message_received(msg)
yield from asyncio.sleep(.1, loop=loop)
assert callbacks.callbackvalue1 == 1
Expand All @@ -206,7 +208,7 @@ def _run_test(loop):
address=address,
target=bytearray([0x00, 0x00, 0x04]),
commandtuple={'cmd1': 0x13, 'cmd2': 0x04},
flags=MessageFlags.create(MESSAGE_FLAG_BROADCAST_0X80, 0, 3, 3))
flags=MessageFlags.create(MESSAGE_TYPE_ALL_LINK_BROADCAST, 0, 3, 3))
plm.message_received(msg)
yield from asyncio.sleep(.1, loop=loop)
assert callbacks.callbackvalue1 == 0
Expand Down

0 comments on commit ff99bd2

Please sign in to comment.