1
0
mirror of https://github.com/no2chem/wideq.git synced 2025-05-18 16:20:20 -07:00

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.
This commit is contained in:
Aaron Godfrey 2019-07-02 14:53:20 -07:00
parent 1e8e51c334
commit 166af43277
3 changed files with 17 additions and 2 deletions

View File

@ -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):

View File

@ -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']))