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

Merge pull request #27 from boralyl/bugfix/reference-value

Fixes the ReferenceValue type.
This commit is contained in:
Adrian Sampson 2019-07-02 18:14:54 -04:00 committed by GitHub
commit 3411ba85e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 2 deletions

View File

@ -68,6 +68,18 @@ DATA = {
}, },
'Unexpected': {'type': 'Unexpected'}, '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): def test_value_reference(self):
actual = self.model_info.value('Course') actual = self.model_info.value('Course')
expected = ReferenceValue('Course') expected = ReferenceValue(DATA['Course'])
self.assertEqual(expected, actual) self.assertEqual(expected, actual)
def test_value_unsupported(self): def test_value_unsupported(self):

View File

@ -296,6 +296,8 @@ class DeviceInfo(object):
BitValue = namedtuple('BitValue', ['options']) BitValue = namedtuple('BitValue', ['options'])
EnumValue = namedtuple('EnumValue', ['options']) EnumValue = namedtuple('EnumValue', ['options'])
RangeValue = namedtuple('RangeValue', ['min', 'max', 'step']) 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']) ReferenceValue = namedtuple('ReferenceValue', ['reference'])
@ -326,7 +328,8 @@ class ModelInfo(object):
bit_values = {opt['startbit']: opt['value'] for opt in d['option']} bit_values = {opt['startbit']: opt['value'] for opt in d['option']}
return BitValue(bit_values) return BitValue(bit_values)
elif d['type'].lower() == 'reference': elif d['type'].lower() == 'reference':
return ReferenceValue(d['option'][0]) ref = d['option'][0]
return ReferenceValue(self.data[ref])
else: else:
raise ValueError("unsupported value type {}".format(d['type'])) raise ValueError("unsupported value type {}".format(d['type']))