-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Fix synology #4296
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
Fix synology #4296
Conversation
This reverts commit b8dc2a92abee6249b3dd42c99d0786820ebbeb72.
This reverts commit 805e87f3af300a1b7627bb5df0792285fcf38901.
Don't make a ClientSession for each call. Use like that:
now you can use this session with hass.data |
The problem is every time the cookie needs to change I need a new ClientSession since that seems to be the only place I can set cookie contents. |
That is wrong. You can set Cookies also in request, http://aiohttp.readthedocs.io/en/stable/client_reference.html#basic-api You need only a own request, if SSL is not verify. |
Okay. I had assumed that the change to ClientSession was done with intent and was trying to preserve it. I'll dump ClientSession and change it to the Basic API |
@@ -146,7 +151,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None): | |||
tasks.append(device.async_read_sid()) | |||
devices.append(device) | |||
|
|||
yield from asyncio.wait(tasks, loop=hass.loop) | |||
yield from asyncio.gather(*tasks, loop=hass.loop) |
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.
Why change this to gather? You're not using the return value.
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.
No idea. I don't think I changed this, I must have started with the wrong code base.
@@ -164,10 +169,12 @@ def get_session_id(hass, username, password, login_url, valid_cert): | |||
} | |||
try: | |||
with async_timeout.timeout(TIMEOUT, loop=hass.loop): | |||
auth_req = yield from hass.websession.get( | |||
auth_req = yield from aiohttp.get( |
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.
This method has been deprecated. You have to use a session instead.
See my example here #4257 (comment)
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.
But then I need a new ClientSession every time the cookie changes. pvizeli keeps linking me to the deprecated aiohttp.get and telling me it accepts cookies. ClientSession.get doesn't accept cookies, it has to be set in the connector. I seem to be getting conflicting direction here. Do I use aiohttp.get and pass the cookie, or create a new ClientSession for every connection that needs a different cookie?
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.
ClientSession
parse get
to request
and that support cookies. That is the same stuff with auth
, you can set it on ClientSession
global for all requests or selected only on get/post/... -> request
.
@@ -212,6 +221,14 @@ def async_read_sid(self): | |||
self._valid_cert | |||
) | |||
|
|||
def websession(self): | |||
"""Create a Client Session.""" | |||
if self._websession is None: |
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.
Only create a websession if we need one because we have to disable verify_ssl
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.
Except I need a different connector to pass the cookie. aiohttp.get accepts cookies, but aiohttp.clientsession.get does not take a cookie parameter, only the connector does.
@@ -231,10 +248,11 @@ def async_camera_image(self): | |||
} | |||
try: | |||
with async_timeout.timeout(TIMEOUT, loop=self.hass.loop): | |||
response = yield from self.hass.websession.get( | |||
response = yield from aiohttp.get( |
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.
Deprecated. Use session
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.
See above issue around cookies. pvizeli recommended to use this.
@@ -260,10 +278,11 @@ def handle_async_mjpeg_stream(self, request): | |||
} | |||
try: | |||
with async_timeout.timeout(TIMEOUT, loop=self.hass.loop): | |||
stream = yield from self.hass.websession.get( | |||
stream = yield from aiohttp.get( |
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.
Deprecated. Use session
Description:
Related issue (if applicable): fixes #
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.github.io#<home-assistant.github.io PR number goes here>
Example entry for
configuration.yaml
(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
tox
run successfully. Your PR cannot be merged unless tests passREQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.If the code does not interact with devices:
tox
run successfully. Your PR cannot be merged unless tests pass