def run_test(loop): housecode = 'C' # byte 0x02 unitcode = 9 # byte 0x07 plm = MockPLM(loop) device = X10OnOff(plm, housecode, unitcode) plm.devices[device.address.id] = device _LOGGER.debug('X10 device id: %s', device.address.id) assert device.address.human == 'X10.{}.{:02d}'.format( housecode, unitcode) # Send On command and test both commands sent device.states[0x01].on() yield from asyncio.sleep(.1, loop=loop) assert plm.sentmessage == '02632700' msg = X10Send(0x27, 0x00, 0x06) device.receive_message(msg) yield from asyncio.sleep(.1, loop=loop) assert plm.sentmessage == '02632280' yield from asyncio.sleep(.1, loop=loop) msg = X10Send(0x22, 0x00, 0x06) device.receive_message(msg) yield from asyncio.sleep(.1, loop=loop) # Send Off command and test both commands sent device.states[0x01].off() yield from asyncio.sleep(.1, loop=loop) assert plm.sentmessage == '02632700' msg = X10Send(0x27, 0x00, 0x06) device.receive_message(msg) yield from asyncio.sleep(.1, loop=loop) assert plm.sentmessage == '02632380' yield from asyncio.sleep(.1, loop=loop) msg = X10Send(0x23, 0x00, 0x06) device.receive_message(msg) yield from asyncio.sleep(.1, loop=loop)
def _register_message_handlers(self): template_all_link_response = AllLinkRecordResponse( None, None, None, None, None, None) template_get_im_info = GetImInfo() template_next_all_link_rec = GetNextAllLinkRecord(acknak=MESSAGE_NAK) template_x10_send = X10Send(None, None, MESSAGE_ACK) template_x10_received = X10Received(None, None) # self._message_callbacks.add( # template_assign_all_link, # self._handle_assign_to_all_link_group) self._message_callbacks.add(template_all_link_response, self._handle_all_link_record_response) self._message_callbacks.add(template_get_im_info, self._handle_get_plm_info) self._message_callbacks.add(template_next_all_link_rec, self._handle_get_next_all_link_record_nak) self._message_callbacks.add(template_x10_send, self._handle_x10_send_receive) self._message_callbacks.add(template_x10_received, self._handle_x10_send_receive)
def run_test(loop): housecode = 'C' # byte 0x02 unitcode = 9 # byte 0x07 newval = 200 steps = round(newval / (255 / 22)) + 1 _LOGGER.info('Steps %d', steps) plm = MockPLM(loop) cb = MockCallbacks() device = X10Dimmable(plm, housecode, unitcode) device.states[0x01].register_updates(cb.callbackmethod1) plm.devices[device.address.id] = device device.states[0x01].set_level(200) for i in range(0, steps): _LOGGER.info('Sending ACK messages') msg = X10Send(0x27, 0x00, 0x06) device.receive_message(msg) yield from asyncio.sleep(.1, loop=loop) yield from asyncio.sleep(.1, loop=loop) msg = X10Send(0x25, 0x80, 0x06) _LOGGER.info('New value: 0x%02x', cb.callbackvalue1) assert cb.callbackvalue1 == round((steps - 1) * (255 / 22))
def test_x10send(): """Test X10Send.""" rawX10 = 0x11 flag = 0x22 ack = 0x06 nak = 0x15 msg = X10Send(rawX10, flag) assert msg.hex == hexmsg(0x02, 0x63, rawX10, flag) assert not msg.isack assert not msg.isnak assert len(msg.hex) / 2 == msg.sendSize msg = X10Send(rawX10, flag, ack) assert msg.hex == hexmsg(0x02, 0x63, rawX10, flag, ack) assert msg.isack assert not msg.isnak assert len(msg.hex) / 2 == msg.receivedSize msg = X10Send(rawX10, flag, nak) assert msg.hex == hexmsg(0x02, 0x63, rawX10, flag, nak) assert not msg.isack assert msg.isnak assert len(msg.hex) / 2 == msg.receivedSize
def _register_message_handlers(self): template_assign_all_link = StandardReceive.template( commandtuple=COMMAND_ASSIGN_TO_ALL_LINK_GROUP_0X01_NONE) template_all_link_response = AllLinkRecordResponse(None, None, None, None, None, None) template_get_im_info = GetImInfo() template_next_all_link_rec = GetNextAllLinkRecord(acknak=MESSAGE_NAK) template_all_link_complete = AllLinkComplete(None, None, None, None, None, None) template_x10_send = X10Send(None, None, MESSAGE_ACK) template_x10_received = X10Received(None, None) self._message_callbacks.add( template_assign_all_link, self._handle_assign_to_all_link_group) self._message_callbacks.add( template_all_link_response, self._handle_all_link_record_response) self._message_callbacks.add( template_get_im_info, self._handle_get_plm_info) self._message_callbacks.add( template_next_all_link_rec, self._handle_get_next_all_link_record_nak) self._message_callbacks.add( template_all_link_complete, self._handle_assign_to_all_link_group) self._message_callbacks.add( template_x10_send, self._handle_x10_send_receive) self._message_callbacks.add( template_x10_received, self._handle_x10_send_receive)