def parse_m_message(self, message): logger.debug('Parsing m_message: ' + message) data = bytearray(base64.b64decode(message[2:].split(',')[2])) num_rooms = data[2] pos = 3 for _ in range(0, num_rooms): room_id = struct.unpack('bb', data[pos:pos + 2])[0] name_length = struct.unpack('bb', data[pos:pos + 2])[1] pos += 1 + 1 name = data[pos:pos + name_length].decode('utf-8') pos += name_length device_rf_address = ''.join("%X" % x for x in data[pos:pos + 3]) pos += 3 room = MaxRoom() room.id = room_id room.name = name room.rf_address = device_rf_address self.rooms.append(room) num_devices = data[pos] pos += 1 for device_idx in range(0, num_devices): device_type = data[pos] device_rf_address = ''.join("%X" % x for x in data[pos + 1:pos + 1 + 3]) device_name_length = data[pos + 14] device_name = data[pos + 15:pos + 15 + device_name_length].decode('utf-8') room_id = data[pos + 15 + device_name_length] device = self.device_by_rf(device_rf_address) if not device: if device_type == MAX_THERMOSTAT or device_type == MAX_THERMOSTAT_PLUS: device = MaxThermostat() if device: self.devices.append(device) if device: device.cube = self device.type = device_type device.type_name = MAX_DEVICES[device_type] device.rf_address = device_rf_address device.room_id = room_id device.name = device_name pos += 1 + 3 + 10 + device_name_length + 2
def parse_m_message(self, message): logger.debug('Parsing m_message: ' + message) data = bytearray(base64.b64decode(message[2:].split(',')[2])) num_rooms = data[2] pos = 3 for _ in range(0, num_rooms): room_id = tuple(data[pos:pos + 2])[0] name_length = tuple(data[pos:pos + 2])[1] pos += 1 + 1 name = data[pos:pos + name_length].decode('utf-8') pos += name_length device_rf_address = self.parse_rf_address(data[pos:pos + 3]) pos += 3 room = MaxRoom() room.id = room_id room.room_id = room_id room.name = name room.rf_address = device_rf_address self.rooms.append(room) self.devices.append(room) num_devices = data[pos] pos += 1 for device_idx in range(0, num_devices): device_type = data[pos] device_rf_address = self.parse_rf_address(data[pos + 1:pos + 1 + 3]) device_serial = data[pos + 4:pos + 14].decode('utf-8') device_name_length = data[pos + 14] device_name = data[pos + 15:pos + 15 + device_name_length].decode('utf-8') room_id = data[pos + 15 + device_name_length] device = self.device_by_rf(device_rf_address) if device and device.is_room(): device = None if not device: if device_type == MAX_THERMOSTAT or device_type == MAX_THERMOSTAT_PLUS: device = MaxThermostat() if device_type == MAX_WINDOW_SHUTTER: device = MaxWindowShutter() if device_type == MAX_WALL_THERMOSTAT: device = MaxWallThermostat() if device: self.devices.append(device) if device: device.type = device_type device.rf_address = device_rf_address device.room_id = room_id device.name = device_name device.serial = device_serial pos += 1 + 3 + 10 + device_name_length + 2