From 166af43277f9783cee8d1660d4799d0ca8a6c90a Mon Sep 17 00:00:00 2001 From: Aaron Godfrey Date: Tue, 2 Jul 2019 14:53:20 -0700 Subject: [PATCH] Fixes the ReferenceValue type. This type is a reference to another key at the root of the data. Prior to this PR we were just storing the name and not the value that the reference pointed to. --- tests/test_client.py | 14 +++++++++++++- tests/{test_simple.py => test_core.py} | 0 wideq/client.py | 5 ++++- 3 files changed, 17 insertions(+), 2 deletions(-) rename tests/{test_simple.py => test_core.py} (100%) diff --git a/tests/test_client.py b/tests/test_client.py index 5d10eb0..21b8836 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -68,6 +68,18 @@ DATA = { }, 'Unexpected': {'type': 'Unexpected'}, }, + 'Course': { + "3": { + "_comment": "Normal", + "courseType": "Course", + "id": 3, + "name": "@WM_DRY27_COURSE_NORMAL_W", + "script": "", + "controlEnable": True, + "freshcareEnable": True, + "imgIndex": 61, + }, + }, } @@ -101,7 +113,7 @@ class ModelInfoTest(unittest.TestCase): def test_value_reference(self): actual = self.model_info.value('Course') - expected = ReferenceValue('Course') + expected = ReferenceValue(DATA['Course']) self.assertEqual(expected, actual) def test_value_unsupported(self): diff --git a/tests/test_simple.py b/tests/test_core.py similarity index 100% rename from tests/test_simple.py rename to tests/test_core.py diff --git a/wideq/client.py b/wideq/client.py index 4b1be67..2a5fa66 100644 --- a/wideq/client.py +++ b/wideq/client.py @@ -296,6 +296,8 @@ class DeviceInfo(object): BitValue = namedtuple('BitValue', ['options']) EnumValue = namedtuple('EnumValue', ['options']) RangeValue = namedtuple('RangeValue', ['min', 'max', 'step']) +#: This is a value that is a reference to another key in the data that is at +#: the same level as the `Value` key. ReferenceValue = namedtuple('ReferenceValue', ['reference']) @@ -326,7 +328,8 @@ class ModelInfo(object): bit_values = {opt['startbit']: opt['value'] for opt in d['option']} return BitValue(bit_values) elif d['type'].lower() == 'reference': - return ReferenceValue(d['option'][0]) + ref = d['option'][0] + return ReferenceValue(self.data[ref]) else: raise ValueError("unsupported value type {}".format(d['type']))