mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
[device.upc_connect] Discount on STOP. (#5553)
* [device.upc_connect] Discount on STOP. * close session it self * Update upc_connect.py
This commit is contained in:
parent
6015274ee2
commit
393c7f2cf1
@ -12,6 +12,7 @@ import aiohttp
|
|||||||
import async_timeout
|
import async_timeout
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.components.device_tracker import (
|
from homeassistant.components.device_tracker import (
|
||||||
DOMAIN, PLATFORM_SCHEMA, DeviceScanner)
|
DOMAIN, PLATFORM_SCHEMA, DeviceScanner)
|
||||||
@ -29,6 +30,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
})
|
})
|
||||||
|
|
||||||
CMD_LOGIN = 15
|
CMD_LOGIN = 15
|
||||||
|
CMD_LOGOUT = 16
|
||||||
CMD_DEVICES = 123
|
CMD_DEVICES = 123
|
||||||
|
|
||||||
|
|
||||||
@ -62,7 +64,21 @@ class UPCDeviceScanner(DeviceScanner):
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.websession = async_create_clientsession(
|
self.websession = async_create_clientsession(
|
||||||
hass, cookie_jar=aiohttp.CookieJar(unsafe=True, loop=hass.loop))
|
hass, auto_cleanup=False,
|
||||||
|
cookie_jar=aiohttp.CookieJar(unsafe=True, loop=hass.loop)
|
||||||
|
)
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def async_logout(event):
|
||||||
|
"""Logout from upc connect box."""
|
||||||
|
try:
|
||||||
|
yield from self._async_ws_function(CMD_LOGOUT)
|
||||||
|
self.token = None
|
||||||
|
finally:
|
||||||
|
self.websession.detach()
|
||||||
|
|
||||||
|
hass.buss.async_listen_once(
|
||||||
|
EVENT_HOMEASSISTANT_STOP, async_logout)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_scan_devices(self):
|
def async_scan_devices(self):
|
||||||
@ -94,6 +110,7 @@ class UPCDeviceScanner(DeviceScanner):
|
|||||||
response = None
|
response = None
|
||||||
try:
|
try:
|
||||||
# get first token
|
# get first token
|
||||||
|
self.websession.cookie_jar.clear()
|
||||||
with async_timeout.timeout(10, loop=self.hass.loop):
|
with async_timeout.timeout(10, loop=self.hass.loop):
|
||||||
response = yield from self.websession.get(
|
response = yield from self.websession.get(
|
||||||
"http://{}/common_page/login.html".format(self.host)
|
"http://{}/common_page/login.html".format(self.host)
|
||||||
|
@ -17,6 +17,8 @@ class AiohttpClientMocker:
|
|||||||
self._cookies = {}
|
self._cookies = {}
|
||||||
self.mock_calls = []
|
self.mock_calls = []
|
||||||
|
|
||||||
|
self.cookie_jar = mock.MagicMock()
|
||||||
|
|
||||||
def request(self, method, url, *,
|
def request(self, method, url, *,
|
||||||
auth=None,
|
auth=None,
|
||||||
status=200,
|
status=200,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user