diff --git a/src/pymax/cube.py b/src/pymax/cube.py index a8f302c..c733b0c 100644 --- a/src/pymax/cube.py +++ b/src/pymax/cube.py @@ -7,7 +7,7 @@ from pymax.messages import QuitMessage, FMessage, SetTemperatureAndModeMessage, SetProgramMessage, \ SetTemperaturesMessage, SetValveConfigMessage -from pymax.objects import DeviceList, Device +from pymax.objects import DeviceList, Device, RFAddr from pymax.response import DiscoveryIdentifyResponse, DiscoveryNetworkConfigurationResponse, HelloResponse, MResponse, \ HELLO_RESPONSE, M_RESPONSE, MultiPartResponses, CONFIGURATION_RESPONSE, ConfigurationResponse, L_RESPONSE, LResponse, \ F_RESPONSE, FResponse, SET_RESPONSE, SetResponse @@ -189,8 +189,12 @@ def disconnect(self): self.connection.disconnect() def handle_message(self, msg): - #if isinstance(msg, LResponse): - # self.devices.update + if isinstance(msg, MResponse): + for idx, device_type, rf_address, serial, name, room_id in msg.devices: + self.devices.update(rf_address=rf_address, serial=serial, name=name, room_id=room_id) + elif isinstance(msg, ConfigurationResponse): + pass + logger.info("Handle message: %s" % msg) @property @@ -207,7 +211,6 @@ def rooms(self): if msg: return [ Room(*room_data, devices=[ - #type=device_data[1] Device(rf_address=device_data[2], serial=device_data[3], name=device_data[4]) for device_data in filter(lambda x: x[5] == room_data[0], msg.devices) ]) for room_data in msg.rooms ] diff --git a/src/pymax/objects.py b/src/pymax/objects.py index a28a44a..98e4381 100644 --- a/src/pymax/objects.py +++ b/src/pymax/objects.py @@ -99,7 +99,6 @@ def __getattr__(self, item): if item in self: return self[item] raise AttributeError("%s has no attribute %s" % (self.__class__.__name__, item)) - #return super(Device, self).__getattr__(item) def __eq__(self, other): if isinstance(other, dict) or isinstance(other, Device): diff --git a/src/pymax/response.py b/src/pymax/response.py index aeb3287..b1cc1fe 100644 --- a/src/pymax/response.py +++ b/src/pymax/response.py @@ -3,7 +3,7 @@ import struct -from pymax.objects import ProgramSchedule +from pymax.objects import ProgramSchedule, RFAddr from pymax.util import Debugger, unpack_temp_and_time import datetime import logging @@ -89,7 +89,7 @@ def _parse(self): self.serial = self.data[8:18].decode('utf-8') self.request_id = chr(self.data[18]) self.request_type = chr(self.data[19]) - self.rf_address = ''.join("%02x" % x for x in self.data[21:24]) + self.rf_address = RFAddr(self.data[21:24]) self.fw_version = ''.join("%02x" % x for x in self.data[24:26]) def __str__(self): @@ -120,7 +120,7 @@ class HelloResponse(BaseResponse): def _parse(self): parts = tuple(self.data.split(b',')) self.serial = parts[0].decode('utf-8') - self.rf_address = parts[1].decode('utf-8') + self.rf_address = RFAddr(parts[1].decode('utf-8')) self.fw_version = parts[2].decode('utf-8') # unknown = parts[3] self.http_connection_id = parts[4] @@ -168,7 +168,7 @@ def _parse(self): for _ in range(0, self.num_rooms): room_id, name_length = struct.unpack('bb', data[pos:pos+2]) room_name = data[pos + 2:pos + 2 + name_length].decode('utf-8') - group_rf_address = ''.join("%X" % x for x in data[pos+name_length + 2 : pos+name_length + 2 + 3]) + group_rf_address = RFAddr(data[pos+name_length + 2 : pos+name_length + 2 + 3]) logger.debug("Room ID: %s, Room Name: %s, Group RF address: %s" % (room_id, room_name, group_rf_address)) self.rooms.append((room_id, room_name, group_rf_address)) # set pos to start of next section @@ -181,7 +181,7 @@ def _parse(self): for device_idx in range(0, self.num_devices): device_type = data[pos] - device_rf_address = ''.join("%X" % x for x in data[pos+1 : pos+1 + 3]) + device_rf_address = RFAddr(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') @@ -208,7 +208,7 @@ def _parse(self): data_length = data[0] logger.debug("Data length for device config: %s" % data_length) - self.device_addr = ''.join("%X" % x for x in data[1:4]) + self.device_addr = RFAddr(data[1:4]) self.device_type, self.room_id, self.firmware_version, self.test_result = struct.unpack('bbbb', data[4:8]) self.serial_number = data[8:17].decode('utf-8') @@ -347,7 +347,7 @@ class LResponse(BaseResponse): def _parse(self): data = bytearray(base64.b64decode(self.data)) submessage_len, rf1, rf2, rf3, unknown, flags1, flags2 = struct.unpack('B3BBBB', bytearray(data[:7])) - self.rf_addr = "{0:02x}{1:02x}{2:02x}".format(rf1, rf2, rf3) + self.rf_addr = RFAddr((rf1, rf2, rf3)) self.weekly_program = not (flags2 & 0x01 or flags2 & 0x02) self.manual_program = bool(flags2 & 0x01 and not flags2 & 0x02)