def _decode_0x51(self, p_controller_obj): """ Insteon Extended Message Received (25 bytes). See p 234(247) of 2009 developers guide. """ l_message = p_controller_obj._Message l_obj_from = utilDecode().get_obj_from_message(self.m_pyhouse_obj, l_message[2:5]) _l_obj_to = utilDecode().get_obj_from_message(self.m_pyhouse_obj, l_message[5:8]) _l_flags = l_message[8] l_cmd1 = l_message[9] l_cmd2 = l_message[10] l_extended = "{:X}.{:X}.{:X}.{:X}.{:X}.{:X}.{:X}.{:X}.{:X}.{:X}.{:X}.{:X}.{:X}.{:X}".format( l_message[11], l_message[12], l_message[13], l_message[14], l_message[15], l_message[16], l_message[17], l_message[18], l_message[19], l_message[20], l_message[21], l_message[22], l_message[23], l_message[24]) if l_cmd1 == 0x03 and l_cmd2 == 0: # Product Data request response l_product_key = self._get_addr_from_message(l_message, 12) l_devcat = l_message[15] * 256 + l_message[16] LOG.info( 'ProdData Fm:"{}"; ProductID:"{}"; DevCat:"{}"; Data:"{}"'. format(l_obj_from.Name, l_product_key, l_devcat, l_extended)) l_obj_from.ProductKey = l_product_key l_obj_from.DevCat = l_devcat p_controller_obj.Ret = True insteon_utils.update_insteon_obj(self.m_pyhouse_obj, l_obj_from) return
def test_01_GetObj(self): """ """ l_msg = MSG_50 # print(FormatBytes(l_msg), 'D2-01-A - Message') _l_ret = utilDecode().get_obj_from_message(self.m_pyhouse_obj, l_msg[2:5])
def _decode_0x50(self, p_controller_obj): """ Insteon Standard Message Received (11 bytes) A Standard-length INSTEON message is received from either a Controller or Responder that you are ALL-Linked to. See p 233(246) of 2009 developers guide. [0] = x02 [1] = 0x50 [2-4] = from address [5-7] = to address / group [8] = message flags [9] = command 1 [10] = command 2 """ l_message = p_controller_obj._Message l_device_obj = utilDecode().get_obj_from_message( self.m_pyhouse_obj, l_message[2:5]) # if l_device_obj.DeviceType == 'Lighting': # Light Type DecodeLight().decode_0x50(self.m_pyhouse_obj, p_controller_obj, l_device_obj) return elif l_device_obj.DeviceType == 'Hvac': # HVAC Type DecodeHvac().decode_0x50(self.m_pyhouse_obj, l_device_obj, p_controller_obj) return elif l_device_obj.DeviceType == 'Security': # Security Type DecodeSecurity().decode_0x50(self.m_pyhouse_obj, l_device_obj, p_controller_obj) return else: LOG.error('Unknown Device Type:{};'.format( l_device_obj.DeviceType)) return
def decode_0x57(p_pyhouse_obj, p_controller_obj): """All-Link Record Response (10 bytes). See p 251(264) of 2009 developers guide. [0] = 0x02 [1] = 0x57 [2] = AllLink Record Flags [3] = AllLink Group [4-6] = from address [7] = Link Data 1 [8] = Link Data 2 [9] = Link Data 3 """ l_message = p_controller_obj._Message l_obj = utilDecode().get_obj_from_message(p_pyhouse_obj, l_message[4:7]) l_link_obj = LinkData() l_link_obj.Flag = l_flags = l_message[2] l_link_obj.Group = l_group = l_message[3] l_link_obj.InsteonAddess = l_obj.InsteonAddress l_link_obj.Data = l_data = [l_message[7], l_message[8], l_message[9]] l_flag_control = l_flags & 0x40 l_type = 'Responder' if l_flag_control != 0: l_type = 'Controller' l_link_obj.IsController = True LOG.info( "All-Link response-0x57 - Group={:#02X}, Name={}, Flags={:#x}, Data={}, {}" .format(l_group, l_obj.Name, l_flags, l_data, l_type)) # Ask for next record Send().queue_0x6A_command(p_controller_obj) return
def _find_to_name(self, p_command): """ Find the device we are sending a message "To" """ l_name = 'No device' try: l_device_obj = utilDecode().get_obj_from_message( self.m_pyhouse_obj, p_command[2:5]) l_name = l_device_obj.Name except Exception: l_name = "Device does not exist." return l_name
def test_02_PutController(self): """ """ _l_controller = self.m_pyhouse_obj.House.Lighting.Controllers[0] # print(PrettyFormatAny.form(l_controller, 'F1-02-A - Controller')) l_addr = INSTEON_1_MSG l_ret = utilDecode().get_obj_from_message(self.m_pyhouse_obj, l_addr) l_ret.Port = PORT_NAME insteon_utils.update_insteon_obj(self.m_pyhouse_obj, l_ret) # print(PrettyFormatAny.form(l_controller, 'F1-02-B - l_ret')) self.assertEqual(self.m_pyhouse_obj.House.Lighting.Controllers[0].Port, PORT_NAME)
def _decode_0x60_record(self, p_controller_obj): """Get Insteon Modem Info (9 bytes). See p 273 of developers guide. """ l_message = p_controller_obj._Message l_obj = utilDecode().get_obj_from_message(self.m_pyhouse_obj, l_message[2:5]) l_devcat = l_message[5] l_devsubcat = l_message[6] l_firmver = l_message[7] LOG.info( "== 60 - Insteon Modem Info - DevCat={}, DevSubCat={}, Firmware={} - Name={}" .format(l_devcat, l_devsubcat, l_firmver, l_obj.Name)) if l_message[8] == ACK: insteon_utils.update_insteon_obj(self.m_pyhouse_obj, l_obj) p_controller_obj.Ret = True else: LOG.error("== 60 - No ACK - Got {:#x}".format(l_message[8])) p_controller_obj.Ret = False return
def _decode_0x62_record(self, p_controller_obj): """Get response to Send Insteon standard-length message (9 bytes). Basically, a response to the 62 command. See p 230(243) of 2009 developers guide. [0] = 0x02 [1] = 0x62 [2-4] = address [5] = message flags [6] = command 1 [7] = command 2 [8] = ACK/NAK [8] = User Data 1 [9] = User Data 2 [10] = User Data 3 [11] = User Data 4 [12] = User Data 5 [13] = User Data 6 [14] = User Data 7 [15] = User Data 8 [16] = User Data 9 [17] = User Data 10 [18] = User Data 11 [19] = User Data 12 [20] = User Data 13 [21] = User Data 14 [22] = ACK/NAK This is an ack/nak of the command and generally is not very interesting by itself. Depending on the command sent, another response MAY follow this message with further data. """ l_message = p_controller_obj._Message l_obj = utilDecode().get_obj_from_message(self.m_pyhouse_obj, l_message[2:5]) _l_msgflags = utilDecode._decode_insteon_message_flag(l_message[5]) l_ack = utilDecode.get_ack_nak(l_message[8]) l_debug_msg = "Device: {}, {}".format(l_obj.Name, l_ack) if l_ack == 'NAK': LOG.info("Got ACK(62); {}".format(l_debug_msg)) return
def decode_0x53(p_pyhouse_obj, p_controller_obj): """Insteon All-Linking completed (10 bytes). See p 247(260) of 2009 developers guide. [0] = 0x02 [1] = 0x53 [2] = LinkCode - 0=PLM is Responder, 1=PLM is Controller, FF=Deleted [3] = LinkGroup [4-6] = from address [7-8] = DevCat [9] = Firmwear Version """ l_message = p_controller_obj._Message l_msg = insteon_utils.decode_link_code(l_message[2]) l_link_group = l_message[3] l_from_id = l_message[4:7] l_device_obj = utilDecode().get_obj_from_message( p_pyhouse_obj, l_from_id) utilDecode._devcat(l_message[7:9], p_controller_obj) _l_version = l_message[9] LOG.info( 'All-Linking completed - Link Code:{}, Group:{}, From:{} '.format( l_msg, l_link_group, l_device_obj.Name))
def _decode_0x6F_record(self, p_controller_obj): """All-Link manage Record Response (12 bytes). See p 252(265) of 2009 developers guide. Modify the IM's All-Link Database (ALDB) with the All-Link data you send. Use caution with this command - the IM does not check the validity of the data you send. [0] = x02 [1] = 0x6F [2] = Control Code [3] = All-Link Record Flag [4] = All Lpink Grou [5-7] = ID [8] = Link Data 1 [9] = Link Data 2 [10] = Link Data 3 [11] = ACK/NAK """ l_message = p_controller_obj._Message l_code = l_message[2] l_flags = l_message[3] l_flag_control = l_flags & 0x40 l_group = l_message[4] l_obj = utilDecode().get_obj_from_message(self.m_pyhouse_obj, l_message[5:8]) l_data = [l_message[8], l_message[9], l_message[10]] l_ack = utilDecode.get_ack_nak(l_message[11]) l_type = 'Responder' if l_flag_control != 0: l_type = 'Controller' l_message = "Manage All-Link response(6F)" l_message += " Group:{:#02X}, Name:{}, Flags:{:#02X}, Data:{}, CtlCode:{:#02x},".format( l_group, l_obj.Name, l_flags, l_data, l_code) l_message += " Ack:{}, Type:{}".format(l_ack, l_type) LOG.info("{}".format(l_message)) p_controller_obj.Ret = True return
def test_01_GetObj(self): """ """ # print(PrettyFormatAny.form(self.m_pyhouse_obj.House.Lighting.Lights[0], 'E1-01-A - Lighting')) l_addr = INSTEON_0_MSG _l_ret = utilDecode().get_obj_from_message(self.m_pyhouse_obj, l_addr)