Skip to content

Commit

Permalink
Merge pull request #18 from jacobtomlinson/master
Browse files Browse the repository at this point in the history
Added open, close and stop commands for Lighting5
  • Loading branch information
Danielhiversen committed May 10, 2016
2 parents eddd10b + 75016f7 commit 309ae48
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
25 changes: 25 additions & 0 deletions RFXtrx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,31 @@ def send_off(self, transport):
""" Send an 'Off' command using the given transport """
self.send_onoff(transport, False)

def send_openclosestop(self, transport, command):
""" Send an 'Open' or a 'Close' or a 'Stop' command
using the given transport """
if self.packettype == 0x14: # Lighting5
if command not in [0x0d, 0x0e, 0x0f]:
raise ValueError(command, "is not a relay packet in Lighting5")
pkt = lowlevel.Lighting5()
pkt.set_transmit(self.subtype, 0, self.id_combined, self.unitcode,
command, 0x00)
transport.send(pkt.data)
else:
raise ValueError("Unsupported packettype")

def send_open(self, transport):
""" Send an 'Open' command using the given transport """
self.send_openclosestop(transport, 0x0f)

def send_close(self, transport):
""" Send an 'Close' command using the given transport """
self.send_openclosestop(transport, 0x0d)

def send_stop(self, transport):
""" Send an 'Stop' command using the given transport """
self.send_openclosestop(transport, 0x0e)

def send_dim(self, transport, level):
""" Send a 'Dim' command with the given level using the given
transport
Expand Down
10 changes: 8 additions & 2 deletions doctest/test_lighting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Lighting2
>>> print(x)
<class 'RFXtrx.LightingDevice'> type='AC' id='1234567:5'
>>> transport = DummyTransport()
>>> x = transport.receive([0x0b, 0x11, 0x00, 0x2a, 0x01, 0x23, 0x45, 0x67, 0x05, 0x02, 0x07, 0x70])
>>> x = transport.receive([0x0b, 0x11, 0x00, 0x2a, 0x01, 0x23, 0x45, 0x67, 0x05, 0x02, 0x07, 0x70])
Recv: 0x0b 0x11 0x00 0x2a 0x01 0x23 0x45 0x67 0x05 0x02 0x07 0x70
>>> print(x)
<class 'RFXtrx.ControlEvent'> device=[<class 'RFXtrx.LightingDevice'> type='AC' id='1234567:5'] values=[('Command', 'Set level'), ('Dim level', 50), ('Rssi numeric', 7)]
Expand Down Expand Up @@ -82,6 +82,12 @@ Recv: 0x0a 0x14 0x00 0x2a 0x12 0x34 0x56 0x07 0x10 0x0f 0x70
Send: 0x0a 0x14 0x00 0x00 0x12 0x34 0x56 0x07 0x01 0x00 0x00
>>> x.device.send_off(transport)
Send: 0x0a 0x14 0x00 0x00 0x12 0x34 0x56 0x07 0x00 0x00 0x00
>>> x.device.send_open(transport)
Send: 0x0a 0x14 0x00 0x00 0x12 0x34 0x56 0x07 0x0f 0x00 0x00
>>> x.device.send_close(transport)
Send: 0x0a 0x14 0x00 0x00 0x12 0x34 0x56 0x07 0x0d 0x00 0x00
>>> x.device.send_stop(transport)
Send: 0x0a 0x14 0x00 0x00 0x12 0x34 0x56 0x07 0x0e 0x00 0x00
>>> x.device.send_dim(transport, 0)
Send: 0x0a 0x14 0x00 0x00 0x12 0x34 0x56 0x07 0x00 0x00 0x00
>>> x.device.send_dim(transport, 1)
Expand All @@ -102,7 +108,7 @@ Lighting6
>>> print(x)
<class 'RFXtrx.LightingDevice'> type='Blyss' id='1234:A5'
>>> transport = DummyTransport()
>>> x = transport.receive([0x0b, 0x15, 0x00, 0x2a, 0x12, 0x34, 0x41, 0x05, 0x03, 0x01, 0x00, 0x70])
>>> x = transport.receive([0x0b, 0x15, 0x00, 0x2a, 0x12, 0x34, 0x41, 0x05, 0x03, 0x01, 0x00, 0x70])
Recv: 0x0b 0x15 0x00 0x2a 0x12 0x34 0x41 0x05 0x03 0x01 0x00 0x70
>>> print(x)
<class 'RFXtrx.ControlEvent'> device=[<class 'RFXtrx.LightingDevice'> type='Blyss' id='1234:A5'] values=[('Command', 'Group off'), ('Rssi numeric', 7)]
Expand Down
6 changes: 4 additions & 2 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def test_format_packet(self):
event = core.transport.parse(bytes_array)
event.device.send_on(core.transport)
event.device.send_off(core.transport)
event.device.send_open(core.transport)
event.device.send_close(core.transport)
event.device.send_stop(core.transport)
self.assertRaises(ValueError,event.device.send_openclosestop,core.transport,0x0c)
self.assertRaises(ValueError,event.device.send_dim,core.transport,150)
self.assertRaises(ValueError,event.device.send_dim,core.transport,-1)
event.device.send_dim(core.transport,50)
Expand Down Expand Up @@ -324,5 +328,3 @@ def test_receive(self):
self.assertEquals(RFXtrx.StatusEvent, type(event))
self.assertEquals(event.__str__(),"<class 'RFXtrx.StatusEvent'> device=[Status [subtype=433.92MHz, firmware=69, devices=['ac', 'arc', 'hideki', 'homeeasy', 'lacrosse', 'oregon', 'x10']]]")
core.close_connection()


0 comments on commit 309ae48

Please sign in to comment.