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

Neato reduce API calls #29156

Merged
merged 3 commits into from Dec 1, 2019
Merged

Conversation

@Santobert
Copy link
Member

Santobert commented Nov 27, 2019

Breaking Change:

Nothing breaks

Description:

The neato integration does a lot of unnecessary api calls. We try to reduce them by caching requested data. This let us reduce the maximal number of updates.

Related issue (if applicable): related to: #29035

Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#<home-assistant.io PR number goes here>

Example entry for configuration.yaml (if applicable):

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist

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. Update and include derived files by running python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.
@probot-home-assistant

This comment has been minimized.

Copy link

probot-home-assistant bot commented Nov 27, 2019

Hey there @dshokouhi, mind taking a look at this pull request as its been labeled with a integration (neato) you are listed as a codeowner for? Thanks!

@project-bot project-bot bot moved this from Needs review to By Code Owner in Dev Nov 27, 2019
@Santobert

This comment has been minimized.

Copy link
Member Author

Santobert commented Nov 27, 2019

@dshokouhi I noticed that we won't use the results of self.neato.update_robots() so I removed it for now. This shouldn't be the goal, obviously. Unfortunately pybotvac doesn't cache data. It always asks the API when we try to access attributes of self.robot. The best solution would it be to handle all IO in NeatoHub and write requested information into a dict. The platforms itself only use the dict then. What do you think?

@Santobert Santobert moved this from By Code Owner to Incoming in Dev Nov 27, 2019
Copy link
Contributor

dshokouhi left a comment

Just a very minor comment, not necessary to change for this PR just something to think about. Nice find to cut down on the calls!

@Santobert

This comment has been minimized.

Copy link
Member Author

Santobert commented Nov 27, 2019

@dshokouhi I'm still not sure how to cache requested attributes. If we don't want to edit pybotvac we have to do in in NeatoHub. Feel free to add comments or commits 😄

@dshokouhi

This comment has been minimized.

Copy link
Contributor

dshokouhi commented Nov 27, 2019

@Santobert that was actually my original reasoning for having the camera and switch with a higher scan interval than the vacuum platform. Somethings don't need to update as often. Maybe instead of keeping the same default scan interval we change it? The camera for example does not need to update every 5 min, I previously had it at 10 because the only time it updates is when the map is new. Also some of the attributes under the vacuum only update as the map updates so maybe we want to move those attributes to the camera?

@balloob

This comment has been minimized.

Copy link
Member

balloob commented Nov 27, 2019

Why wouldn't you want to update pybotvac to make it easier to cache ?

@Santobert

This comment has been minimized.

Copy link
Member Author

Santobert commented Nov 27, 2019

Thats not yet decided. It depends on the current code base. Since pybotvac does IO within it's property methods every caching belongs there. Otherwise we have to duplicate most of the data using our own objects or dicts. But this requires to break parts of pybotvacs API. This decision still needs some research, I guess.

@Santobert

This comment has been minimized.

Copy link
Member Author

Santobert commented Nov 28, 2019

@dshokouhi what's your opinion?

Santobert added 2 commits Nov 27, 2019
@Santobert Santobert force-pushed the Santobert:neato_reduce_api_calls branch from a9f37d0 to 67612f0 Nov 29, 2019
@Santobert Santobert marked this pull request as ready for review Nov 29, 2019
@dshokouhi

This comment has been minimized.

Copy link
Contributor

dshokouhi commented Nov 29, 2019

@Santobert I think we should do more research here but best would be to update pybotvac to do what we need if we can.

@Santobert

This comment has been minimized.

Copy link
Member Author

Santobert commented Nov 29, 2019

@dshokouhi We can merge this if you have successfully tested it with your robots. The only way to further improve the situation is to change the way pybotvac works. I don't see any other way because they mix available values and API requests and hide this behind @property functions. The alternative way to improve this without editing pybotvac is to create helper objects in HA that wrap around pybotvac's objects, and that would be really ugly somehow.

@Santobert Santobert changed the title WIP: Neato reduce API calls Neato reduce API calls Nov 29, 2019
@Santobert

This comment has been minimized.

Copy link
Member Author

Santobert commented Nov 30, 2019

Can be merged. To do further improvements pybotvac needs some changes first

@Santobert

This comment has been minimized.

Copy link
Member Author

Santobert commented Nov 30, 2019

This also adds a workaround if robot.get_robot_info() does not work. This sometimes happens as mentioned here: #29239

@balloob balloob merged commit c061994 into home-assistant:dev Dec 1, 2019
11 checks passed
11 checks passed
CI #20191130.8 succeeded
Details
CI (FullCheck Mypy) FullCheck Mypy succeeded
Details
CI (FullCheck Pylint) FullCheck Pylint succeeded
Details
CI (Overview CheckFormat) Overview CheckFormat succeeded
Details
CI (Overview Lint) Overview Lint succeeded
Details
CI (Overview Validate) Overview Validate succeeded
Details
CI (Tests PyTest Python36) Tests PyTest Python36 succeeded
Details
CI (Tests PyTest Python37) Tests PyTest Python37 succeeded
Details
cla-bot Everyone involved has signed the CLA
codecov/patch Coverage not affected when comparing 04bad4b...aa08050
Details
codecov/project 94.43% (target 90%)
Details
Dev automation moved this from Incoming to Done Dec 1, 2019
@lock lock bot locked and limited conversation to collaborators Dec 2, 2019
@Santobert Santobert deleted the Santobert:neato_reduce_api_calls branch Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Dev
  
Done
4 participants
You can’t perform that action at this time.