Add functions to obtain miotspec information#11
Conversation
This extends the public API by adding the following new methods to MiCloud:
* miot_get_specs() to get list of all available specs, containing device urns and version information
* miot_get_spec(device_urn) to get a spec for the given device urn
* miot_get_standard_types(type) to get list of standardized elements for a given type (devices, properties, actions, ..)
* miot_get_standard_type_spec(type_urn) to get the spec for a standardized element
The cli tool is extended with a new group ("miot") that can be used to access this functionality.
|
Thank you for the PR, I'll try to make time to look it over and merge ASAP. At the latest this weekend! |
|
There is no hurry, take your time :-) I started to wonder if I should shift the new methods into a new class as they are clearly a bit out-of-place currently, but using the existing fetch functionalities (to keep the useragents etc. consistent) would necessitate some refactoring. Let me know what you think and I'll make the necessary adjustments. |
|
Yeah, fell free to do any refactoring you see fit. If you want to move common code to a new parent or utility class to be able to put miot-functions in its own class, that's fine by me. :) |
|
I reorganized the code a bit by moving the miotspec methods into their own module, and extracted the session creation into an utils function. Feel free to take a look and let me know what you think @Squachen. |
This extends the public API by adding a new module
MiotSpecwith the following new class methods:get_specs()to get list of all available specs, containing device urns and version informationget_spec_for_urn(device_urn)to get a spec for the given device urnget_standard_types(type)to get list of standardized elements for a given "type" (devices, properties, actions, ..)get_standard_type_spec(type_urn)to get the spec for a standardized elementThese methods can be used to obtain information to create generic interfaces based on the response metadata, see rytilahti/python-miio#1581 for an example use-case.
The cli tool is extended with a new sub-command (
miot) that can be used to access this functionality (unfortunately, the existing get-devices has now to be called explicitly...):which allows accessing the new functionalities:
The new commands return JSON so that the output can be passed to
jqor other tools that can consume JSON.Open questions:
get-devicescould be addedreset=Trueto reset the session for every request to avoid passing all extra headers potentially added by the existing functionalityURLs to fetch the data were found at https://gist.github.com/marcelrv/20509106e97b4c7dd8c9056aefda2332 – thanks @marcelrv