WIP: improve miotdevice API, add gosund plug support (cuco.plug.cp1)#672
WIP: improve miotdevice API, add gosund plug support (cuco.plug.cp1)#672
Conversation
* add miot_info() to get the common information from the device * this includes manufacturer, model, firmeware version and serial number * add get_properties_for_dataclass(cls) which allows easy implementation for get_properties mappings * each field() can define metadata containing siid and piid, these are mapped automatically to the response container * _siid can be used to define common siid, _max_properties can be used to set number of maximum properties per request * get_properties_for_mapping() requires explicit passing of the mapping, no more passing over __init__
* rename old set_property to set_property_from_mapping * add set_properties_from_dataclass (allows passing a mapping object with all wanted values at once) ``` device.set_properties_from_dataclass(GosundPlugStatus(state=True, some_other_property=123) ``` * new set_property helper which takes kwargs that are used automatically with the help of the class-given _MAPPING: ``` device.set_property(state=True) ```
this is just a poc to show how the new api could function
|
@foxel if you have some time, your feedback on how/if the API needs adaptations to allow porting airpurifier_miot over it :-) for the time being this is just an experimental try to see if this approach makes sense in general, alas, the only miot device I have has only a single service (besides the common miot_info) with a single property... |
|
FYI. Device Information-Current Firmware Version |
|
Yeah, probably not all manufacturers implement it properly (considering miio.info also reveals enough information). Here's what I'm getting out with that plug: edit: also calling the |
|
the code looks much easier for miot in this branch, can you improve it asap? i want to add more devices like curtain wifi version |
|
I'll try to find some time soonish to push this onwards. I have a locally modified devtools that will make integrating a bit easier. I'll create another PR for that when I can. |
|
Hi. Just an idea: What about downloading and parsing the miot spec on new device detection? On this page: |
|
@mkohns see the soon-to-be-linked PR, I'm closing this now as obsolete :-) |
This PR aims to add better support for miot devices, and build a common API to simplify contributions for new devices.
add miot_info() to get the common information from the device
add get_properties_for_dataclass(cls) which allows easy implementation for get_properties mappings
"old" get_properties_for_mapping() requires explicit passing of the mapping, no more passing over
__init__rename old set_property to set_property_from_mapping
Add support for gosund miot plug (cuco.plug.cp1) to show how the API could work.
TODO
_MAPPING_max_properties.add_property(piid, siid)?