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

Add miot simulator #1539

Merged
merged 1 commit into from Sep 26, 2022
Merged

Add miot simulator #1539

merged 1 commit into from Sep 26, 2022

Conversation

rytilahti
Copy link
Owner

@rytilahti rytilahti commented Sep 26, 2022

This adds a simple, full-functioning miot simulator based on miotspec files, making it possible to test both python-miio and downstream implementations. The simulator keeps an internal state constructed based on the defined property constraints (e.g., ranges for int properties or choices for enums). The values are currently randomly generated based on the constraints the spec file does.

The simulator implements the main commands a miot device uses:

  • get_properties (get property values)
  • set_properties (set property values)
  • action (call actions, noop returning success)
  • miIO.info

Additionally, the available services and properties can be dumped using dump_services and dump_properties commands.

Using miiocli devtools miot-simulator requires defining the model (--model) and the path to a miotspec json file (--file).

Example showing an emulated zhimi.airpurifier.mb4 in homeassistant (miiocli devtools miot-simulator --file urn\:miot-spec-v2\:device\:air-purifier\:0000A007\:zhimi-mb4\:2.json --model zhimi.airpurifier.mb4):
image

This adds a simple, full-functioning miot simulator based on miotspec files, making it possible to test both python-miio and downstream implementations.
The simulator keeps an internal state constructed based on the defined properties.
The values are currently randomly generated based on the constraints the spec file does.

The simulator implements the main commands a miot device uses:
* get_properties (get property values)
* set_properties (set property values)
* action (call actions, noop returning success)
* miIO.info

Additionally, the available services and properties can be dumped using `dump_services` and `dump_properties` commands.

Using `miiocli devtools miot-simulator` requires defining the model (`--model`) and the path to a miotspec json file (`--file`.
@codecov-commenter
Copy link

codecov-commenter commented Sep 26, 2022

Codecov Report

Merging #1539 (cb07abe) into master (a1ff575) will decrease coverage by 1.06%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master    #1539      +/-   ##
==========================================
- Coverage   81.95%   80.88%   -1.07%     
==========================================
  Files         149      151       +2     
  Lines       14594    14787     +193     
  Branches     3550     3594      +44     
==========================================
  Hits        11960    11960              
- Misses       2387     2580     +193     
  Partials      247      247              
Impacted Files Coverage Δ
miio/devtools/__init__.py 0.00% <0.00%> (ø)
miio/devtools/simulators/__init__.py 0.00% <0.00%> (ø)
miio/devtools/simulators/miotsimulator.py 0.00% <0.00%> (ø)
miio/devtools/simulators/models.py 0.00% <0.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@rytilahti rytilahti merged commit 639a008 into master Sep 26, 2022
@rytilahti rytilahti deleted the feat/miot_simulator branch September 26, 2022 18:14
rytilahti added a commit that referenced this pull request Oct 26, 2022
Add some documentation on how to use the miot simulator, which was
forgotten to do in #1539
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants