Async clientsession / fix stuff on aiohttp and camera platform (#4084)

* add websession

* convert to websession

* convert camera to async

* fix lint

* fix spell

* add import

* create task to loop

* fix test

* update aiohttp

* fix tests part 2

* Update aiohttp.py
This commit is contained in:
Pascal Vizeli 2016-10-28 06:40:10 +02:00 committed by Paulus Schoutsen
parent 85747fe2ef
commit 3324995e70
5 changed files with 199 additions and 121 deletions

View file

@ -71,11 +71,11 @@ class MjpegCamera(Camera):
self._password = device_info.get(CONF_PASSWORD)
self._mjpeg_url = device_info[CONF_MJPEG_URL]
auth = None
self._auth = None
if self._authentication == HTTP_BASIC_AUTHENTICATION:
auth = aiohttp.BasicAuth(self._username, password=self._password)
self._session = aiohttp.ClientSession(loop=hass.loop, auth=auth)
self._auth = aiohttp.BasicAuth(
self._username, password=self._password
)
def camera_image(self):
"""Return a still image response from the camera."""
@ -103,7 +103,10 @@ class MjpegCamera(Camera):
# connect to stream
try:
with async_timeout.timeout(10, loop=self.hass.loop):
stream = yield from self._session.get(self._mjpeg_url)
stream = yield from self.hass.websession.get(
self._mjpeg_url,
auth=self._auth
)
except asyncio.TimeoutError:
raise HTTPGatewayTimeout()