Example #1
0
    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 = self.parse_rf_address(data[pos:pos + 3])
            pos += 3

            room = MaxRoom()
            room.id = room_id
            room.name = name
            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 = 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 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
Example #2
0
    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
Example #3
0
 def test_devices_by_room_negative(self):
     room = MaxRoom()
     room.id = 3
     devices = self.cube.devices_by_room(room)
     self.assertEqual(0, len(devices))
Example #4
0
 def test_devices_by_room(self):
     room = MaxRoom()
     room.id = 1
     devices = self.cube.devices_by_room(room)
     self.assertEqual(2, len(devices))
 def test_devices_by_room_negative(self, ClassMock):
     self.init(ClassMock, INIT_RESPONSE_2)
     room = MaxRoom()
     room.id = 3
     devices = self.cube.devices_by_room(room)
     self.assertEqual(0, len(devices))
Example #6
0
def room():
    """Create a test MAX! room."""
    r = MaxRoom()
    r.id = 1
    r.name = "TestRoom"
    return r