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

Change Honeywell somecomfort API to AIOSomecomfort API #86102

Merged
merged 8 commits into from
Jan 18, 2023

Conversation

mkmer
Copy link
Contributor

@mkmer mkmer commented Jan 17, 2023

Proposed change

Move to AIOSomecomfort API - ported from https://github.com/kk7ds/somecomfort requests based API
Remove rate limit, updating at 10 seconds vs 5 minutes
Use HASS clientsession for aiohttp.

Type of change

  • Dependency upgrade: mkmer/AIOSomecomfort@main...0.0.2
  • 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
  • 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

Hey there @rdfurman, mind taking a look at this pull request as it has been labeled with an integration (honeywell) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of honeywell can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Change the title of the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign honeywell Removes the current integration label and assignees on the issue, add the integration domain after the command.

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.

LGTM, I'd like a second opinion about the library change though

homeassistant/components/honeywell/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/honeywell/__init__.py Outdated Show resolved Hide resolved
@emontnemery emontnemery added the second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. label Jan 18, 2023
mkmer and others added 2 commits January 18, 2023 06:48
remove "todo" from code

Co-authored-by: Erik Montnemery <erik@montnemery.com>
@mkmer
Copy link
Contributor Author

mkmer commented Jan 18, 2023

There's a lot "bad" about the old library :)
Found via debuging the web page connections that we are only "API limited" when logging in and hitting web pages... we can refresh fast all day. 10 seconds may be a bit to fast, maybe move to 30 sec (although that's the rate on the web page).

This will be multi part for sure - next PR will be to add the reauth flow, and follow on PR's to address issues in the backlog.

update devices per entity
rework retry login
@emontnemery emontnemery removed the second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. label Jan 18, 2023
@emontnemery emontnemery merged commit 5e6ba59 into home-assistant:dev Jan 18, 2023
@mkmer mkmer deleted the AIOSomecomfort branch January 18, 2023 15:04
@rdfurman
Copy link
Contributor

Thank the lord someone with some python experience came to rescue this integration haha! I was really flailing around here and was getting pretty demotivated to work on it.

Awesome job moving the backing library (somecomfort) to AIO. For some reason I thought it would need a full rewrite but it looks like you were able to keep the majority of the old code and integrate AIO. I was struggling with trying to learn how to create a new python library project and get that all uploaded to pypi.org and everything.

This is awesome news, hopefully everything will work better now that you've determined the root cause (login endpoint having a rate limit). I will message you outside of this PR to talk about some of the other major issues and goals I had with this integration modernization project. I see now I may have bitten off more than I can chew alone, but now that you're here perhaps we can get this thing working like a well oiled machine.

Once again, great work and thanks for taking this on!

@mkmer
Copy link
Contributor Author

mkmer commented Jan 18, 2023

@rdfurman : chat on discord is best. mkmer#0872

Glad to be of assistance - as usual, it's mostly a selfish activity, but why not share :)
I'm no python expert, but have been tinkering with HA and python for long enough to get somewhere.

I've been looking at the backlog of issues - I think we can fix many of them up fairly quickly now that we have control of the API.

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Please address the comments in a new PR. Thanks!

@MartinHjelmare
Copy link
Member

Found via debuging the web page connections that we are only "API limited" when logging in and hitting web pages... we can refresh fast all day.

Does this mean that there's a local API in use for some of the requests and only some requests are going to the cloud?

@mkmer
Copy link
Contributor Author

mkmer commented Jan 19, 2023

Unfortunately, there is not a local API. The original somecomfort requests based API was refreshing web pages and re-logging in multiple times - this was triggering an API rate limit from Honeywell. Only logging in when the session keys have been expired prevents hitting the API limit. Polling the device parameters with device.refresh() can be run as fast as 1 second, but the web page updates at 10 seconds (so I did the same).

@MartinHjelmare
Copy link
Member

Polling a cloud API at 10 seconds sounds excessive even if we're not rate limited at the moment. I'd recommend using a longer update interval, eg 30 seconds, unless there is documentation that says that 10 seconds is allowed.

@mkmer
Copy link
Contributor Author

mkmer commented Jan 19, 2023

I was thinking that was a bit fast... but that's what they are doing :)
I'll move it to 30 - still way better than 5 minutes.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 20, 2023
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.

4 participants