mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-16 07:10:09 -07:00
Allow strings in ModelInfo
The only instance where this is used is a comment, see issue #62. For now it will just be ignored. The comment seems to contain several times. Fixes #62
This commit is contained in:
parent
d8389f3bee
commit
be05e1b33e
@ -1,7 +1,7 @@
|
||||
import unittest
|
||||
|
||||
from wideq.client import (
|
||||
BitValue, EnumValue, ModelInfo, RangeValue, ReferenceValue)
|
||||
BitValue, EnumValue, ModelInfo, RangeValue, ReferenceValue, StringValue)
|
||||
|
||||
|
||||
DATA = {
|
||||
@ -66,10 +66,15 @@ DATA = {
|
||||
],
|
||||
'type': 'Bit'
|
||||
},
|
||||
'TimeBsOn': {
|
||||
'_comment':
|
||||
'오전 12시 30분은 0030, 오후12시30분은 1230 ,오후 4시30분은 1630 off는 0 ',
|
||||
'type': 'String'
|
||||
},
|
||||
'Unexpected': {'type': 'Unexpected'},
|
||||
'StringOption': {
|
||||
'type': 'String',
|
||||
'option': 'some string'
|
||||
'Unexpected2': {
|
||||
'type': 'Unexpected',
|
||||
'option': 'some option'
|
||||
},
|
||||
},
|
||||
'Course': {
|
||||
@ -120,6 +125,12 @@ class ModelInfoTest(unittest.TestCase):
|
||||
expected = ReferenceValue(DATA['Course'])
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
def test_string(self):
|
||||
actual = self.model_info.value('TimeBsOn')
|
||||
expected = StringValue(
|
||||
"오전 12시 30분은 0030, 오후12시30분은 1230 ,오후 4시30분은 1630 off는 0 ")
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
def test_value_unsupported(self):
|
||||
data = "{'type': 'Unexpected'}"
|
||||
with self.assertRaisesRegex(
|
||||
@ -129,9 +140,9 @@ class ModelInfoTest(unittest.TestCase):
|
||||
self.model_info.value('Unexpected')
|
||||
|
||||
def test_value_unsupported_but_data_available(self):
|
||||
data = "{'type': 'String', 'option': 'some string'}"
|
||||
data = "{'type': 'Unexpected', 'option': 'some option'}"
|
||||
with self.assertRaisesRegex(
|
||||
ValueError,
|
||||
f"unsupported value name: 'StringOption'"
|
||||
f" type: 'String' data: '{data}"):
|
||||
self.model_info.value('StringOption')
|
||||
f"unsupported value name: 'Unexpected2'"
|
||||
f" type: 'Unexpected' data: '{data}"):
|
||||
self.model_info.value('Unexpected2')
|
||||
|
@ -292,6 +292,7 @@ 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'])
|
||||
StringValue = namedtuple('StringValue', ['comment'])
|
||||
|
||||
|
||||
class ModelInfo(object):
|
||||
@ -306,7 +307,7 @@ class ModelInfo(object):
|
||||
|
||||
:param name: The name to look up.
|
||||
:returns: One of (`BitValue`, `EnumValue`, `RangeValue`,
|
||||
`ReferenceValue`).
|
||||
`ReferenceValue`, `StringValue`).
|
||||
:raises ValueError: If an unsupported type is encountered.
|
||||
"""
|
||||
d = self.data['Value'][name]
|
||||
@ -323,6 +324,8 @@ class ModelInfo(object):
|
||||
elif d['type'].lower() == 'reference':
|
||||
ref = d['option'][0]
|
||||
return ReferenceValue(self.data[ref])
|
||||
elif d['type'].lower() == 'string':
|
||||
return StringValue(d.get('_comment', ''))
|
||||
else:
|
||||
raise ValueError(
|
||||
f"unsupported value name: '{name}'"
|
||||
|
Loading…
x
Reference in New Issue
Block a user