8000 Fix synology by jgriff2 · Pull Request #4296 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Closed
wants to merge 8 commits into from
Closed

Fix synology #4296

wants to merge 8 commits into from

Conversation

jgriff2
Copy link
Contributor
@jgriff2 jgriff2 commented Nov 7, 2016

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:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

@mention-bot
Copy link

@jgriff2, thanks for your PR! By analyzing the history of the files in this pull request, we identified @pvizeli and @balloob to be potential reviewers.

@pvizeli
Copy link
Member
pvizeli commented Nov 7, 2016

Don't make a ClientSession for each call. Use like that:

DATA_SYNOLOGY_WEBSESSION = 'synology_websession'
...
hass.data[DATA_SYNOLOGY_WEBSESSION] = aiohttp.ClientSession(...)

now you can use this session with hass.data

@jgriff2
Copy link
Contributor Author
jgriff2 commented Nov 8, 2016

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.

@pvizeli
Copy link
Member
pvizeli commented Nov 8, 2016

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.

@jgriff2
Copy link
Contributor Author
jgriff2 commented Nov 8, 2016

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)
Copy link
Member

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.

Copy link
Contributor Author

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(
Copy link
Member

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)

Copy link
Contributor Author

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?

Copy link
Member

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:
Copy link
Member

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

Copy link
Contributor Author

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(
Copy link
Member

Choose a reason for hiding this comment

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

Deprecated. Use session

Copy link
Contributor Author

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(
Copy link
Member

Choose a reason for hiding this comment

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

Deprecated. Use session

@balloob balloob closed this Nov 11, 2016
@home-assistant home-assistant locked and limited conversation to collaborators Mar 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0