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 Aprilaire integration #95093

Merged
merged 26 commits into from
Feb 16, 2024
Merged

Conversation

chamberlain2007
Copy link
Contributor

@chamberlain2007 chamberlain2007 commented Jun 23, 2023

Proposed change

Add a new integration to support Aprilaire smart thermostats.

This has been requested/discussed in the community forums: https://community.home-assistant.io/t/aprilaire-thermostat-8800-any-modbus-experts

This integration has been available on HACS for some time and has been tested by some community members: https://github.com/chamberlain2007/aprilaire-ha

This initial pull request adds the climate entity with core functionality. I expect additional releases to include the rest of the functionality currently available in the custom repo.

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 Black (black --fast 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.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hi @chamberlain2007

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!

homeassistant/components/aprilaire/climate.py Outdated Show resolved Hide resolved
homeassistant/components/aprilaire/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/aprilaire/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/aprilaire/entity.py Outdated Show resolved Hide resolved
Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

Some initial config, did not review everything because I'm on mobile

homeassistant/components/aprilaire/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/aprilaire/climate.py Outdated Show resolved Hide resolved
homeassistant/components/aprilaire/climate.py Outdated Show resolved Hide resolved
homeassistant/components/aprilaire/climate.py Outdated Show resolved Hide resolved
_LOGGER.exception("Unexpected exception")
errors["base"] = str(err)
else:
coordinator = AprilaireCoordinator(
Copy link
Member

Choose a reason for hiding this comment

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

I still need to see what the coordinator does, but I don't prefer to call the coordinator in the config flow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joostlek It's probably not ideal, but the complication comes from the wait_for_ready method. Due to the asynchronous nature of the connection and it being pushed based, connecting requires a multi-step process, which is what that method does. Basically, we need to wait for the data to be in the coordinator, regardless of if that is because we sent a request for it or the thermostat sent it on its own. I was thinking if it would be possible to shift the wait_for_ready method to the client (which is in the pyaprilaire package), but there is a dependence on the coordinator's state to make it work.

Considering that, I think there are two options:

  1. Leave it as-is, favoring properly testing the connection at the expense of referencing the coordinator in the config flow
  2. Make the config flow only check that the socket is accessible at the host/port combination, and not check that anything else about the connection is successful.

I think the user experience of the first option is better, avoiding adding a thermostat that doesn't actually connect, which does happen. But I welcome your thoughts.

homeassistant/components/aprilaire/entity.py Show resolved Hide resolved
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft September 13, 2023 09:39
homeassistant/components/aprilaire/coordinator.py Outdated Show resolved Hide resolved
"""Stop listening for data."""
self.client.stop_listen()

async def wait_for_ready(
Copy link
Member

Choose a reason for hiding this comment

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

I am no expert on this, but maybe you can create a task for everything you wait for and use it with asyncio.gather. But I am not sure if that is something good to use here. But just putting it out here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joostlek It is possible to, but the complication here is that the connection doesn't work in a request/response manner like you might expect. Packets are sent to the thermostat with no acknowledgement or response, and at some point in the future the thermostat sends an altogether separate packet with the data. Additionally, the thermostat is very sensitive to receiving too many packets at once, which can cause it to ignore some, send errors, or in a worst-case scenario lock up entirely. So, sending these serially here is in my opinion the best approach, though it definitely is not the cleanest from a code perspective.

homeassistant/components/aprilaire/entity.py Outdated Show resolved Hide resolved
homeassistant/components/aprilaire/entity.py Outdated Show resolved Hide resolved
@home-assistant home-assistant deleted a comment from joostlek Sep 13, 2023
homeassistant/components/aprilaire/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/aprilaire/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/aprilaire/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/aprilaire/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/aprilaire/entity.py Outdated Show resolved Hide resolved
homeassistant/components/aprilaire/entity.py Show resolved Hide resolved
homeassistant/components/aprilaire/entity.py Outdated Show resolved Hide resolved
homeassistant/components/aprilaire/entity.py Outdated Show resolved Hide resolved
homeassistant/components/aprilaire/manifest.json Outdated Show resolved Hide resolved
@home-assistant home-assistant deleted a comment from joostlek Sep 13, 2023
@home-assistant home-assistant deleted a comment from joostlek Sep 13, 2023
@home-assistant home-assistant deleted a comment from joostlek Sep 13, 2023
tests/components/aprilaire/conftest.py Outdated Show resolved Hide resolved
@chamberlain2007 chamberlain2007 marked this pull request as ready for review September 16, 2023 00:13
Copy link
Contributor

@emontnemery emontnemery 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 now @chamberlain2007 👍

Just a few minor comments, then this is good to go.
Please also consider this: #95093 (comment)

homeassistant/components/aprilaire/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/aprilaire/entity.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft January 25, 2024 09:50
@chamberlain2007 chamberlain2007 marked this pull request as ready for review January 28, 2024 20:58
Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

Not sure why we inherit the BaseCoordinatorEntity

homeassistant/components/aprilaire/entity.py Show resolved Hide resolved
homeassistant/components/aprilaire/entity.py Show resolved Hide resolved
@jonoberheide
Copy link
Contributor

Looks like all the requested changes have been incorporated/resolved? Anything remaining blocking a merge?

@nberardi
Copy link

@emontnemery @edenhaus @IsakNyberg any chance you could take a look at this and provide next steps for @chamberlain2007 ?

@edenhaus
Copy link
Contributor

@nberardi Please don't ping others asking for a review. Instead, could you help review other PRs so the total number goes down?

Copy link
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @chamberlain2007 👍

@emontnemery emontnemery dismissed stale reviews from edenhaus and joostlek February 13, 2024 13:10

Stale review

@emontnemery emontnemery reopened this Feb 14, 2024
@emontnemery
Copy link
Contributor

@chamberlain2007 can you look into the failing ruff check please?

Co-authored-by: Jon Oberheide <506986+jonoberheide@users.noreply.github.com>
@emontnemery emontnemery reopened this Feb 15, 2024
@nberardi
Copy link

Apologies for the 11th hour request.

I noticed that the ‘humidifier’ entity isn’t being used for the Humidifier or Dehumidifier integrations. And the ‘weather’ entity isn’t being used for the outside temp and humidity sensors. The Ecobee integration is a great example of both integrations.

It would be great if these were added in for the initial release, or at the very least a fast follow to reduce as many migrations as possible farther down the line. @chamberlain2007

Other integrations such as Aux/Emergency heat can be added in later without worrying about migration of entities later.

@chamberlain2007
Copy link
Contributor Author

Apologies for the 11th hour request.

I noticed that the ‘humidifier’ entity isn’t being used for the Humidifier or Dehumidifier integrations. And the ‘weather’ entity isn’t being used for the outside temp and humidity sensors. The Ecobee integration is a great example of both integrations.

It would be great if these were added in for the initial release, or at the very least a fast follow to reduce as many migrations as possible farther down the line. @chamberlain2007

Other integrations such as Aux/Emergency heat can be added in later without worrying about migration of entities later.

The Home Assistant team prefers starting an integration with a minimal set of functionality, hence this only containing the climate entity. If you use the other entities, I would recommend staying with the unofficial version until everything is implemented here.

@emontnemery emontnemery merged commit ce8cf31 into home-assistant:dev Feb 16, 2024
53 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Feb 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants