Use shared clientsession for sense (#46419)

This commit is contained in:
J. Nick Koston 2021-02-15 10:35:58 -10:00 committed by GitHub
parent e3ae3cfb83
commit 6f4df7e52e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 6 deletions

View file

@ -2,7 +2,7 @@
"domain": "emulated_kasa", "domain": "emulated_kasa",
"name": "Emulated Kasa", "name": "Emulated Kasa",
"documentation": "https://www.home-assistant.io/integrations/emulated_kasa", "documentation": "https://www.home-assistant.io/integrations/emulated_kasa",
"requirements": ["sense_energy==0.8.1"], "requirements": ["sense_energy==0.9.0"],
"codeowners": ["@kbickar"], "codeowners": ["@kbickar"],
"quality_scale": "internal" "quality_scale": "internal"
} }

View file

@ -14,6 +14,7 @@ from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, CONF_TIMEOUT from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, CONF_TIMEOUT
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.event import async_track_time_interval
@ -96,7 +97,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
password = entry_data[CONF_PASSWORD] password = entry_data[CONF_PASSWORD]
timeout = entry_data[CONF_TIMEOUT] timeout = entry_data[CONF_TIMEOUT]
gateway = ASyncSenseable(api_timeout=timeout, wss_timeout=timeout) client_session = async_get_clientsession(hass)
gateway = ASyncSenseable(
api_timeout=timeout, wss_timeout=timeout, client_session=client_session
)
gateway.rate_limit = ACTIVE_UPDATE_RATE gateway.rate_limit = ACTIVE_UPDATE_RATE
try: try:

View file

@ -6,6 +6,7 @@ import voluptuous as vol
from homeassistant import config_entries, core from homeassistant import config_entries, core
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, CONF_TIMEOUT from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, CONF_TIMEOUT
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import ACTIVE_UPDATE_RATE, DEFAULT_TIMEOUT, SENSE_TIMEOUT_EXCEPTIONS from .const import ACTIVE_UPDATE_RATE, DEFAULT_TIMEOUT, SENSE_TIMEOUT_EXCEPTIONS
from .const import DOMAIN # pylint:disable=unused-import; pylint:disable=unused-import from .const import DOMAIN # pylint:disable=unused-import; pylint:disable=unused-import
@ -27,8 +28,11 @@ async def validate_input(hass: core.HomeAssistant, data):
Data has the keys from DATA_SCHEMA with values provided by the user. Data has the keys from DATA_SCHEMA with values provided by the user.
""" """
timeout = data[CONF_TIMEOUT] timeout = data[CONF_TIMEOUT]
client_session = async_get_clientsession(hass)
gateway = ASyncSenseable(api_timeout=timeout, wss_timeout=timeout) gateway = ASyncSenseable(
api_timeout=timeout, wss_timeout=timeout, client_session=client_session
)
gateway.rate_limit = ACTIVE_UPDATE_RATE gateway.rate_limit = ACTIVE_UPDATE_RATE
await gateway.authenticate(data[CONF_EMAIL], data[CONF_PASSWORD]) await gateway.authenticate(data[CONF_EMAIL], data[CONF_PASSWORD])

View file

@ -2,7 +2,7 @@
"domain": "sense", "domain": "sense",
"name": "Sense", "name": "Sense",
"documentation": "https://www.home-assistant.io/integrations/sense", "documentation": "https://www.home-assistant.io/integrations/sense",
"requirements": ["sense_energy==0.8.1"], "requirements": ["sense_energy==0.9.0"],
"codeowners": ["@kbickar"], "codeowners": ["@kbickar"],
"config_flow": true, "config_flow": true,
"dhcp": [{"hostname":"sense-*","macaddress":"009D6B*"}, {"hostname":"sense-*","macaddress":"DCEFCA*"}] "dhcp": [{"hostname":"sense-*","macaddress":"009D6B*"}, {"hostname":"sense-*","macaddress":"DCEFCA*"}]

View file

@ -2010,7 +2010,7 @@ sense-hat==2.2.0
# homeassistant.components.emulated_kasa # homeassistant.components.emulated_kasa
# homeassistant.components.sense # homeassistant.components.sense
sense_energy==0.8.1 sense_energy==0.9.0
# homeassistant.components.sentry # homeassistant.components.sentry
sentry-sdk==0.20.1 sentry-sdk==0.20.1

View file

@ -1026,7 +1026,7 @@ scapy==2.4.4
# homeassistant.components.emulated_kasa # homeassistant.components.emulated_kasa
# homeassistant.components.sense # homeassistant.components.sense
sense_energy==0.8.1 sense_energy==0.9.0
# homeassistant.components.sentry # homeassistant.components.sentry
sentry-sdk==0.20.1 sentry-sdk==0.20.1