def test_message_callback_extended(): """Test message callback extended.""" callbacks = MessageCallback() callbacktest = "test callback" address = '1a2b3c' target = '4d5e6f' template_ext_on = ExtendedReceive.template( commandtuple=COMMAND_LIGHT_ON_0X11_NONE, userdata=Userdata({'d1': 0x02})) callbacks.add(template_ext_on, callbacktest) msg1 = ExtendedReceive(address, target, COMMAND_LIGHT_ON_0X11_NONE, Userdata({'d1': 0x02}), cmd2=0xff) msg2 = ExtendedReceive(address, target, COMMAND_LIGHT_ON_0X11_NONE, Userdata({ 'd1': 0x03, 'd2': 0x02 }), cmd2=0xff) callback1 = callbacks.get_callbacks_from_message(msg1) callback2 = callbacks.get_callbacks_from_message(msg2) assert callback1[0] == callbacktest assert not callback2
def _register_messages(self): mode_status_msg = StandardReceive.template( commandtuple=COMMAND_THERMOSTAT_MODE_STATUS_0X70_NONE, address=self._address, flags=MessageFlags.template(MESSAGE_TYPE_DIRECT_MESSAGE, None), ) mode_change_fan_on_ack = StandardReceive.template( commandtuple=COMMAND_THERMOSTAT_CONTROL_ON_FAN_0X6B_0X07, address=self._address, flags=MessageFlags.template(MESSAGE_TYPE_DIRECT_MESSAGE_ACK), ) mode_change_fan_auto_ack = StandardReceive.template( commandtuple=COMMAND_THERMOSTAT_CONTROL_OFF_FAN_0X6B_0X08, address=self._address, flags=MessageFlags.template(MESSAGE_TYPE_DIRECT_MESSAGE_ACK), ) mode_change_off_ack = StandardReceive.template( commandtuple=COMMAND_THERMOSTAT_CONTROL_OFF_ALL_0X6B_0X09, address=self._address, flags=MessageFlags.template(MESSAGE_TYPE_DIRECT_MESSAGE_ACK), ) ext_status_recd = ExtendedReceive.template( commandtuple=COMMAND_EXTENDED_GET_SET_0X2E_0X00, cmd2=0x02, userdata=Userdata.template({"d1": 0x01}), ) self._message_callbacks.add(mode_status_msg, self._status_received) self._message_callbacks.add(mode_change_fan_on_ack, self._mode_change_ack) self._message_callbacks.add(mode_change_fan_auto_ack, self._mode_change_ack) self._message_callbacks.add(mode_change_off_ack, self._mode_change_ack) self._message_callbacks.add(ext_status_recd, self._ext_status_received)
def test_extendedReceive(): """Test ExtendedReceive.""" address = bytearray([0x11, 0x22, 0x33]) target = bytearray([0x44, 0x55, 0x66]) flags = 0x77 cmd1 = 0x88 cmd2 = 0x99 userdata = {} userdatatest = bytearray() for i in range(1, 15): key = 'd' + str(i) userdata.update({key: 0xe0}) userdatatest.append(0xe0) msg = ExtendedReceive(address, target, { 'cmd1': cmd1, 'cmd2': cmd2 }, userdata, flags=flags) assert msg.hex == hexmsg(0x02, 0x51, Address(address), Address(target), flags, cmd1, cmd2, userdatatest) assert len(msg.hex) / 2 == msg.sendSize assert len(msg.hex) / 2 == msg.receivedSize
def _register_messages(self): ext_msg_aldb_record = ExtendedReceive.template( address=self._address, commandtuple=COMMAND_EXTENDED_READ_WRITE_ALDB_0X2F_0X00, userdata=Userdata.template({'d2': 1}), flags=MessageFlags.template( messageType=MESSAGE_TYPE_DIRECT_MESSAGE, extended=1)) std_msg_pre_nak = StandardReceive.template(flags=MessageFlags.template( messageType=MESSAGE_FLAG_DIRECT_MESSAGE_NAK_0XA0), cmd2=0xfc) ext_msg_pre_nak = ExtendedReceive.template(flags=MessageFlags.template( messageType=MESSAGE_FLAG_DIRECT_MESSAGE_NAK_0XA0), cmd2=0xfc) self._message_callbacks.add(ext_msg_aldb_record, self._handle_aldb_record_received) self._message_callbacks.add(std_msg_pre_nak, self._handle_pre_nak) self._message_callbacks.add(ext_msg_pre_nak, self._handle_pre_nak)
def _register_messages(self): temp_msg = StandardReceive.template( commandtuple=COMMAND_THERMOSTAT_TEMPERATURE_STATUS_0X6E_NONE, address=self._address, flags=MessageFlags.template(MESSAGE_TYPE_DIRECT_MESSAGE, None)) self._message_callbacks.add(temp_msg, self._temp_received) ext_status_recd = ExtendedReceive.template( commandtuple=COMMAND_EXTENDED_GET_SET_0X2E_0X00, cmd2=0x02, userdata=Userdata.template({"d1": 0x01})) self._message_callbacks.add(ext_status_recd, self._ext_status_received)
def _register_messages(self): cool_set_point_status = StandardReceive.template( address=self._address, commandtuple=COMMAND_THERMOSTAT_COOL_SET_POINT_STATUS_0X71_NONE, flags=MessageFlags.template(MESSAGE_TYPE_DIRECT_MESSAGE, False)) self._message_callbacks.add(cool_set_point_status, self._status_message_received) ext_status_recd = ExtendedReceive.template( commandtuple=COMMAND_EXTENDED_GET_SET_0X2E_0X00, cmd2=0x02, userdata=Userdata.template({"d1": 0x01})) self._message_callbacks.add(ext_status_recd, self._ext_status_received)
def _register_messages(self): super()._register_messages() template_status_recd = ExtendedReceive.template( address=self._address, commandtuple=COMMAND_EXTENDED_GET_SET_0X2E_0X00, # flags=MessageFlags.template(MESSAGE_TYPE_DIRECT_MESSAGE, # True), userdata={ 'd1': self._group, 'd2': 0x01 }) self._message_callbacks.add(template_status_recd, self._status_extended_message_received)
def _register_messages(self): _LOGGER.debug('Starting HeatSetPoint register_messages') heat_set_point_status = StandardReceive.template( address=self._address, commandtuple=COMMAND_THERMOSTAT_HEAT_SET_POINT_STATUS_0X72_NONE, flags=MessageFlags.template(MESSAGE_TYPE_DIRECT_MESSAGE, False)) self._message_callbacks.add(heat_set_point_status, self._status_message_received) ext_status_recd = ExtendedReceive.template( commandtuple=COMMAND_EXTENDED_GET_SET_0X2E_0X00, cmd2=0x02, flags=MessageFlags.template(MESSAGE_TYPE_DIRECT_MESSAGE, True), userdata=Userdata.template({"d1": 0x01})) _LOGGER.debug('Reg Ext Status: %s', ext_status_recd) self._message_callbacks.add(ext_status_recd, self._ext_status_received)
async def run_test(loop): mockPLM = MockPLM(loop) linkcode = 0x01 group = 0x00 address = '112233' cat = 0x02 subcat = 0x39 firmware = 0x44 # Create OutletLinc device = insteonplm.devices.create(mockPLM, address, cat, subcat, firmware) # Start the process with an All-Link complete message with # the IM as a controller of Group 0x00 msg = AllLinkComplete(linkcode, group, address, cat, subcat, firmware) device.receive_message(msg) await asyncio.sleep(.1, loop=loop) # The device should start linking based on the groups in # self.states assert mockPLM.sentmessage == StandardSend( device.address, COMMAND_ENTER_LINKING_MODE_0X09_NONE, cmd2=0x01).hex msg = StandardSend(device.address, COMMAND_ENTER_LINKING_MODE_0X09_NONE, cmd2=0x01, acknak=MESSAGE_ACK) device.receive_message(msg) await asyncio.sleep(.1, loop=loop) # Confirm that the link attempt to group 0x01 completed msg = AllLinkComplete(0x00, 0x01, address, cat, subcat, firmware) device.receive_message(msg) await asyncio.sleep(.1, loop=loop) # The device should then start linking to group 0x02 assert mockPLM.sentmessage == StandardSend( device.address, COMMAND_ENTER_LINKING_MODE_0X09_NONE, cmd2=0x02).hex await asyncio.sleep(1, loop=loop) # Confirm that the link attempt to group 0x02 completed msg = AllLinkComplete(0x00, 0x01, address, cat, subcat, firmware) device.receive_message(msg) await asyncio.sleep(.1, loop=loop) # The device will now attempt to read the ALDB msg = ExtendedSend(address, COMMAND_EXTENDED_READ_WRITE_ALDB_0X2F_0X00, userdata=Userdata()) msg.set_checksum() assert mockPLM.sentmessage == msg.hex # Send a dummy ALDB record as a high water mark to end the process msg = ExtendedReceive( address, '111111', commandtuple=COMMAND_EXTENDED_READ_WRITE_ALDB_0X2F_0X00, userdata=Userdata({ 'd1': 0, 'd2': 0x01, 'd3': 0xff, 'd4': 0x77, 'd5': 0, 'd6': 0, 'd7': 0, 'd8': 0, 'd9': 0, 'd10': 0, 'd11': 0, 'd12': 0, 'd13': 0, 'd14': 0x3b })) device.receive_message(msg) await asyncio.sleep(1, loop=loop)