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 support for Smartmi Air Purifier (zhimi.airpurifier.za1) #1417

Merged
merged 4 commits into from
Jun 26, 2022

Conversation

julian-klode
Copy link
Contributor

Add support for zhimi.airpurifier.za1

This also adds a tvoc attribute, and the gesture control setting in a 2nd commit.

Fixes #1025

@julian-klode julian-klode changed the title Zhimi.airpurifier.za1 Add support for Smartmi Air Purifier (zhimi.airpurifier.za1) May 12, 2022
@julian-klode
Copy link
Contributor Author

julian-klode commented May 12, 2022

I don't know what unit the TVOC value is, it seems to go from 0..500 in 1 steps according to the spec.

There's a bunch more attributes like max. filter time, when the filter door was last opened, or how long the purifier has been sued that I did not bother adding as they do not seem all that useful.

@julian-klode
Copy link
Contributor Author

flake8 failure seems unrelated flake8 issue, should be fixed in master first and I guess then rebase the PR.

I still see:

WARNING:miio.device:Found an unsupported model 'zhimi.airpurifier.za1' for class 'AirPurifierMiot'. If this is working for you, please open an issue at https://github.com/rytilahti/python-miio/

But I'm not sure where else to put that string to get it to be recognized.

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.

LGTM after fixing the exception message, the flake8 error is now fixed in master so rebasing the PR on it should fix the build! The warning you are still receiving feels odd as the keys from mappings dictionary are used to check whether the device is listed as supported or not..

miio/integrations/airpurifier/zhimi/airpurifier_miot.py Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Jun 21, 2022

Codecov Report

Merging #1417 (fe46f48) into master (f92e0e1) will decrease coverage by 0.03%.
The diff coverage is 50.00%.

@@            Coverage Diff             @@
##           master    #1417      +/-   ##
==========================================
- Coverage   84.30%   84.27%   -0.04%     
==========================================
  Files         135      135              
  Lines       13401    13413      +12     
  Branches     3204     3209       +5     
==========================================
+ Hits        11298    11304       +6     
- Misses       1886     1891       +5     
- Partials      217      218       +1     
Impacted Files Coverage Δ
...integrations/airpurifier/zhimi/airpurifier_miot.py 80.73% <50.00%> (-1.80%) ⬇️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@julian-klode
Copy link
Contributor Author

I'm also confused about the warning. It happens with a clean-ish docker container running a tiny python script, so hmm (e9d9270 being the previous head of the branch).

jak@jak-t480s:~/Projects/Stable/python-miio:zhimi.airpurifier.za1$ cat tvoc 
#!/usr/bin/python3
import miio
import time
import paho
import sys

ap=miio.AirPurifierMiot("<ip>", "<key>")


import paho.mqtt.client

import miio

client=paho.mqtt.client.Client()
client.connect("192.168.0.233")


while True:
    try:
        print("Request", file=sys.stderr)
        tvoc = ap.status().tvoc
        print(time.strftime("%H:%M:%S", time.localtime()), tvoc, file=sys.stderr)
        client.publish("sensors/tvoc", tvoc)
    except miio.exceptions.DeviceException as exc:
        print(time.strftime("%H:%M:%S", time.localtime()), exc, file=sys.stderr)
        pass

    time.sleep(5)
jak@jak-t480s:~/Projects/Stable/python-miio:zhimi.airpurifier.za1$ cat Dockerfile 
FROM ubuntu:jammy
RUN apt update && apt install -y python3-pip
RUN pip3 install --upgrade pip poetry
WORKDIR /miio
RUN /usr/lib/apt/apt-helper download-file https://github.com/julian-klode/python-miio/tarball/e9d9270cfe14445e7a16eae4e0a3fa0fb675995a /tmp/miio.tar.gz && tar xvzf /tmp/miio.tar.gz -C /miio --strip-components=1 && rm /tmp/miio.tar.gz
RUN poetry install
RUN poetry add paho-mqtt
ADD tvoc /usr/bin
ENTRYPOINT poetry run python /usr/bin/tvoc

Running this yields

Jun 21 07:12:58 iot-gateway docker[226357]: Request
Jun 21 07:12:59 iot-gateway docker[226357]: Found an unsupported model 'zhimi.airpurifier.za1' for class 'AirPurifierMiot'. If this is working for you, please open an issue at https://github.com/rytilahti/python-miio/

Not sure what else would be missing to drop this, but it works fine otherwise. And for really unsupported models one would additionally get:

WARNING:miio.miot_device:Unable to find mapping for zhimi.airpurifier.za1, falling back to xiaomi.aircondition.mc1

Co-authored-by: Teemu R. <tpr@iki.fi>
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.

LGTM, let's get this into the next release, thanks @julian-klode! 👍

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 new device support - Smartmi Air Purifier
3 participants