Added: Adapter and CA4 model support #35
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
CA4 model uses miotspec protocol, the schema can be found http://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:humidifier:0000A00E:zhimi-ca4:2
miotspec communication can't fit in the current code structure easily, so as part of this PR, I introduced two components which can be potentially a alternative code structure.
The idea is have a base Humidifier class
devices/MiHumidifierAdapter.js
which encapsulate the common Services and Characteristics, then have different models' implementation inherited from it (devices/MiHumidifierCA4.js
for CA4).Inside the implementation code page, the characteristics are defined in a data driven fashion. here is an example.
devices/MiHumidifierAdapter.js
has a generic functionregisterCharacteristic
to process the above data driven config.devices/MiHumidifierFactory.js
provided a factory function to instantiate the MiHumidifier based on the model in the config. If the model is not supported by the Factory, a null will be returned. Hence, there is no regression issue for all existing models.Test
All characteristics have been tested with my CA4 device.
Note
Javascript is not my specialty language, please point me out if there is any js specific mistake I made.
Related issues:
#26