Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

miottemplate.py print specs.json fails #906

Closed
syssi opened this issue Jan 10, 2021 · 7 comments · Fixed by #910 or #971
Closed

miottemplate.py print specs.json fails #906

syssi opened this issue Jan 10, 2021 · 7 comments · Fixed by #910 or #971
Labels

Comments

@syssi
Copy link
Collaborator

syssi commented Jan 10, 2021

$ python3 miottemplate.py download zhimi.humidifier.ca4
WARNING more than a single match for model zhimi.humidifier.ca4: ['urn:miot-spec-v2:device:humidifier:0000A00E:zhimi-ca4:1', 'urn:miot-spec-v2:device:humidifier:0000A00E:zhimi-ca4:2']
Saving data to urn:miot-spec-v2:device:humidifier:0000A00E:zhimi-ca4:1.json

$ python3 miottemplate.py print urn\:miot-spec-v2\:device\:humidifier\:0000A00E\:zhimi-ca4\:1.json 
Traceback (most recent call last):
  File "/home/sebastian/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 263, in _decode_generic
    res = _get_type_cons(type_)(xs)
TypeError: 'TypeVar' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sebastian/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 263, in _decode_generic
    res = _get_type_cons(type_)(xs)
  File "/home/sebastian/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 309, in <genexpr>
    items = (_decode_generic(type_arg, x, infer_missing) for x in xs)
  File "/home/sebastian/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 265, in _decode_generic
    res = type_(xs)
  File "/usr/lib/python3.7/typing.py", line 668, in __call__
    raise TypeError(f"Type {self._name} cannot be instantiated; "
TypeError: Type Dict cannot be instantiated; use dict() instead

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sebastian/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 263, in _decode_generic
    res = _get_type_cons(type_)(xs)
  File "/home/sebastian/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 307, in <genexpr>
    for x in xs)
  File "/home/sebastian/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 203, in _decode_dataclass
    infer_missing)
  File "/home/sebastian/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 275, in _decode_generic
    res = _decode_generic(type_arg, value, infer_missing)
  File "/home/sebastian/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 265, in _decode_generic
    res = type_(xs)
  File "/usr/lib/python3.7/typing.py", line 668, in __call__
    raise TypeError(f"Type {self._name} cannot be instantiated; "
TypeError: Type List cannot be instantiated; use list() instead

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sebastian/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 263, in _decode_generic
    res = _get_type_cons(type_)(xs)
  File "/home/sebastian/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 307, in <genexpr>
    for x in xs)
  File "/home/sebastian/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 203, in _decode_dataclass
    infer_missing)
  File "/home/sebastian/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 265, in _decode_generic
    res = type_(xs)
  File "/usr/lib/python3.7/typing.py", line 668, in __call__
    raise TypeError(f"Type {self._name} cannot be instantiated; "
TypeError: Type List cannot be instantiated; use list() instead

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "miottemplate.py", line 153, in <module>
    cli()
  File "/home/sebastian/.local/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/sebastian/.local/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/sebastian/.local/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/sebastian/.local/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/sebastian/.local/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "miottemplate.py", line 92, in print
    gen.print_infos()
  File "miottemplate.py", line 29, in print_infos
    dev = Device.from_json(self.data)
  File "/home/sebastian/.local/lib/python3.7/site-packages/dataclasses_json/api.py", line 76, in from_json
    return cls.from_dict(kvs, infer_missing=infer_missing)
  File "/home/sebastian/.local/lib/python3.7/site-packages/dataclasses_json/api.py", line 83, in from_dict
    return _decode_dataclass(cls, kvs, infer_missing)
  File "/home/sebastian/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 203, in _decode_dataclass
    infer_missing)
  File "/home/sebastian/.local/lib/python3.7/site-packages/dataclasses_json/core.py", line 265, in _decode_generic
    res = type_(xs)
  File "/usr/lib/python3.7/typing.py", line 668, in __call__
    raise TypeError(f"Type {self._name} cannot be instantiated; "
TypeError: Type List cannot be instantiated; use list() instead
@syssi syssi added the bug label Jan 10, 2021
@rytilahti
Copy link
Owner

rytilahti commented Jan 11, 2021

Are you running the current master already? #902 should have fixed the issue with TypeError: Type List cannot be instantiated; use list() instead errors, and this seems to be working fine here (with Python 3.9.1):

$ python3 miottemplate.py download zhimi.humidifier.ca4
WARNING more than a single match for model zhimi.humidifier.ca4: [InstanceInfo(model='zhimi.humidifier.ca4', status='released', type='urn:miot-spec-v2:device:humidifier:0000A00E:zhimi-ca4:1', version=1), InstanceInfo(model='zhimi.humidifier.ca4', status='released', type='urn:miot-spec-v2:device:humidifier:0000A00E:zhimi-ca4:2', version=2)] - using the first one
Saving data to urn:miot-spec-v2:device:humidifier:0000A00E:zhimi-ca4:1.json

$ python3 miottemplate.py print urn:miot-spec-v2:device:humidifier:0000A00E:zhimi-ca4:1.json
Device 'urn:miot-spec-v2:device:humidifier:0000A00E:zhimi-ca4:1': Humidifier with 7 services

* Service siid 1: (Device Information): 4 props, 0 actions

        ## Properties ##
                siid 1: piid: 1 (Device Manufacturer): (string, unit: None) (acc: ['read'])
                siid 1: piid: 2 (Device Model): (string, unit: None) (acc: ['read'])
                siid 1: piid: 3 (Device Serial Number): (string, unit: None) (acc: ['read'])
                siid 1: piid: 4 (Current Firmware Version): (string, unit: None) (acc: ['read'])

* Service siid 2: (Humidifier): 9 props, 0 actions

        ## Properties ##
                siid 2: piid: 1 (Switch Status): (bool, unit: none) (acc: ['read', 'write', 'notify'])
                siid 2: piid: 2 (Device Fault): (uint8, unit: None) (acc: ['read', 'notify'])
                        Range: [0, 15, 1]

@syssi
Copy link
Collaborator Author

syssi commented Jan 11, 2021

Yes. I'm running the current master (python 3.7.3, debian buster).

@rytilahti
Copy link
Owner

Hmm, okay, maybe there are some differences between python versions here.

dataclasses-json is annoying to debug, but the following may help figuring out which part of the structure it is failing: open the dataclasses_json/core.py around 201 and add a print out for the parameters like this, and re-run the script:

          elif _is_supported_generic(field_type) and field_type != str:
#            print("initializing %s with t: %s v: %s, infer: %s" % (field.name, field_type, field_value, infer_missing))

The fix in that PR was to add the necessary types for the containers, but figuring out which class is not being initialized is the first step to figure out how we could fix that for you.

@syssi
Copy link
Collaborator Author

syssi commented Jan 11, 2021

This is the output:

python3 miottemplate.py print urn\:miot-spec-v2\:device\:humidifier\:0000A00E\:zhimi-ca4\:2.json 
initializing services with t: typing.List[containers.Service] v: [{'iid': 1, 'type': 'urn:miot-spec-v2:service:device-information:00007801:zhimi-ca4:1', 'description': 'Device Information', 'properties': [{'iid': 1, 'type': 'urn:miot-spec-v2:property:manufacturer:00000001:zhimi-ca4:1', 'description': 'Device Manufacturer', 'format': 'string', 'access': ['read']}, {'iid': 2, 'type': 'urn:miot-spec-v2:property:model:00000002:zhimi-ca4:1', 'description': 'Device Model', 'format': 'string', 'access': ['read']}, {'iid': 3, 'type': 'urn:miot-spec-v2:property:serial-number:00000003:zhimi-ca4:1', 'description': 'Device Serial Number', 'format': 'string', 'access': ['read']}, {'iid': 4, 'type': 'urn:miot-spec-v2:property:firmware-revision:00000005:zhimi-ca4:1', 'description': 'Current Firmware Version', 'format': 'string', 'access': ['read']}]}, {'iid': 2, 'type': 'urn:miot-spec-v2:service:humidifier:00007818:zhimi-ca4:1', 'description': 'Humidifier', 'properties': [{'iid': 1, 'type': 'urn:miot-spec-v2:property:on:00000006:zhimi-ca4:1', 'description': 'Switch Status', 'format': 'bool', 'access': ['read', 'write', 'notify'], 'unit': 'none'}, {'iid': 2, 'type': 'urn:miot-spec-v2:property:fault:00000009:zhimi-ca4:1', 'description': 'Device Fault', 'format': 'uint8', 'access': ['read', 'notify'], 'value-range': [0, 15, 1]}, {'iid': 5, 'type': 'urn:miot-spec-v2:property:fan-level:00000016:zhimi-ca4:1', 'description': '风机档位', 'format': 'uint8', 'access': ['read', 'write', 'notify'], 'unit': 'none', 'value-list': [{'value': 0, 'description': 'Auto'}, {'value': 1, 'description': 'Level1'}, {'value': 2, 'description': 'Level2'}, {'value': 3, 'description': 'Level3'}]}, {'iid': 6, 'type': 'urn:miot-spec-v2:property:target-humidity:00000022:zhimi-ca4:1', 'description': '设定湿度', 'format': 'uint8', 'access': ['read', 'write', 'notify'], 'unit': 'percentage', 'value-range': [30, 80, 1]}, {'iid': 7, 'type': 'urn:miot-spec-v2:property:water-level:0000003D:zhimi-ca4:1', 'description': 'Water Level', 'format': 'uint8', 'access': ['read', 'notify'], 'value-range': [0, 128, 1]}, {'iid': 11, 'type': 'urn:miot-spec-v2:property:speed-level:00000023:zhimi-ca4:1', 'description': '设定速度', 'format': 'int32', 'access': ['read', 'write', 'notify'], 'unit': 'none', 'value-range': [200, 2000, 10]}, {'iid': 8, 'type': 'urn:zhimi-spec:property:dry:00000001:zhimi-ca4:1', 'description': '', 'format': 'bool', 'access': ['read', 'write', 'notify']}, {'iid': 9, 'type': 'urn:zhimi-spec:property:use-time:00000002:zhimi-ca4:1', 'description': '', 'format': 'int32', 'access': ['read', 'notify'], 'value-range': [0, 2147483600, 1]}, {'iid': 10, 'type': 'urn:zhimi-spec:property:button-pressed:00000003:zhimi-ca4:1', 'description': '按键信息', 'format': 'uint8', 'access': ['read', 'notify'], 'value-list': [{'value': 0, 'description': 'none'}, {'value': 1, 'description': 'led'}, {'value': 2, 'description': 'power'}]}], 'events': [{'iid': 1, 'type': 'urn:miot-spec-v2:event:low-water-level:0000500A:zhimi-ca4:1', 'description': 'Low Water Level', 'arguments': []}]}, {'iid': 3, 'type': 'urn:miot-spec-v2:service:environment:0000780A:zhimi-ca4:1', 'description': 'Environment', 'properties': [{'iid': 7, 'type': 'urn:miot-spec-v2:property:temperature:00000020:zhimi-ca4:1', 'description': '温度', 'format': 'float', 'access': ['read', 'notify'], 'unit': 'celsius', 'value-range': [-40, 125, 0.1]}, {'iid': 9, 'type': 'urn:miot-spec-v2:property:relative-humidity:0000000C:zhimi-ca4:1', 'description': 'Relative Humidity', 'format': 'uint8', 'access': ['read', 'notify'], 'unit': 'percentage', 'value-range': [0, 100, 1]}, {'iid': 8, 'type': 'urn:zhimi-spec:property:fahrenheit:00000001:zhimi-ca4:1', 'description': '', 'format': 'float', 'access': ['read', 'notify'], 'value-range': [-40, 257, 0.1]}]}, {'iid': 4, 'type': 'urn:miot-spec-v2:service:alarm:00007804:zhimi-ca4:1', 'description': 'Alarm', 'properties': [{'iid': 1, 'type': 'urn:miot-spec-v2:property:alarm:00000012:zhimi-ca4:1', 'description': 'Alarm', 'format': 'bool', 'access': ['read', 'write', 'notify']}]}, {'iid': 5, 'type': 'urn:miot-spec-v2:service:screen:00007806:zhimi-ca4:1', 'description': 'Screen', 'properties': [{'iid': 2, 'type': 'urn:miot-spec-v2:property:brightness:0000000D:zhimi-ca4:1', 'description': '亮度', 'format': 'uint8', 'access': ['read', 'write', 'notify'], 'unit': 'percentage', 'value-list': [{'value': 0, 'description': 'Dark'}, {'value': 1, 'description': 'Glimmer'}, {'value': 2, 'description': 'Brightest'}]}]}, {'iid': 6, 'type': 'urn:miot-spec-v2:service:physical-controls-locked:00007807:zhimi-ca4:1', 'description': 'Physical Control Locked', 'properties': [{'iid': 1, 'type': 'urn:miot-spec-v2:property:physical-controls-locked:0000001D:zhimi-ca4:1', 'description': 'Physical Control Locked', 'format': 'bool', 'access': ['read', 'write', 'notify']}]}, {'iid': 7, 'type': 'urn:zhimi-spec:service:other:00007801:zhimi-ca4:1', 'description': '', 'properties': [{'iid': 1, 'type': 'urn:zhimi-spec:property:actual-speed:00000001:zhimi-ca4:1', 'description': '', 'format': 'uint32', 'access': ['read'], 'value-range': [0, 2000, 1]}, {'iid': 3, 'type': 'urn:zhimi-spec:property:power-time:00000003:zhimi-ca4:1', 'description': '', 'format': 'uint32', 'access': ['read'], 'unit': 'seconds', 'value-range': [0, 4294967295, 1]}, {'iid': 4, 'type': 'urn:zhimi-spec:property:country-code:00000002:zhimi-ca4:2', 'description': 'country-code', 'format': 'uint32', 'access': ['read', 'notify', 'write'], 'unit': 'none', 'value-list': [{'value': 0, 'description': '0未知'}, {'value': 1, 'description': 'US美国'}, {'value': 82, 'description': 'KR韩国'}, {'value': 44, 'description': 'EU欧洲'}, {'value': 81, 'description': 'JP日本'}, {'value': 7, 'description': 'RU俄罗斯'}, {'value': 86, 'description': 'CN中国'}, {'value': 852, 'description': 'HK中国香港'}, {'value': 886, 'description': 'TW中国台湾'}, {'value': 33, 'description': 'FR法国'}]}, {'iid': 5, 'type': 'urn:zhimi-spec:property:clean:00000004:zhimi-ca4:2', 'description': 'clean', 'format': 'bool', 'access': ['read', 'notify', 'write'], 'unit': 'none'}], 'events': [{'iid': 1, 'type': 'urn:zhimi-spec:event:status-report:00005001:zhimi-ca4:1', 'description': '聚合上报', 'arguments': [3]}, {'iid': 2, 'type': 'urn:zhimi-spec:event:water-box-off:00005002:zhimi-ca4:1', 'description': '水箱分离', 'arguments': []}, {'iid': 3, 'type': 'urn:zhimi-spec:event:child-lock-trigger:00005003:zhimi-ca4:1', 'description': '童锁上报', 'arguments': []}]}], infer: False
initializing properties with t: typing.List[containers.Property] v: [{'iid': 1, 'type': 'urn:miot-spec-v2:property:manufacturer:00000001:zhimi-ca4:1', 'description': 'Device Manufacturer', 'format': 'string', 'access': ['read']}, {'iid': 2, 'type': 'urn:miot-spec-v2:property:model:00000002:zhimi-ca4:1', 'description': 'Device Model', 'format': 'string', 'access': ['read']}, {'iid': 3, 'type': 'urn:miot-spec-v2:property:serial-number:00000003:zhimi-ca4:1', 'description': 'Device Serial Number', 'format': 'string', 'access': ['read']}, {'iid': 4, 'type': 'urn:miot-spec-v2:property:firmware-revision:00000005:zhimi-ca4:1', 'description': 'Current Firmware Version', 'format': 'string', 'access': ['read']}], infer: False
initializing access with t: typing.List[str] v: ['read'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing access with t: typing.List[str] v: ['read'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing access with t: typing.List[str] v: ['read'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing access with t: typing.List[str] v: ['read'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing actions with t: typing.List[containers.Action] v: [], infer: False
initializing events with t: typing.List[containers.Event] v: [], infer: False
initializing properties with t: typing.List[containers.Property] v: [{'iid': 1, 'type': 'urn:miot-spec-v2:property:on:00000006:zhimi-ca4:1', 'description': 'Switch Status', 'format': 'bool', 'access': ['read', 'write', 'notify'], 'unit': 'none'}, {'iid': 2, 'type': 'urn:miot-spec-v2:property:fault:00000009:zhimi-ca4:1', 'description': 'Device Fault', 'format': 'uint8', 'access': ['read', 'notify'], 'value-range': [0, 15, 1]}, {'iid': 5, 'type': 'urn:miot-spec-v2:property:fan-level:00000016:zhimi-ca4:1', 'description': '风机档位', 'format': 'uint8', 'access': ['read', 'write', 'notify'], 'unit': 'none', 'value-list': [{'value': 0, 'description': 'Auto'}, {'value': 1, 'description': 'Level1'}, {'value': 2, 'description': 'Level2'}, {'value': 3, 'description': 'Level3'}]}, {'iid': 6, 'type': 'urn:miot-spec-v2:property:target-humidity:00000022:zhimi-ca4:1', 'description': '设定湿度', 'format': 'uint8', 'access': ['read', 'write', 'notify'], 'unit': 'percentage', 'value-range': [30, 80, 1]}, {'iid': 7, 'type': 'urn:miot-spec-v2:property:water-level:0000003D:zhimi-ca4:1', 'description': 'Water Level', 'format': 'uint8', 'access': ['read', 'notify'], 'value-range': [0, 128, 1]}, {'iid': 11, 'type': 'urn:miot-spec-v2:property:speed-level:00000023:zhimi-ca4:1', 'description': '设定速度', 'format': 'int32', 'access': ['read', 'write', 'notify'], 'unit': 'none', 'value-range': [200, 2000, 10]}, {'iid': 8, 'type': 'urn:zhimi-spec:property:dry:00000001:zhimi-ca4:1', 'description': '', 'format': 'bool', 'access': ['read', 'write', 'notify']}, {'iid': 9, 'type': 'urn:zhimi-spec:property:use-time:00000002:zhimi-ca4:1', 'description': '', 'format': 'int32', 'access': ['read', 'notify'], 'value-range': [0, 2147483600, 1]}, {'iid': 10, 'type': 'urn:zhimi-spec:property:button-pressed:00000003:zhimi-ca4:1', 'description': '按键信息', 'format': 'uint8', 'access': ['read', 'notify'], 'value-list': [{'value': 0, 'description': 'none'}, {'value': 1, 'description': 'led'}, {'value': 2, 'description': 'power'}]}], infer: False
initializing access with t: typing.List[str] v: ['read', 'write', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: none, infer: False
initializing access with t: typing.List[str] v: ['read', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: [0, 15, 1], infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing access with t: typing.List[str] v: ['read', 'write', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict], NoneType] v: [{'value': 0, 'description': 'Auto'}, {'value': 1, 'description': 'Level1'}, {'value': 2, 'description': 'Level2'}, {'value': 3, 'description': 'Level3'}], infer: False
Traceback (most recent call last):
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/dataclasses_json/core.py", line 264, in _decode_generic
    res = _get_type_cons(type_)(xs)
TypeError: 'TypeVar' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/dataclasses_json/core.py", line 264, in _decode_generic
    res = _get_type_cons(type_)(xs)
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/dataclasses_json/core.py", line 310, in <genexpr>
    items = (_decode_generic(type_arg, x, infer_missing) for x in xs)
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/dataclasses_json/core.py", line 266, in _decode_generic
    res = type_(xs)
  File "/usr/lib/python3.7/typing.py", line 668, in __call__
    raise TypeError(f"Type {self._name} cannot be instantiated; "
TypeError: Type Dict cannot be instantiated; use dict() instead

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/dataclasses_json/core.py", line 264, in _decode_generic
    res = _get_type_cons(type_)(xs)
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/dataclasses_json/core.py", line 308, in <genexpr>
    for x in xs)
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/dataclasses_json/core.py", line 204, in _decode_dataclass
    infer_missing)
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/dataclasses_json/core.py", line 276, in _decode_generic
    res = _decode_generic(type_arg, value, infer_missing)
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/dataclasses_json/core.py", line 266, in _decode_generic
    res = type_(xs)
  File "/usr/lib/python3.7/typing.py", line 668, in __call__
    raise TypeError(f"Type {self._name} cannot be instantiated; "
TypeError: Type List cannot be instantiated; use list() instead

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/dataclasses_json/core.py", line 264, in _decode_generic
    res = _get_type_cons(type_)(xs)
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/dataclasses_json/core.py", line 308, in <genexpr>
    for x in xs)
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/dataclasses_json/core.py", line 204, in _decode_dataclass
    infer_missing)
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/dataclasses_json/core.py", line 266, in _decode_generic
    res = type_(xs)
  File "/usr/lib/python3.7/typing.py", line 668, in __call__
    raise TypeError(f"Type {self._name} cannot be instantiated; "
TypeError: Type List cannot be instantiated; use list() instead

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "miottemplate.py", line 153, in <module>
    cli()
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "miottemplate.py", line 92, in print
    gen.print_infos()
  File "miottemplate.py", line 29, in print_infos
    dev = Device.from_json(self.data)
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/dataclasses_json/api.py", line 76, in from_json
    return cls.from_dict(kvs, infer_missing=infer_missing)
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/dataclasses_json/api.py", line 83, in from_dict
    return _decode_dataclass(cls, kvs, infer_missing)
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/dataclasses_json/core.py", line 204, in _decode_dataclass
    infer_missing)
  File "/home/sebastian/src/python-miio/venv/lib/python3.7/site-packages/dataclasses_json/core.py", line 266, in _decode_generic
    res = type_(xs)
  File "/usr/lib/python3.7/typing.py", line 668, in __call__
    raise TypeError(f"Type {self._name} cannot be instantiated; "
TypeError: Type List cannot be instantiated; use list() instead
(venv) 

@rytilahti
Copy link
Owner

rytilahti commented Jan 11, 2021

Ah, it's the second json, but that parses here also just fine. Which version of dataclasses-json do you have installed? This is the one I'm using: dataclasses-json==0.5.2.

One more thing to try out, you could try to modify containers.py line 60 to include the types of the dict elements by changing

value_list: Optional[List[Dict]] = field

to

value_list: Optional[List[Dict[str, Any]]] = field

If that let's it process the file further, then the rest of the Dict hints needs to be converted, too.

@syssi
Copy link
Collaborator Author

syssi commented Jan 13, 2021

$ python3 miottemplate.py print urn\:miot-spec-v2\:device\:humidifier\:0000A00E\:zhimi-ca4\:2.json 
initializing services with t: typing.List[containers.Service] v: [{'iid': 1, 'type': 'urn:miot-spec-v2:service:device-information:00007801:zhimi-ca4:1', 'description': 'Device Information', 'properties': [{'iid': 1, 'type': 'urn:miot-spec-v2:property:manufacturer:00000001:zhimi-ca4:1', 'description': 'Device Manufacturer', 'format': 'string', 'access': ['read']}, {'iid': 2, 'type': 'urn:miot-spec-v2:property:model:00000002:zhimi-ca4:1', 'description': 'Device Model', 'format': 'string', 'access': ['read']}, {'iid': 3, 'type': 'urn:miot-spec-v2:property:serial-number:00000003:zhimi-ca4:1', 'description': 'Device Serial Number', 'format': 'string', 'access': ['read']}, {'iid': 4, 'type': 'urn:miot-spec-v2:property:firmware-revision:00000005:zhimi-ca4:1', 'description': 'Current Firmware Version', 'format': 'string', 'access': ['read']}]}, {'iid': 2, 'type': 'urn:miot-spec-v2:service:humidifier:00007818:zhimi-ca4:1', 'description': 'Humidifier', 'properties': [{'iid': 1, 'type': 'urn:miot-spec-v2:property:on:00000006:zhimi-ca4:1', 'description': 'Switch Status', 'format': 'bool', 'access': ['read', 'write', 'notify'], 'unit': 'none'}, {'iid': 2, 'type': 'urn:miot-spec-v2:property:fault:00000009:zhimi-ca4:1', 'description': 'Device Fault', 'format': 'uint8', 'access': ['read', 'notify'], 'value-range': [0, 15, 1]}, {'iid': 5, 'type': 'urn:miot-spec-v2:property:fan-level:00000016:zhimi-ca4:1', 'description': '风机档位', 'format': 'uint8', 'access': ['read', 'write', 'notify'], 'unit': 'none', 'value-list': [{'value': 0, 'description': 'Auto'}, {'value': 1, 'description': 'Level1'}, {'value': 2, 'description': 'Level2'}, {'value': 3, 'description': 'Level3'}]}, {'iid': 6, 'type': 'urn:miot-spec-v2:property:target-humidity:00000022:zhimi-ca4:1', 'description': '设定湿度', 'format': 'uint8', 'access': ['read', 'write', 'notify'], 'unit': 'percentage', 'value-range': [30, 80, 1]}, {'iid': 7, 'type': 'urn:miot-spec-v2:property:water-level:0000003D:zhimi-ca4:1', 'description': 'Water Level', 'format': 'uint8', 'access': ['read', 'notify'], 'value-range': [0, 128, 1]}, {'iid': 11, 'type': 'urn:miot-spec-v2:property:speed-level:00000023:zhimi-ca4:1', 'description': '设定速度', 'format': 'int32', 'access': ['read', 'write', 'notify'], 'unit': 'none', 'value-range': [200, 2000, 10]}, {'iid': 8, 'type': 'urn:zhimi-spec:property:dry:00000001:zhimi-ca4:1', 'description': '', 'format': 'bool', 'access': ['read', 'write', 'notify']}, {'iid': 9, 'type': 'urn:zhimi-spec:property:use-time:00000002:zhimi-ca4:1', 'description': '', 'format': 'int32', 'access': ['read', 'notify'], 'value-range': [0, 2147483600, 1]}, {'iid': 10, 'type': 'urn:zhimi-spec:property:button-pressed:00000003:zhimi-ca4:1', 'description': '按键信息', 'format': 'uint8', 'access': ['read', 'notify'], 'value-list': [{'value': 0, 'description': 'none'}, {'value': 1, 'description': 'led'}, {'value': 2, 'description': 'power'}]}], 'events': [{'iid': 1, 'type': 'urn:miot-spec-v2:event:low-water-level:0000500A:zhimi-ca4:1', 'description': 'Low Water Level', 'arguments': []}]}, {'iid': 3, 'type': 'urn:miot-spec-v2:service:environment:0000780A:zhimi-ca4:1', 'description': 'Environment', 'properties': [{'iid': 7, 'type': 'urn:miot-spec-v2:property:temperature:00000020:zhimi-ca4:1', 'description': '温度', 'format': 'float', 'access': ['read', 'notify'], 'unit': 'celsius', 'value-range': [-40, 125, 0.1]}, {'iid': 9, 'type': 'urn:miot-spec-v2:property:relative-humidity:0000000C:zhimi-ca4:1', 'description': 'Relative Humidity', 'format': 'uint8', 'access': ['read', 'notify'], 'unit': 'percentage', 'value-range': [0, 100, 1]}, {'iid': 8, 'type': 'urn:zhimi-spec:property:fahrenheit:00000001:zhimi-ca4:1', 'description': '', 'format': 'float', 'access': ['read', 'notify'], 'value-range': [-40, 257, 0.1]}]}, {'iid': 4, 'type': 'urn:miot-spec-v2:service:alarm:00007804:zhimi-ca4:1', 'description': 'Alarm', 'properties': [{'iid': 1, 'type': 'urn:miot-spec-v2:property:alarm:00000012:zhimi-ca4:1', 'description': 'Alarm', 'format': 'bool', 'access': ['read', 'write', 'notify']}]}, {'iid': 5, 'type': 'urn:miot-spec-v2:service:screen:00007806:zhimi-ca4:1', 'description': 'Screen', 'properties': [{'iid': 2, 'type': 'urn:miot-spec-v2:property:brightness:0000000D:zhimi-ca4:1', 'description': '亮度', 'format': 'uint8', 'access': ['read', 'write', 'notify'], 'unit': 'percentage', 'value-list': [{'value': 0, 'description': 'Dark'}, {'value': 1, 'description': 'Glimmer'}, {'value': 2, 'description': 'Brightest'}]}]}, {'iid': 6, 'type': 'urn:miot-spec-v2:service:physical-controls-locked:00007807:zhimi-ca4:1', 'description': 'Physical Control Locked', 'properties': [{'iid': 1, 'type': 'urn:miot-spec-v2:property:physical-controls-locked:0000001D:zhimi-ca4:1', 'description': 'Physical Control Locked', 'format': 'bool', 'access': ['read', 'write', 'notify']}]}, {'iid': 7, 'type': 'urn:zhimi-spec:service:other:00007801:zhimi-ca4:1', 'description': '', 'properties': [{'iid': 1, 'type': 'urn:zhimi-spec:property:actual-speed:00000001:zhimi-ca4:1', 'description': '', 'format': 'uint32', 'access': ['read'], 'value-range': [0, 2000, 1]}, {'iid': 3, 'type': 'urn:zhimi-spec:property:power-time:00000003:zhimi-ca4:1', 'description': '', 'format': 'uint32', 'access': ['read'], 'unit': 'seconds', 'value-range': [0, 4294967295, 1]}, {'iid': 4, 'type': 'urn:zhimi-spec:property:country-code:00000002:zhimi-ca4:2', 'description': 'country-code', 'format': 'uint32', 'access': ['read', 'notify', 'write'], 'unit': 'none', 'value-list': [{'value': 0, 'description': '0未知'}, {'value': 1, 'description': 'US美国'}, {'value': 82, 'description': 'KR韩国'}, {'value': 44, 'description': 'EU欧洲'}, {'value': 81, 'description': 'JP日本'}, {'value': 7, 'description': 'RU俄罗斯'}, {'value': 86, 'description': 'CN中国'}, {'value': 852, 'description': 'HK中国香港'}, {'value': 886, 'description': 'TW中国台湾'}, {'value': 33, 'description': 'FR法国'}]}, {'iid': 5, 'type': 'urn:zhimi-spec:property:clean:00000004:zhimi-ca4:2', 'description': 'clean', 'format': 'bool', 'access': ['read', 'notify', 'write'], 'unit': 'none'}], 'events': [{'iid': 1, 'type': 'urn:zhimi-spec:event:status-report:00005001:zhimi-ca4:1', 'description': '聚合上报', 'arguments': [3]}, {'iid': 2, 'type': 'urn:zhimi-spec:event:water-box-off:00005002:zhimi-ca4:1', 'description': '水箱分离', 'arguments': []}, {'iid': 3, 'type': 'urn:zhimi-spec:event:child-lock-trigger:00005003:zhimi-ca4:1', 'description': '童锁上报', 'arguments': []}]}], infer: False
initializing properties with t: typing.List[containers.Property] v: [{'iid': 1, 'type': 'urn:miot-spec-v2:property:manufacturer:00000001:zhimi-ca4:1', 'description': 'Device Manufacturer', 'format': 'string', 'access': ['read']}, {'iid': 2, 'type': 'urn:miot-spec-v2:property:model:00000002:zhimi-ca4:1', 'description': 'Device Model', 'format': 'string', 'access': ['read']}, {'iid': 3, 'type': 'urn:miot-spec-v2:property:serial-number:00000003:zhimi-ca4:1', 'description': 'Device Serial Number', 'format': 'string', 'access': ['read']}, {'iid': 4, 'type': 'urn:miot-spec-v2:property:firmware-revision:00000005:zhimi-ca4:1', 'description': 'Current Firmware Version', 'format': 'string', 'access': ['read']}], infer: False
initializing access with t: typing.List[str] v: ['read'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing access with t: typing.List[str] v: ['read'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing access with t: typing.List[str] v: ['read'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing access with t: typing.List[str] v: ['read'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing actions with t: typing.List[containers.Action] v: [], infer: False
initializing events with t: typing.List[containers.Event] v: [], infer: False
initializing properties with t: typing.List[containers.Property] v: [{'iid': 1, 'type': 'urn:miot-spec-v2:property:on:00000006:zhimi-ca4:1', 'description': 'Switch Status', 'format': 'bool', 'access': ['read', 'write', 'notify'], 'unit': 'none'}, {'iid': 2, 'type': 'urn:miot-spec-v2:property:fault:00000009:zhimi-ca4:1', 'description': 'Device Fault', 'format': 'uint8', 'access': ['read', 'notify'], 'value-range': [0, 15, 1]}, {'iid': 5, 'type': 'urn:miot-spec-v2:property:fan-level:00000016:zhimi-ca4:1', 'description': '风机档位', 'format': 'uint8', 'access': ['read', 'write', 'notify'], 'unit': 'none', 'value-list': [{'value': 0, 'description': 'Auto'}, {'value': 1, 'description': 'Level1'}, {'value': 2, 'description': 'Level2'}, {'value': 3, 'description': 'Level3'}]}, {'iid': 6, 'type': 'urn:miot-spec-v2:property:target-humidity:00000022:zhimi-ca4:1', 'description': '设定湿度', 'format': 'uint8', 'access': ['read', 'write', 'notify'], 'unit': 'percentage', 'value-range': [30, 80, 1]}, {'iid': 7, 'type': 'urn:miot-spec-v2:property:water-level:0000003D:zhimi-ca4:1', 'description': 'Water Level', 'format': 'uint8', 'access': ['read', 'notify'], 'value-range': [0, 128, 1]}, {'iid': 11, 'type': 'urn:miot-spec-v2:property:speed-level:00000023:zhimi-ca4:1', 'description': '设定速度', 'format': 'int32', 'access': ['read', 'write', 'notify'], 'unit': 'none', 'value-range': [200, 2000, 10]}, {'iid': 8, 'type': 'urn:zhimi-spec:property:dry:00000001:zhimi-ca4:1', 'description': '', 'format': 'bool', 'access': ['read', 'write', 'notify']}, {'iid': 9, 'type': 'urn:zhimi-spec:property:use-time:00000002:zhimi-ca4:1', 'description': '', 'format': 'int32', 'access': ['read', 'notify'], 'value-range': [0, 2147483600, 1]}, {'iid': 10, 'type': 'urn:zhimi-spec:property:button-pressed:00000003:zhimi-ca4:1', 'description': '按键信息', 'format': 'uint8', 'access': ['read', 'notify'], 'value-list': [{'value': 0, 'description': 'none'}, {'value': 1, 'description': 'led'}, {'value': 2, 'description': 'power'}]}], infer: False
initializing access with t: typing.List[str] v: ['read', 'write', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: none, infer: False
initializing access with t: typing.List[str] v: ['read', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: [0, 15, 1], infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing access with t: typing.List[str] v: ['read', 'write', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [{'value': 0, 'description': 'Auto'}, {'value': 1, 'description': 'Level1'}, {'value': 2, 'description': 'Level2'}, {'value': 3, 'description': 'Level3'}], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: none, infer: False
initializing access with t: typing.List[str] v: ['read', 'write', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: [30, 80, 1], infer: False
initializing unit with t: typing.Union[str, NoneType] v: percentage, infer: False
initializing access with t: typing.List[str] v: ['read', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: [0, 128, 1], infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing access with t: typing.List[str] v: ['read', 'write', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: [200, 2000, 10], infer: False
initializing unit with t: typing.Union[str, NoneType] v: none, infer: False
initializing access with t: typing.List[str] v: ['read', 'write', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing access with t: typing.List[str] v: ['read', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: [0, 2147483600, 1], infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing access with t: typing.List[str] v: ['read', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [{'value': 0, 'description': 'none'}, {'value': 1, 'description': 'led'}, {'value': 2, 'description': 'power'}], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing actions with t: typing.List[containers.Action] v: [], infer: False
initializing events with t: typing.List[containers.Event] v: [{'iid': 1, 'type': 'urn:miot-spec-v2:event:low-water-level:0000500A:zhimi-ca4:1', 'description': 'Low Water Level', 'arguments': []}], infer: False
initializing arguments with t: typing.List[int] v: [], infer: False
initializing properties with t: typing.List[containers.Property] v: [{'iid': 7, 'type': 'urn:miot-spec-v2:property:temperature:00000020:zhimi-ca4:1', 'description': '温度', 'format': 'float', 'access': ['read', 'notify'], 'unit': 'celsius', 'value-range': [-40, 125, 0.1]}, {'iid': 9, 'type': 'urn:miot-spec-v2:property:relative-humidity:0000000C:zhimi-ca4:1', 'description': 'Relative Humidity', 'format': 'uint8', 'access': ['read', 'notify'], 'unit': 'percentage', 'value-range': [0, 100, 1]}, {'iid': 8, 'type': 'urn:zhimi-spec:property:fahrenheit:00000001:zhimi-ca4:1', 'description': '', 'format': 'float', 'access': ['read', 'notify'], 'value-range': [-40, 257, 0.1]}], infer: False
initializing access with t: typing.List[str] v: ['read', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: [-40, 125, 0.1], infer: False
initializing unit with t: typing.Union[str, NoneType] v: celsius, infer: False
initializing access with t: typing.List[str] v: ['read', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: [0, 100, 1], infer: False
initializing unit with t: typing.Union[str, NoneType] v: percentage, infer: False
initializing access with t: typing.List[str] v: ['read', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: [-40, 257, 0.1], infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing actions with t: typing.List[containers.Action] v: [], infer: False
initializing events with t: typing.List[containers.Event] v: [], infer: False
initializing properties with t: typing.List[containers.Property] v: [{'iid': 1, 'type': 'urn:miot-spec-v2:property:alarm:00000012:zhimi-ca4:1', 'description': 'Alarm', 'format': 'bool', 'access': ['read', 'write', 'notify']}], infer: False
initializing access with t: typing.List[str] v: ['read', 'write', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing actions with t: typing.List[containers.Action] v: [], infer: False
initializing events with t: typing.List[containers.Event] v: [], infer: False
initializing properties with t: typing.List[containers.Property] v: [{'iid': 2, 'type': 'urn:miot-spec-v2:property:brightness:0000000D:zhimi-ca4:1', 'description': '亮度', 'format': 'uint8', 'access': ['read', 'write', 'notify'], 'unit': 'percentage', 'value-list': [{'value': 0, 'description': 'Dark'}, {'value': 1, 'description': 'Glimmer'}, {'value': 2, 'description': 'Brightest'}]}], infer: False
initializing access with t: typing.List[str] v: ['read', 'write', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [{'value': 0, 'description': 'Dark'}, {'value': 1, 'description': 'Glimmer'}, {'value': 2, 'description': 'Brightest'}], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: percentage, infer: False
initializing actions with t: typing.List[containers.Action] v: [], infer: False
initializing events with t: typing.List[containers.Event] v: [], infer: False
initializing properties with t: typing.List[containers.Property] v: [{'iid': 1, 'type': 'urn:miot-spec-v2:property:physical-controls-locked:0000001D:zhimi-ca4:1', 'description': 'Physical Control Locked', 'format': 'bool', 'access': ['read', 'write', 'notify']}], infer: False
initializing access with t: typing.List[str] v: ['read', 'write', 'notify'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing actions with t: typing.List[containers.Action] v: [], infer: False
initializing events with t: typing.List[containers.Event] v: [], infer: False
initializing properties with t: typing.List[containers.Property] v: [{'iid': 1, 'type': 'urn:zhimi-spec:property:actual-speed:00000001:zhimi-ca4:1', 'description': '', 'format': 'uint32', 'access': ['read'], 'value-range': [0, 2000, 1]}, {'iid': 3, 'type': 'urn:zhimi-spec:property:power-time:00000003:zhimi-ca4:1', 'description': '', 'format': 'uint32', 'access': ['read'], 'unit': 'seconds', 'value-range': [0, 4294967295, 1]}, {'iid': 4, 'type': 'urn:zhimi-spec:property:country-code:00000002:zhimi-ca4:2', 'description': 'country-code', 'format': 'uint32', 'access': ['read', 'notify', 'write'], 'unit': 'none', 'value-list': [{'value': 0, 'description': '0未知'}, {'value': 1, 'description': 'US美国'}, {'value': 82, 'description': 'KR韩国'}, {'value': 44, 'description': 'EU欧洲'}, {'value': 81, 'description': 'JP日本'}, {'value': 7, 'description': 'RU俄罗斯'}, {'value': 86, 'description': 'CN中国'}, {'value': 852, 'description': 'HK中国香港'}, {'value': 886, 'description': 'TW中国台湾'}, {'value': 33, 'description': 'FR法国'}]}, {'iid': 5, 'type': 'urn:zhimi-spec:property:clean:00000004:zhimi-ca4:2', 'description': 'clean', 'format': 'bool', 'access': ['read', 'notify', 'write'], 'unit': 'none'}], infer: False
initializing access with t: typing.List[str] v: ['read'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: [0, 2000, 1], infer: False
initializing unit with t: typing.Union[str, NoneType] v: None, infer: False
initializing access with t: typing.List[str] v: ['read'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: [0, 4294967295, 1], infer: False
initializing unit with t: typing.Union[str, NoneType] v: seconds, infer: False
initializing access with t: typing.List[str] v: ['read', 'notify', 'write'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [{'value': 0, 'description': '0未知'}, {'value': 1, 'description': 'US美国'}, {'value': 82, 'description': 'KR韩国'}, {'value': 44, 'description': 'EU欧洲'}, {'value': 81, 'description': 'JP日本'}, {'value': 7, 'description': 'RU俄罗斯'}, {'value': 86, 'description': 'CN中国'}, {'value': 852, 'description': 'HK中国香港'}, {'value': 886, 'description': 'TW中国台湾'}, {'value': 33, 'description': 'FR法国'}], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: none, infer: False
initializing access with t: typing.List[str] v: ['read', 'notify', 'write'], infer: False
initializing value_list with t: typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType] v: [], infer: False
initializing value_range with t: typing.Union[typing.List[int], NoneType] v: None, infer: False
initializing unit with t: typing.Union[str, NoneType] v: none, infer: False
initializing actions with t: typing.List[containers.Action] v: [], infer: False
initializing events with t: typing.List[containers.Event] v: [{'iid': 1, 'type': 'urn:zhimi-spec:event:status-report:00005001:zhimi-ca4:1', 'description': '聚合上报', 'arguments': [3]}, {'iid': 2, 'type': 'urn:zhimi-spec:event:water-box-off:00005002:zhimi-ca4:1', 'description': '水箱分离', 'arguments': []}, {'iid': 3, 'type': 'urn:zhimi-spec:event:child-lock-trigger:00005003:zhimi-ca4:1', 'description': '童锁上报', 'arguments': []}], infer: False
initializing arguments with t: typing.List[int] v: [3], infer: False
initializing arguments with t: typing.List[int] v: [], infer: False
initializing arguments with t: typing.List[int] v: [], infer: False
Device 'urn:miot-spec-v2:device:humidifier:0000A00E:zhimi-ca4:2': Humidifier with 7 services

* Service siid 1: (Device Information): 4 props, 0 actions

        ## Properties ##
                siid 1: piid: 1 (Device Manufacturer): (string, unit: None) (acc: ['read'])
                siid 1: piid: 2 (Device Model): (string, unit: None) (acc: ['read'])
                siid 1: piid: 3 (Device Serial Number): (string, unit: None) (acc: ['read'])
                siid 1: piid: 4 (Current Firmware Version): (string, unit: None) (acc: ['read'])

* Service siid 2: (Humidifier): 9 props, 0 actions

        ## Properties ##
                siid 2: piid: 1 (Switch Status): (bool, unit: none) (acc: ['read', 'write', 'notify'])
                siid 2: piid: 2 (Device Fault): (uint8, unit: None) (acc: ['read', 'notify'])
                        Range: [0, 15, 1]
                siid 2: piid: 5 (风机档位): (uint8, unit: none) (acc: ['read', 'write', 'notify'])
                        {'value': 0, 'description': 'Auto'}
                        {'value': 1, 'description': 'Level1'}
                        {'value': 2, 'description': 'Level2'}
                        {'value': 3, 'description': 'Level3'}
                siid 2: piid: 6 (设定湿度): (uint8, unit: percentage) (acc: ['read', 'write', 'notify'])
                        Range: [30, 80, 1]
                siid 2: piid: 7 (Water Level): (uint8, unit: None) (acc: ['read', 'notify'])
                        Range: [0, 128, 1]
                siid 2: piid: 11 (设定速度): (int32, unit: none) (acc: ['read', 'write', 'notify'])
                        Range: [200, 2000, 10]
                siid 2: piid: 8 (): (bool, unit: None) (acc: ['read', 'write', 'notify'])
                siid 2: piid: 9 (): (int32, unit: None) (acc: ['read', 'notify'])
                        Range: [0, 2147483600, 1]
                siid 2: piid: 10 (按键信息): (uint8, unit: None) (acc: ['read', 'notify'])
                        {'value': 0, 'description': 'none'}
                        {'value': 1, 'description': 'led'}
                        {'value': 2, 'description': 'power'}

        ## Events ##
                siid 2: eiid 1 (Low Water Level): (args: [])

* Service siid 3: (Environment): 3 props, 0 actions

        ## Properties ##
                siid 3: piid: 7 (温度): (float, unit: celsius) (acc: ['read', 'notify'])
                        Range: [-40, 125, 0.1]
                siid 3: piid: 9 (Relative Humidity): (uint8, unit: percentage) (acc: ['read', 'notify'])
                        Range: [0, 100, 1]
                siid 3: piid: 8 (): (float, unit: None) (acc: ['read', 'notify'])
                        Range: [-40, 257, 0.1]

* Service siid 4: (Alarm): 1 props, 0 actions

        ## Properties ##
                siid 4: piid: 1 (Alarm): (bool, unit: None) (acc: ['read', 'write', 'notify'])

* Service siid 5: (Screen): 1 props, 0 actions

        ## Properties ##
                siid 5: piid: 2 (亮度): (uint8, unit: percentage) (acc: ['read', 'write', 'notify'])
                        {'value': 0, 'description': 'Dark'}
                        {'value': 1, 'description': 'Glimmer'}
                        {'value': 2, 'description': 'Brightest'}

* Service siid 6: (Physical Control Locked): 1 props, 0 actions

        ## Properties ##
                siid 6: piid: 1 (Physical Control Locked): (bool, unit: None) (acc: ['read', 'write', 'notify'])

* Service siid 7: (): 4 props, 0 actions

        ## Properties ##
                siid 7: piid: 1 (): (uint32, unit: None) (acc: ['read'])
                        Range: [0, 2000, 1]
                siid 7: piid: 3 (): (uint32, unit: seconds) (acc: ['read'])
                        Range: [0, 4294967295, 1]
                siid 7: piid: 4 (country-code): (uint32, unit: none) (acc: ['read', 'notify', 'write'])
                        {'value': 0, 'description': '0未知'}
                        {'value': 1, 'description': 'US美国'}
                        {'value': 82, 'description': 'KR韩国'}
                        {'value': 44, 'description': 'EU欧洲'}
                        {'value': 81, 'description': 'JP日本'}
                        {'value': 7, 'description': 'RU俄罗斯'}
                        {'value': 86, 'description': 'CN中国'}
                        {'value': 852, 'description': 'HK中国香港'}
                        {'value': 886, 'description': 'TW中国台湾'}
                        {'value': 33, 'description': 'FR法国'}
                siid 7: piid: 5 (clean): (bool, unit: none) (acc: ['read', 'notify', 'write'])

        ## Events ##
                siid 7: eiid 1 (聚合上报): (args: [3])
                siid 7: eiid 2 (水箱分离): (args: [])
                siid 7: eiid 3 (童锁上报): (args: [])
(venv)

It looks like this fixed the issue.

@syssi
Copy link
Collaborator Author

syssi commented Jan 13, 2021

I'm using dataclasses-json==0.5.2, too.

rytilahti pushed a commit that referenced this issue Jan 13, 2021
…910)

* Fix __repr__ of AirHumidifierMiotStatus (Closes: #908)

* Improve miottemplate.py print to support python 3.7.3
xvlady pushed a commit to xvlady/python-miio that referenced this issue May 9, 2021
…hti#906) (rytilahti#910)

* Fix __repr__ of AirHumidifierMiotStatus (Closes: rytilahti#908)

* Improve miottemplate.py print to support python 3.7.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants