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

WIP: Initial support for Vacuum 1C STYTJ01ZHM (dreame.vacuum.mc1808) #683

Closed
wants to merge 15 commits into from

Conversation

rytilahti
Copy link
Owner

@rytilahti rytilahti commented Apr 21, 2020

Partially autogenerated based on the spec file, so things may or may not work,
so use at your own risk. in its current state it is more or less just for testing.

Fixes #669 when its ready.
This based itself on #672, so it should be merged first when the time comes.

* 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
partially autogenerated based on the spec file, so things may or may not work,
so use at your own risk. in its current state it is more or less just for testing.

Fixes #669
@rytilahti rytilahti changed the title Initial support for Vacuum 1C STYTJ01ZHM (dreame.vacuum.mc1808) WIP: Initial support for Vacuum 1C STYTJ01ZHM (dreame.vacuum.mc1808) Apr 21, 2020
@craiq
Copy link

craiq commented Apr 22, 2020

requests are using 'get_prop' but should be 'get_properties'
after changing the status command runs flawlessly :D
http://txt.do/1q5mx

@craiq
Copy link

craiq commented Apr 22, 2020

Start
action "{'did':'...','siid':18,'aiid':1,'in':[{'piid':1,'value':2}]}"

Resume to charge
action "{'did':'...','siid':2,'aiid':1,'in':[]}"

… on unfetchable properties

* Changes the property getter (get_prop for miio, get_properties for miot)
* The properties that were not properly fetched are now returned instead of crashing completely
  * useful for setting _max_properties=1 for debugging to see which properties are available
@floman321
Copy link

hello, what syntax should a use for start_remote please ? X and Y ?

@craiq
Copy link

craiq commented Apr 26, 2020

start_remote will just start the modus without additional variables
Then you have to give direction and speed as separate commands. But they are not integrated yet

@floman321
Copy link

thanks you

@floman321
Copy link

this is working well. thank you for your work.

@DavidConnack
Copy link

@rytilahti would you mind to explain how the commands are working.
Mainly the siid piid and aiid.
Im interested in seeing if i can create some more commands.
Thanks

@rytilahti
Copy link
Owner Author

Do you have something specific you are interested in?

The code itself bases on the metadata files that are available on the internet (#543 (comment)) which are parsed using the script found under devtools directory of the repository. #543 (comment) describes the different pieces of information found in those description files.

The PR linked on the issue description (#672) which this bases on has some todo items. For example, the manual controls on this device are done using writing the properties of the service with siid 21 (https://github.com/rytilahti/python-miio/pull/683/files#diff-1d60d6cac3e7d3a87e527874901056afR195).

About setting properties, the API is not yet there, but you can get an idea if you take a look at https://github.com/rytilahti/python-miio/pull/672/files#diff-917e6e7e59bfa94f83c5923372d51a4dR32 . The state here is the property as listed in the dataclass defined by _MAPPING, so setting the fan speed to silent should probably work by doing:

vac.set_property(fan_speed=0)

For actions, the service id and action id are also obtained from the description file.

@DavidConnack
Copy link

Thanks for the info
Im looking for an explanation of implementing the API rather than using it.
Such as:
@command() def stop_sweeping(self) -> None: """aiid 2 Stop Sweeping: in: [] -> out: []""" return self.call_action(3, 2)

From what i can make out for each action requires a call to call_action with a siid, aiid and an optional payload.

I was attempting to change the fan speed with something like the following:
@command() def fan_speed(self) -> None: payload = [{"piid": 6, "value": 3}] return self.call_action(6,2,payload)

@rytilahti
Copy link
Owner Author

Where did you get the siid 6, aiid 2 for the call? Anyways, if you look at the description file, the fan speed is a property as I mentioned above. Did you try that set_property method call?

So maybe something like this could work?

@command(
    click.argument("speed", type=EnumType(VacuumSpeed, casesensitive=False))
)
def fan_speed(self, speed):
    return self.set_property(fan_speed=speed.value)

and calling like fan_speed silent with any VacuumSpeed.

@DavidConnack
Copy link

I think i have a clearer picture now of how this works.
One last thing, I think with the mapping.
A simple function like this:
@command() def fan_speed(self): return self.set_property(fan_speed=3)
should turn the vacuum speed to turbo.
However it requires arguments for each property.
https://pastebin.com/xPPB687y

Thanks again for explaining

@rytilahti
Copy link
Owner Author

Ah, indeed, I didn't recall that API is not yet complete, sorry for that. To make it work, all the field definitions need to be modified to default to some value.

So

battery: int = field(metadata={"siid": 2, "piid": 1, "access": ["read", "notify"]})

needs to become

battery: int = field(metadata={"siid": 2, "piid": 1, "access": ["read", "notify"]}, default=None)

and so on for each and every field.

This is related to the TODO item helper to create fields with wanted metadata, maybe add_property(piid, siid)?.

@DavidConnack
Copy link

I had to add the default=None to each property, but then then finally got it working.
@command(click.argument("speed", type=int)) def fan_speed(self, speed): return self.set_property(fan_speed=speed)
What further work needs to be done to get this merged(at least basic functionality)?
Im keen on getting a home assistant integration for this

@rytilahti
Copy link
Owner Author

So there are two things that needs to be done until I'm satisfied to get this out:

  1. Improve the miot API implementation for cleaner action calls, setters. When I find some time I will be working on this.
  2. Generalize the vacuum interface (Add support for Vacuum 1C STYTJ01ZHM #669 (comment)) so that all different vacuums can be controlled using a common interface.

@Griizly
Copy link

Griizly commented May 28, 2020

Hello, stupid question, is it already possible to install this on home assistant ?

@SLG
Copy link

SLG commented Jun 11, 2020

@rytilahti I'm new to this repo, but have both Home Assistant as a Vacuum 1c. Is there anything I can do to help? I've just created a simple cli file, based on the vacuum_cli, but a lot of commands are still missing.
@Griizly , nope, not until this PR is merged.

@rytilahti
Copy link
Owner Author

@SLG see my previous comment (the link). We are going to need an abstract interface (or interfaces, the status containers should also have a common base) that exposes the common functionality of all current (and potential future) implementations. The vacuum implementations will implement this interface and we can simply use the common interface in homeassistant (or cli) to provide some basic functionality using that interface.

@craiq
Copy link

craiq commented Jun 21, 2020

does anyone has a working fork for just this vacuum?
I would love to use the vacuum with home assistant in the near future.

@DavidConnack
Copy link

does anyone has a working fork for just this vacuum?
I would love to use the vacuum with home assistant in the near future.

https://github.com/Concentricc/xiaomi_vacuum
It has the basic features working.
Spot cleaning/ room cleaning and other more advanced features dont work. (dont know if they are supported.)

@craiq
Copy link

craiq commented Jun 21, 2020

great!!! Thank you! I'll have a look :)

@muchar
Copy link

muchar commented Jan 8, 2021

+1

@rytilahti
Copy link
Owner Author

This has been obsoleted by #952.

@rytilahti rytilahti closed this Feb 24, 2021
@rytilahti rytilahti deleted the dreame_miot_mc1808 branch February 24, 2021 14:40
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.

Add support for Vacuum 1C STYTJ01ZHM
8 participants