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

Support for Xiaomi Mijia G1 (mijia.vacuum.v2) #867

Merged
merged 34 commits into from Sep 2, 2021
Merged

Support for Xiaomi Mijia G1 (mijia.vacuum.v2) #867

merged 34 commits into from Sep 2, 2021

Conversation

neturmel
Copy link
Contributor

@neturmel neturmel commented Nov 23, 2020

just a quick and dirty hack based on airhumidifier_miot and dreame.vacuum.mc1808.
Only some commands are working. But you get some status report and starting and stopping ist possible.
Didn't bother to try it with the newer "get_properties_by_dataclass".

@gorbypark
Copy link

I've checked out this branch, did a poetry install and am trying to run mirobo with poetry run mirobo --token .... --ip 172.20.10.3 --debug status but only get errors. Any ideas? I just got a G1 (actually an "essential", but I believe it's the same as a G1 just for the European market) and would like to contribute to getting this working.

Using python3 (3.8.6)
INFO:miio.vacuum_cli:Debug mode active
DEBUG:miio.vacuum_cli:Connecting to 172.20.10.3 with token .....
DEBUG:miio.protocol:Unable to decrypt, returning raw bytes: b''
DEBUG:miio.miioprotocol:Got a response: Container:
    data = Container:
        data = b'' (total 0)
        value = b'' (total 0)
        offset1 = 32
        offset2 = 32
        length = 0
    header = Container:
        data = b'!1\x00 \x00\x00\x00\x00\x12\xea\xdeW\x00\x00\x0c\xcb' (total 16)
        value = Container:
            length = 32
            unknown = 0
            device_id = unhexlify('12eade57')
            ts = 1970-01-01 00:54:35
        offset1 = 0
        offset2 = 16
        length = 16
    checksum = b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' (total 16)
DEBUG:miio.miioprotocol:Discovered 12eade57 with ts: 1970-01-01 00:54:35, token: b'ffffffffffffffffffffffffffffffff'
DEBUG:miio.miioprotocol:172.20.10.3:54321 >>: {'id': 1, 'method': 'get_status', 'params': []}
DEBUG:miio.miioprotocol:172.20.10.3:54321 (ts: 1970-01-01 00:54:35, id: 1) << {'id': 1, 'error': {'code': -9999, 'message': 'undefined command'}, 'exe_time': 80}
DEBUG:miio.click_common:Exception: {'code': -9999, 'message': 'undefined command'}
Traceback (most recent call last):
  File "/Users/mikehamilton/Documents/vacuum/python-miio/miio/click_common.py", line 59, in __call__
    return self.main(*args, **kwargs)
  File "/Users/mikehamilton/Library/Caches/pypoetry/virtualenvs/python-miio-a_sq3Jxb-py3.8/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/mikehamilton/Library/Caches/pypoetry/virtualenvs/python-miio-a_sq3Jxb-py3.8/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/mikehamilton/Library/Caches/pypoetry/virtualenvs/python-miio-a_sq3Jxb-py3.8/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/mikehamilton/Library/Caches/pypoetry/virtualenvs/python-miio-a_sq3Jxb-py3.8/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/mikehamilton/Library/Caches/pypoetry/virtualenvs/python-miio-a_sq3Jxb-py3.8/lib/python3.8/site-packages/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/Users/mikehamilton/Library/Caches/pypoetry/virtualenvs/python-miio-a_sq3Jxb-py3.8/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/mikehamilton/Documents/vacuum/python-miio/miio/vacuum_cli.py", line 112, in status
    res = vac.status()
  File "/Users/mikehamilton/Documents/vacuum/python-miio/miio/vacuum.py", line 236, in status
    return VacuumStatus(self.send("get_status")[0])
  File "/Users/mikehamilton/Documents/vacuum/python-miio/miio/device.py", line 143, in send
    return self._protocol.send(
  File "/Users/mikehamilton/Documents/vacuum/python-miio/miio/miioprotocol.py", line 213, in send
    self._handle_error(payload["error"])
  File "/Users/mikehamilton/Documents/vacuum/python-miio/miio/miioprotocol.py", line 273, in _handle_error
    raise DeviceError(error)
miio.exceptions.DeviceError: {'code': -9999, 'message': 'undefined command'}
Error: {'code': -9999, 'message': 'undefined command'}

@neturmel
Copy link
Contributor Author

neturmel commented Jan 6, 2021

Your log was my starting point also ;)

mirobo won't work because it doesn't know of "g1vacuum", could you please try it with:

poetry run miiocli g1vacuum --token .... --ip 172.20.10.3 --debug status

Since everything which I wanted works - like starting, stopping, pausing, return to home and status working in FHEM (via pythonbinding of miio) and homebridge/Siri , I really don't know if this code will evolve in the near future.

@neturmel neturmel changed the title WIP: Support for Xiaomi Mijia G1 (mijia.vacuum.v2) Support for Xiaomi Mijia G1 (mijia.vacuum.v2) Jan 6, 2021
@NeRobbi
Copy link

NeRobbi commented Jan 11, 2021

I use home assistant as docker image. How can i test your code without installing standalone home assistant and manual update from your branch?

@neturmel
Copy link
Contributor Author

I use home assistant as docker image. How can i test your code without installing standalone home assistant and manual update from your branch?

Unfortunatlely I can't help here, because I have no knowledge about home assistant or its docker image, Maybe it is sufficient to just replace the init.py and insert the new file g1vacuum.py (but I don't know how to map these to the docker image)

@huhuhugo1
Copy link

Thank you!
I just tested your branch with my Xiaomi Mijia G1 Chinese version, and all control commands are working (I did not test reset commands / raw command).

Model: mijia.vacuum.v1
Hardware version: esp32
Firmware version: 2.1.3

@gorbypark
Copy link

gorbypark commented Jun 7, 2021

Sorry for the super late reply...but I can confirm that this appears to work with the Xiaomi Vacccum Mop Essential (afaik it's the same at the G1 but for Europe). This is the output from poetry run miiocli g1vacuum --token .... --ip .... status.

State: State.Charging
Error: Error.Everything_is_ok
Battery: 100%
Mode: VacuumMode.Global_clean
Mop State: MopState.On
Charge Status: ChargeState.Charging_competely
Fan speed: FanSpeed.Standard
Water level: WaterLevel.Level2
Filter Life Level: 95%
Brush Life Level: 97%
Side Brush Life Level: 94%
Clean Area: 0
Clean Time: None
Total Clean Count: 0

Output from poetry run miiocli device --ip ... --token ... info

Model: mijia.vacuum.v2
Hardware version: esp32
Firmware version: 2.0.8

It would be great to get this merged and into an upcoming Home Assistant release..

Copy link
Owner

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @neturmel and thanks for the PR! I'm sorry, I somehow missed this PR earlier and just realized I haven't commented on it after receiving a notification on your recent change.

On the surface the PR looks good, but there are some changes that are easier to done now than later on, mostly related to consolidating the API among different vacuum implementations.

miio/g1vacuum.py Outdated Show resolved Hide resolved
miio/g1vacuum.py Outdated Show resolved Hide resolved
miio/g1vacuum.py Outdated Show resolved Hide resolved
miio/g1vacuum.py Outdated Show resolved Hide resolved
miio/g1vacuum.py Outdated Show resolved Hide resolved
miio/g1vacuum.py Outdated Show resolved Hide resolved
miio/g1vacuum.py Outdated Show resolved Hide resolved
miio/g1vacuum.py Outdated Show resolved Hide resolved
miio/g1vacuum.py Outdated Show resolved Hide resolved
miio/__init__.py Outdated Show resolved Hide resolved
@neturmel
Copy link
Contributor Author

neturmel commented Jul 6, 2021

Just committed some changes. But keep in mind that Python is not my native language ;).
Most of the time I am only hacking bash/ksh scripts and some SQLs.

Copy link
Owner

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to be merged after fixing a few minor issues. Note that there will be an API break so some of the names and values will likely change when I'll consolidate all existing vacuum implementations to have a common (base) API to allow easier downstream integration.

miio/g1vacuum.py Outdated Show resolved Hide resolved
miio/g1vacuum.py Outdated Show resolved Hide resolved
miio/g1vacuum.py Outdated Show resolved Hide resolved
miio/g1vacuum.py Outdated Show resolved Hide resolved
miio/g1vacuum.py Outdated Show resolved Hide resolved
Copy link
Owner

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A final round of comments, thanks for your patience and work on this! :-) When those are done, let's merge this and fix any potential issues in future PRs.

miio/g1vacuum.py Outdated Show resolved Hide resolved
miio/g1vacuum.py Outdated Show resolved Hide resolved
miio/g1vacuum.py Outdated Show resolved Hide resolved
miio/g1vacuum.py Outdated Show resolved Hide resolved
miio/g1vacuum.py Outdated Show resolved Hide resolved
neturmel and others added 4 commits July 9, 2021 09:17
Co-authored-by: Teemu R. <tpr@iki.fi>
Co-authored-by: Teemu R. <tpr@iki.fi>
Co-authored-by: Teemu R. <tpr@iki.fi>
@rytilahti
Copy link
Owner

Looks like black is still doing some changes.. The easiest way to fix this is to run pre-commit run -a on your local copy which will perform the same checks as the CI does :-)

@neturmel
Copy link
Contributor Author

Looks like black is still doing some changes.. The easiest way to fix this is to run pre-commit run -a on your local copy which will perform the same checks as the CI does :-)

no more reformatting by black on local run :)

@rytilahti
Copy link
Owner

Here's the diff that I get after running black on a local checkout:

$ git diff .
diff --git a/miio/g1vacuum.py b/miio/g1vacuum.py
index d9e0152..cd9dbdd 100644
--- a/miio/g1vacuum.py
+++ b/miio/g1vacuum.py
@@ -361,7 +361,7 @@ class G1Vacuum(MiotDevice):
     @command(click.argument("consumable", type=G1Consumable))
     def consumable_reset(self, consumable: G1Consumable):
         """Reset consumable information.
-           CONSUMABLE=main_brush_life_level|side_brush_life_level|filter_life_level"""
+        CONSUMABLE=main_brush_life_level|side_brush_life_level|filter_life_level"""
         if consumable.name == G1Consumable.MainBrush:
             return self.call_action("reset_main_brush_life_level")
         elif consumable.name == G1Consumable.SideBrush:
@@ -375,4 +375,4 @@ class G1Vacuum(MiotDevice):
     )
     def set_fan_speed(self, fan_speed: G1FanSpeed):
         """Set fan speed."""
-        return self.set_property("fan_speed", fan_speed.value)
\ No newline at end of file
+        return self.set_property("fan_speed", fan_speed.value)

@codecov-commenter
Copy link

codecov-commenter commented Jul 13, 2021

Codecov Report

Merging #867 (5f9445d) into master (1d5536d) will decrease coverage by 1.19%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #867      +/-   ##
==========================================
- Coverage   76.07%   74.87%   -1.20%     
==========================================
  Files          75       76       +1     
  Lines        8722     8999     +277     
  Branches      747      767      +20     
==========================================
+ Hits         6635     6738     +103     
- Misses       1905     2077     +172     
- Partials      182      184       +2     
Impacted Files Coverage Δ
miio/g1vacuum.py 0.00% <0.00%> (ø)
miio/fan_miot.py 84.38% <0.00%> (-3.66%) ⬇️
miio/airpurifier_miot.py 87.93% <0.00%> (-1.36%) ⬇️
miio/discovery.py 48.64% <0.00%> (+0.03%) ⬆️
miio/airhumidifier.py 87.62% <0.00%> (+0.06%) ⬆️
miio/fan.py 90.10% <0.00%> (+0.21%) ⬆️
miio/vacuum.py 59.72% <0.00%> (+0.26%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1d5536d...5f9445d. Read the comment docs.

@rytilahti
Copy link
Owner

rytilahti commented Aug 2, 2021

Do you mind adding some tests for this to avoid breaking it when the vacuum integrations get refactored? That would make the codecov checks also happy :-)

@neturmel
Copy link
Contributor Author

neturmel commented Aug 3, 2021

Do you mind adding some tests for this to avoid breaking it when the vacuum integrations get refactored? That would make the codecov checks also happy :-)

No, I don't. But since this is entirely new to me, I expect further errors/warnings whatsoever.

@rytilahti
Copy link
Owner

Great, thanks! Btw, you can run the whole linting process by calling tox -e lint or pre-commit run -a in your local checkout. You can also execute pytest directly locally to verify that the tests are working. This is faster for testing as github requires an approval before it runs the checks :-)

@neturmel
Copy link
Contributor Author

neturmel commented Aug 3, 2021

prec-commit run -a on local checkout was successful.
Hopefully I didn't screw up the EOF this time again before updating.

@rytilahti
Copy link
Owner

Thanks again for the PR and your patience, @neturmel, let's merge it!

@rytilahti rytilahti merged commit 981368c into rytilahti:master Sep 2, 2021
@rytilahti rytilahti mentioned this pull request Nov 30, 2021
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

6 participants