Skip to content

Commit

Permalink
Merge pull request #25 from Danielhiversen/lighting4
Browse files Browse the repository at this point in the history
Lighting4
  • Loading branch information
Danielhiversen authored Jul 8, 2016
2 parents 2a46202 + 4303f37 commit 28cc866
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
9 changes: 8 additions & 1 deletion RFXtrx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def send_onoff(self, transport, turn_on):
self.cmndseqnbr = (self.cmndseqnbr + 1) % 5
transport.send(pkt.data)
else:
raise ValueError("Unsupported packettype")
return

def send_on(self, transport):
""" Send an 'On' command using the given transport """
Expand Down Expand Up @@ -247,6 +247,7 @@ def send_dim(self, transport, level):

def get_device(packettype, subtype, id_string):
""" Return a device base on its identifying values """
# pylint: disable=too-many-return-statements
if packettype == 0x10: # Lighting1
pkt = lowlevel.Lighting1()
pkt.parse_id(subtype, id_string)
Expand All @@ -259,6 +260,10 @@ def get_device(packettype, subtype, id_string):
pkt = lowlevel.Lighting3()
pkt.parse_id(subtype, id_string)
return LightingDevice(pkt)
elif packettype == 0x13: # Lighting4
pkt = lowlevel.Lighting4()
pkt.parse_id(subtype, id_string)
return LightingDevice(pkt)
elif packettype == 0x14: # Lighting5
pkt = lowlevel.Lighting5()
pkt.parse_id(subtype, id_string)
Expand Down Expand Up @@ -352,9 +357,11 @@ class ControlEvent(RFXtrxEvent):
""" Concrete class for control events """

def __init__(self, pkt):
# pylint: disable=too-many-boolean-expressions
if isinstance(pkt, lowlevel.Lighting1) \
or isinstance(pkt, lowlevel.Lighting2) \
or isinstance(pkt, lowlevel.Lighting3) \
or isinstance(pkt, lowlevel.Lighting4) \
or isinstance(pkt, lowlevel.Lighting5) \
or isinstance(pkt, lowlevel.Lighting6):
device = LightingDevice(pkt)
Expand Down
3 changes: 3 additions & 0 deletions RFXtrx/lowlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ def __init__(self):
self.pulsehigh = None
self.pulselow = None
self.pulse = None
self.cmnd_string = ""

def parse_id(self, subtype, id_string):
"""Parse a string id into individual components"""
Expand Down Expand Up @@ -686,6 +687,8 @@ def _set_strings(self):
# Degrade nicely for yet unknown subtypes
self.type_string = self._UNKNOWN_TYPE.format(self.packettype,
self.subtype)
if self.cmd is not None:
self.cmnd_string = "{0:#04x}".format(self.cmd)


###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_format_packet(self):
bytes_array = [0x09, 0x13, 0x00, 0x2a, 0x12, 0x34, 0x56, 0x01, 0x5e, 0x70]
event = core.transport.parse(bytes_array)
self.assertEquals(RFXtrx.ControlEvent, type(event))
self.assertEquals(RFXtrx.RFXtrxDevice, type(event.device))
self.assertEquals(RFXtrx.LightingDevice, type(event.device))
# event.device.send_on(core.transport)
# event.device.send_off(core.transport)
# self.assertRaises(ValueError,event.device.send_dim,core.transport,50)
Expand Down

0 comments on commit 28cc866

Please sign in to comment.