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 air purifiers in HomeKit #142467

Merged
merged 43 commits into from
Apr 9, 2025

Conversation

MaartenStaa
Copy link
Contributor

@MaartenStaa MaartenStaa commented Apr 7, 2025

Proposed change

This PR allows exposing fans as air purifiers in HomeKit. It is based on #82499, which was closed without merging. Fans with an attached PM2.5 sensor are automatically exposed as air purifiers, but this can be customized via the configuration. Filter life level and filter change indication can also be exposed.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

ak6i and others added 25 commits November 21, 2022 18:39
Any fan and PM2.5 in the same device will be treated as an air purifier.

type_air_purifiers.py heavily based on type_fans.py -
I tried extending type_fans.py but this looked better to me.
Any fan and PM2.5 in the same device will be treated as an air purifier.

type_air_purifiers.py heavily based on type_fans.py -
I tried extending type_fans.py but this looked better to me.
Any fan and PM2.5 in the same device will be treated as an air purifier.

type_air_purifiers.py heavily based on type_fans.py -
I tried extending type_fans.py but this looked better to me.
Any fan and PM2.5 in the same device will be treated as an air purifier.

type_air_purifiers.py heavily based on type_fans.py -
I tried extending type_fans.py but this looked better to me.
Be more explicit than assuming a fan is an air purifier if it has a PM2.5 sensor. Set defaults based on the presence of sensors.
Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @MaartenStaa

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

Tested with an Airversa AP 2 passed through from HKC to HomeKit 👍

@bdraco bdraco added the smash Indicator this PR is close to finish for merging or closing label Apr 8, 2025
@bdraco
Copy link
Member

bdraco commented Apr 8, 2025

Looks good. 0100 here so not able to fully double check though. Will test it some more tomorrow

This is already exposed as a target mode on the air purifier service itself
@bdraco
Copy link
Member

bdraco commented Apr 9, 2025

Fix looks good. We need a test for that case and I think this is good to merge. Test was already there. I didn't scroll down far enough

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

marking request changes for the test to make sure the auto switch isn't created for the air purifiers

#142467 (comment)

@home-assistant home-assistant bot marked this pull request as draft April 9, 2025 06:50
Also don't remove device class when updating state in test
@MaartenStaa MaartenStaa marked this pull request as ready for review April 9, 2025 07:03
@home-assistant home-assistant bot requested a review from bdraco April 9, 2025 07:03
@MaartenStaa
Copy link
Contributor Author

@bdraco I already accounted for this in the test, in the same commit:

if auto_preset:
    assert len(switches) == len(preset_modes) - 1
else:
    assert len(switches) == len(preset_modes)
assert "smart" in switches
assert "sleep" in switches
if auto_preset:
    assert auto_preset not in switches

I also just pushed another commit, because I noticed some errors in my log when the state was unavailable (casting to float for the linked sensor states would fail).

@bdraco
Copy link
Member

bdraco commented Apr 9, 2025

I’m going to have to pick this back up tomorrow—spent most of the day (UTC-10) debugging memory leaks and I’m pretty wiped. That said, feel free to keep things moving while I get some rest! I’m looking forward to catching up with your progress in the morning.

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

Thanks @MaartenStaa

Retested, all seems well

@bdraco bdraco merged commit 9fe306f into home-assistant:dev Apr 9, 2025
34 checks passed
@MaartenStaa MaartenStaa deleted the homekit-air-purifier branch April 10, 2025 08:57
@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed has-tests integration: homekit new-feature noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) Quality Scale: No score smash Indicator this PR is close to finish for merging or closing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants