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_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_0x50(self, p_pyhouse_obj, p_device_obj, p_controller_obj): """ @param p_device_obj: is the Device (GDO, Motion...) we are decoding. 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 = SensorMessage(p_device_obj.Name, p_device_obj.RoomName, 'Generic ') l_topic = 'houe/security/' l_mqtt_msg = 'security ' if p_device_obj.DeviceSubType == 'GarageDoorOpener': l_mqtt_msg += 'Garage Door: ' l_device.Type = 'Garage Door' l_topic += 'garage_door' elif p_device_obj.DeviceSubType == 'MotionDetector': l_mqtt_msg += 'Motion Sensor: ' l_device.Type = 'Motion Sensor' l_topic += 'motion_sensor' # l_firmware = l_message[7] l_flags = utilDecode._decode_insteon_message_flag(l_message[8]) l_cmd1 = l_message[9] l_cmd2 = l_message[10] l_data = [l_cmd1, l_cmd2] l_mqtt_msg += 'Fm:"{}"; Flg:{}; C1:{:#x},{:#x}; '.format( p_device_obj.Name, l_flags, l_cmd1, l_cmd2) if l_message[8] & 0xE0 == 0x80: # 100 - SB [Broadcast] l_mqtt_msg += utilDecode._devcat(l_message[5:7], p_device_obj) elif l_message[ 8] & 0xE0 == 0xC0: # 110 - SA Broadcast = all link broadcast of group id l_group = l_message[7] l_mqtt_msg += 'A-L-brdcst-Gp:"{}","{}"; '.format(l_group, l_data) if l_cmd1 == MESSAGE_TYPES['cleanup_success']: # 0x06 l_mqtt_msg += 'CleanupSuccess with {} failures; '.format(l_cmd2) elif l_cmd1 == MESSAGE_TYPES['engine_version']: # 0x0D p_device_obj.EngineVersion = l_cmd2 l_mqtt_msg += 'Engine-version:"{}"; '.format(l_cmd2) elif l_cmd1 == MESSAGE_TYPES['id_request']: # 0x10 p_device_obj.FirmwareVersion = l_firmware l_mqtt_msg += 'Request-ID-From:"{}"; '.format(p_device_obj.Name) elif l_cmd1 == MESSAGE_TYPES['on']: # 0x11 if p_device_obj.DeviceSubType == 'GarageDoorOpener': # The status turns on when the Garage Door goes closed l_mqtt_msg += 'Garage Door Closed; '.format(p_device_obj.Name) p_device_obj.Status = 'Close' l_device.Status = 'Garage Door Closed.' elif p_device_obj.DeviceSubType == 'MotionDetector': l_mqtt_msg += 'Motion Detected; '.format(p_device_obj.Name) l_device.Status = 'Motion Detected.' else: l_mqtt_msg += 'Unknown SubType {} for Device; '.format( p_device_obj.DeviceSubType, p_device_obj.Name) if ((l_message[8] & 0xE0) >> 5) == 6: p_pyhouse_obj._APIs.Core.MqttAPI.MqttPublish( l_topic, l_device) # /security elif l_cmd1 == MESSAGE_TYPES['off']: # 0x13 if p_device_obj.DeviceSubType == 'GarageDoorOpener': l_mqtt_msg += 'Garage Door Opened; '.format(p_device_obj.Name) p_device_obj.Status = 'Opened' l_device.Status = 'Garage Door Opened.' elif p_device_obj.DeviceSubType == 'MotionDetector': l_mqtt_msg += 'NO Motion; '.format(p_device_obj.Name) l_device.Status = 'Motion Stopped.' else: l_mqtt_msg += 'Unknown SubType {} for Device; '.format( p_device_obj.DeviceSubType, p_device_obj.Name) if ((l_message[8] & 0xE0) >> 5) == 6: p_pyhouse_obj._APIs.Core.MqttAPI.MqttPublish( l_topic, l_device) # /security LOG.info('Security {}'.format(l_mqtt_msg)) insteon_utils.update_insteon_obj(p_pyhouse_obj, p_device_obj) return
def decode_0x50(self, p_pyhouse_obj, p_controller_obj, p_device_obj): """ There are 2 types of responses here. One is from a request for information from the light type device. The other is a change of status from a light type device. @param p_controller_obj: is the controller that received the message @param p_device_obj: is 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_mqtt_publish = False p_device_obj.BrightnessPct = '?' p_device_obj.ControllerNode = p_pyhouse_obj.Computer.Name p_device_obj.ControllerName = p_controller_obj.Name l_flags = utilDecode._decode_insteon_message_flag(l_message[8]) l_cmd1 = l_message[9] l_cmd2 = l_message[10] l_data = [l_cmd1, l_cmd2] l_debug_msg = 'Fm:"{}"; Flg:{}; C1:{:#x},{:#x}; '.format( p_device_obj.Name, l_flags, l_cmd1, l_cmd2) # # Break down bits 7(msb), 6, 5 into message type # if l_message[8] & 0xE0 == 0x80: # 100 - SB [Broadcast] l_debug_msg += utilDecode._devcat(l_message[5:7], p_device_obj) elif l_message[ 8] & 0xE0 == 0xC0: # 110 - SA Broadcast = all link broadcast of group id l_group = l_message[7] l_debug_msg += 'A-L-brdcst-Gp:"{}","{}"; '.format(l_group, l_data) try: # Query responses if l_cmd1 == MESSAGE_TYPES[ 'assign_to_group'] and l_message[8] & 0xE0 == 0x80: # 0x01 l_debug_msg += ' Device-Set-Button-Pressed ' elif l_cmd1 == MESSAGE_TYPES['delete_from_group'] and l_message[ 8] & 0xE0 == 0x80: # 0x02 l_debug_msg += ' Controller-Set-Button-Pressed ' elif l_cmd1 == MESSAGE_TYPES['product_data_request']: # 0x03 l_debug_msg += " Product-data-request." elif l_cmd1 == MESSAGE_TYPES['cleanup_success']: # 0x06 l_debug_msg += 'CleanupSuccess with {} failures; '.format( l_cmd2) elif l_cmd1 == MESSAGE_TYPES['engine_version']: # 0x0D p_device_obj.EngineVersion = l_cmd2 l_debug_msg += 'Engine-version:"{}(i-{})"; '.format( l_cmd2, l_cmd2 + 1) elif l_cmd1 == MESSAGE_TYPES['id_request']: # 0x10 p_device_obj.FirmwareVersion = l_cmd2 l_debug_msg += 'Request-ID:"{}"; '.format( p_device_obj.FirmwareVersion) elif l_cmd1 == MESSAGE_TYPES['on']: # 0x11 p_device_obj.BrightnessPct = 100 l_mqtt_publish = True l_debug_msg += 'Turn ON; '.format(p_device_obj.Name) elif l_cmd1 == MESSAGE_TYPES['off']: # 0x13 p_device_obj.BrightnessPct = 0 l_mqtt_publish = True l_debug_msg += 'Turn OFF; '.format(p_device_obj.Name) elif l_cmd1 == MESSAGE_TYPES['status_request']: # 0x19 p_device_obj.BrightnessPct = l_level = utilDecode.decode_insteon_light_brightness( l_cmd2) l_mqtt_publish = True l_debug_msg += 'Status of light:"{}"-level:"{}"; '.format( p_device_obj.Name, l_level) else: l_debug_msg += '\n\tUnknown-type:{} - "{}"; '.format( l_cmd1, FormatBytes(l_message)) p_device_obj.BrightnessPct = utilDecode.decode_insteon_light_brightness( l_cmd2) l_mqtt_publish = True except AttributeError as e_err: LOG.error('ERROR decoding 0x50 record {}'.format(e_err)) insteon_utils.update_insteon_obj(p_pyhouse_obj, p_device_obj) p_controller_obj.Ret = True LOG.debug('Light Response {}'.format(l_debug_msg)) LOG.info('Light: {}, Brightness: {}'.format( p_device_obj.Name, p_device_obj.BrightnessPct)) if l_mqtt_publish: l_topic = 'house/lighting/light/status' p_pyhouse_obj._APIs.Core.MqttAPI.MqttPublish(l_topic, p_device_obj) pass return l_debug_msg