-
-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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
Opower: Call async_create_clientsession instead of async_get_clientsession #97541
Conversation
@@ -50,7 +50,7 @@ def __init__( | |||
update_interval=timedelta(hours=12), | |||
) | |||
self.api = Opower( | |||
aiohttp_client.async_get_clientsession(hass), | |||
aiohttp_client.async_create_clientsession(hass), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, why is that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure. The 2 core bugs fail for the same reason. The library fails to parse the login page but only while getting updated data, not in the config flow. The only difference is the config flow creates its own session while coordinator uses a common session. I suspect it's because the library modifies the default user agent instead of specifying it on every HTTP request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect it's because the library modifies the default user agent instead of specifying it on every HTTP request.
That sounds familiar! Got a pointer to me for that upstream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aah yes, that shouldn't be used/set and, indeed passed on request.
We've "monkeypatched" it in Home Assistant to prevent it to work, as modifying internals of shared sessions like that causes issues (and has caused many issues in the past).
Ref:
core/homeassistant/helpers/aiohttp_client.py
Line 148 in a8a3b67
clientsession._default_headers = MappingProxyType( # type: ignore[assignment] |
TBH, from that perspective, I don't agree on the solution provided in this PR. I think we should update upstream to pass the headers in on request.
../Frenck
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I modified the library to pass the headers in each request and created #97548 to bump the dependency
Proposed change
Call async_create_clientsession instead of async_get_clientsession in the coordinator.py. config_flow.py calls async_create_clientsession and login works there.
This is an attempt to fix tronikos/opower-hacs#10, #97516, and #97349
Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: