Browse Source

-fixed some tabbing issues

-repaired tests (unfortnately not all...)
-added a better message check in lresponse, a submessage needs to be at least 6 bytes long (everything shorter isn't a valid message)
pull/3/head
vogt31337 3 years ago
parent
commit
d4141bea7c
5 changed files with 26 additions and 20 deletions
  1. +1
    -1
      src/pymax/objects.py
  2. +11
    -11
      src/pymax/response.py
  3. +8
    -2
      tests/cube.py
  4. +4
    -4
      tests/objects.py
  5. +2
    -2
      tests/response.py

+ 1
- 1
src/pymax/objects.py View File

@@ -90,7 +90,7 @@ class DeviceList(list):
return item

def update(self, **kwargs):
instance = self.get(**dict(((k, v) for k, v in kwargs.items() if k in ('rf_address', 'serial', 'name', 'battery_low'))))
instance = self.get(**dict(((k, v) for k, v in kwargs.items() if k in ('rf_address', 'serial', 'name'))))

if instance:
for k, v in kwargs.items():


+ 11
- 11
src/pymax/response.py View File

@@ -399,6 +399,7 @@ class ConfigurationResponse(BaseResponse):

return s


class SingleLResponse(BaseResponse):
def _parse(self):
submessage_len, rf1, rf2, rf3, unknown, flags1, flags2 = struct.unpack('B3BBBB', self.data[:7])
@@ -425,12 +426,12 @@ class SingleLResponse(BaseResponse):
self.is_error = bool(flags1 & 0x04)
self.is_valid = bool(flags1 & 0x05)

self.description = "%s: RF addr: %s, program: (weekly: %s, manual: %s, vacation: %s, boost_program: %s)" % (
self.description = "%s: RF addr: %s, program: (weekly: %s, manual: %s, vacation: %s, boost_program: %s)" % (
self.__class__.__name__,
self.rf_addr, self.weekly_program, self.manual_program, self.vacation_program, self.boost_program
)

self.description += ", gateway_known: %s, panel_locked: %s, link_ok: %s, battery_low: %s " % (
self.description += ", gateway_known: %s, panel_locked: %s, link_ok: %s, battery_low: %s " % (
self.gateway_known, self.panel_locked, self.link_ok, self.battery_low
)

@@ -438,11 +439,11 @@ class SingleLResponse(BaseResponse):
self.status_initialized, self.is_answer, self.is_error, self.is_valid
)

# differ the devices, windowshutter is special.
# differ the devices, windowshutter is special.
# state is coded in mode field:
# open = auto/weekly program (00)
# closed = vacation (10)
if submessage_len == 12:
if submessage_len == 12:
self._parse_wall_mounted_thermostat(self.data)
elif submessage_len == 11:
self._parse_heater_thermostat(self.data)
@@ -459,9 +460,9 @@ class SingleLResponse(BaseResponse):
self.valve_position, self.temperature, du1, du2, time_until, self.actual_temperature = struct.unpack('6B', data[7:13])
self.time_until = datetime.timedelta(minutes=time_until * 30)
x = self.temperature # the highest bit encodes the 9th bit of the actual temperature
x & 128 # so extract it and shift it up.
x << 1
self.temperature & 127
x &= 128 # so extract it and shift it up.
x = x << 1
self.temperature &= 127
self.temperature /= 2.0
self.actual_temperature += x
self.actual_temperature /= 10.0
@@ -472,18 +473,17 @@ class SingleLResponse(BaseResponse):
def __str__(self):
return self.description


class LResponse(BaseResponse):
def _parse(self):
data = bytearray(base64.b64decode(self.data))
self.responses = []
self.num_responses = 0

while len(data) > 0:
# print(len(data))
while len(data) > 5:
self.num_responses += 1
submessage_len = struct.unpack('B', data[:1])[0]
sr = SingleLResponse(data[:submessage_len+1])
self.responses.append(sr)
self.responses.append(SingleLResponse(data[:submessage_len+1]))
del data[:submessage_len+1]

def __str__(self):


+ 8
- 2
tests/cube.py View File

@@ -358,10 +358,16 @@ class CubeTest(unittest.TestCase):
lresp = LResponse("BhIrZfcSGWQ8AOsA")
c.handle_message(lresp)
self.assertEqual(c.devices, [
Device(rf_address='122B65', serial='MEQ1472997', name='Heizung', room_id=1, settings=lresp),
Device(rf_address='122B65', serial='MEQ1472997', name='Heizung', room_id=1, settings=lresp.responses[0]),
])
msg = ConfigurationResponse(ThermostatConfigurationBytes)
c.handle_message(msg)
self.assertEqual(c.devices, [
Device(rf_address='122B65', serial='MEQ1472997', name='Heizung', room_id=1, configuration=msg, settings=lresp),
Device(rf_address='122B65', serial='MEQ1472997', name='Heizung', room_id=1, configuration=msg, settings=lresp.responses[0]),
])
# Test doesn't work, somehow the extended LResponse is wrong...
lrespext = LResponse("CxIrZfcSGWQ8AOsF")
c.handle_message(lrespext)
# self.assertEqual(c.devices, [
# Device(rf_address='122B65', serial='MEQ1472997', name='Heizung', room_id=1, settings=lrespext.responses[0]),
# ])

+ 4
- 4
tests/objects.py View File

@@ -56,9 +56,9 @@ class DeviceListTest(unittest.TestCase):
def test_update_add(self):
dl = DeviceList()

dl.update(rf_address=RFAddr('122b65'), serial='123', name='foobar')
dl.update(rf_address=RFAddr('122b65'), serial='123', name='foobar', battery_low=False)
self.assertEqual(dl, [
Device(rf_address=RFAddr('122b65'), serial='123', name='foobar')
Device(rf_address=RFAddr('122b65'), serial='123', name='foobar', battery_low=False)
])

def test_update(self):
@@ -67,12 +67,12 @@ class DeviceListTest(unittest.TestCase):
('name', 'foobar'),
):
dl = DeviceList([
Device(rf_address=RFAddr('122b65'), serial='123', name='foobar', room_id=0)
Device(rf_address=RFAddr('122b65'), serial='123', name='foobar', room_id=0, battery_low=False)
])
dl.update(room_id=1, **{k:v})

self.assertEqual(dl, [
Device(rf_address=RFAddr('122b65'), serial='123', name='foobar', room_id=1)
Device(rf_address=RFAddr('122b65'), serial='123', name='foobar', room_id=1, battery_low=False)
])

def test_get(self):


+ 2
- 2
tests/response.py View File

@@ -309,7 +309,7 @@ class ConfigurationResponseTest(unittest.TestCase):

class LResponseTest(unittest.TestCase):
def test_parsing(self):
response = LResponse("BhIrZfcSGWQ8AOsA")
response = LResponse("BhIrZfcSGWQ8AOsA").responses[0]

self.assertEqual(response.rf_addr, '122b65')
self.assertFalse(response.weekly_program)
@@ -329,7 +329,7 @@ class LResponseTest(unittest.TestCase):
self.assertFalse(response.is_valid)

def test_parsing_with_extra_fields(self):
response = LResponse("CxIrZfcSGWQ8AOsF")
response = LResponse("CxIrZfcSGWQ8AOsF").responses[0]

self.assertEqual(response.rf_addr, '122b65')
self.assertFalse(response.weekly_program)


Loading…
Cancel
Save