8000 Create new websession if more than one entry in Tesla by alandtse · Pull Request #47886 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Create new websession if more than one entry in Tesla #478 8000 86

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

Merged
merged 4 commits into from
Mar 30, 2021

Conversation

alandtse
Copy link
Contributor

Breaking change

Proposed change

Detect if multiple config entries and only allowed the first config entry to use the shared ClientSession with HA. This is necessary because each account needs its own cookies.

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)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

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

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant probot-home-assistant bot added bugfix integration: tesla removed integration small-pr PRs with less than 30 lines. by-code-owner labels Mar 14, 2021
@probot-home-assistant
Copy link

Hey there @zabuldon, mind taking a look at this pull request as its been labeled with an integration (tesla) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

Copy link
Contributor
@elupus elupus left a comment

Choose a reason for hiding this comment

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

Technically I think the session should be closed if we create new one when the entry is unloaded. Same goes with the use in the config entry setup.

I'm not sure it matter much though. I think this is good enough.

@alandtse
Copy link
Contributor Author

Doesn't the auto close handle that?

@elupus
Copy link
Contributor
elupus commented Mar 16, 2021

The auto close/cleanup parameter to async_create_clientsession will cleanup on home assistant shutdown. But it won't clean up on a config entry re/un-load. So each reload of the component will leave a lingering clientsession object. Since that object shared the connection pool, it's not going to be that bad. Just a very minor memory leak.

The correct way would be to use auto_cleanup=False and explicitly call session.detach() when the entry or home assistant stops.

@balloob
I wonder if it might actually be better to always set auto_cleanup=False on created sessions. The only thing detach() does is drop a reference to the connection pool. It doesn't actually do anything more. This would be done automatically by garbage collector. HOWEVER, when auto_cleanup=True, we store a reference to this object in hass.data[] so it will never be garbage collected.

@balloob
Copy link
Member
balloob commented Mar 17, 2021

That's probably better indeed. If detach ever does something more, we would end up not calling it. But that's better.

@balloob
Copy link
Member
balloob commented Mar 17, 2021

Looking at the source, it looks like ClientSession will complain when it's not closed when it's garbage collected, but closing is a no-op when not owner of the connector.

@alandtse
Copy link
Contributor Author

Do we need to have a close_clientsession helper so clean up any data from create_clientsession?

Copy link
Contributor
@elupus elupus left a comment

Choose a reason for hiding this comment

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

That would be one option. But those is good enough.

@elupus elupus merged commit 984fb12 into home-assistant:dev Mar 30, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Mar 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bugfix by-code-owner cla-signed integration: tesla removed integration small-pr PRs with less than 30 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding more than one Tesla mixes up attributes
4 participants
0