mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Use async_create_clientsession for enigma2 (#108395)
Use async_creeate_clientsession for enigma2
This commit is contained in:
parent
2b389739d3
commit
b612fafb9b
@ -5,6 +5,7 @@ from aiohttp.client_exceptions import ClientConnectorError
|
||||
from openwebif.api import OpenWebIfDevice
|
||||
from openwebif.enums import RemoteControlCodes, SetVolumeOption
|
||||
import voluptuous as vol
|
||||
from yarl import URL
|
||||
|
||||
from homeassistant.components.media_player import (
|
||||
MediaPlayerEntity,
|
||||
@ -22,6 +23,7 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
from homeassistant.helpers.aiohttp_client import async_create_clientsession
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
@ -88,12 +90,18 @@ async def async_setup_platform(
|
||||
config[CONF_DEEP_STANDBY] = DEFAULT_DEEP_STANDBY
|
||||
config[CONF_SOURCE_BOUQUET] = DEFAULT_SOURCE_BOUQUET
|
||||
|
||||
device = OpenWebIfDevice(
|
||||
base_url = URL.build(
|
||||
scheme="https" if config[CONF_SSL] else "http",
|
||||
host=config[CONF_HOST],
|
||||
port=config.get(CONF_PORT),
|
||||
username=config.get(CONF_USERNAME),
|
||||
user=config.get(CONF_USERNAME),
|
||||
password=config.get(CONF_PASSWORD),
|
||||
is_https=config[CONF_SSL],
|
||||
)
|
||||
|
||||
session = async_create_clientsession(hass, verify_ssl=False, base_url=base_url)
|
||||
|
||||
device = OpenWebIfDevice(
|
||||
host=session,
|
||||
turn_off_to_deep=config.get(CONF_DEEP_STANDBY),
|
||||
source_bouquet=config.get(CONF_SOURCE_BOUQUET),
|
||||
)
|
||||
@ -101,7 +109,6 @@ async def async_setup_platform(
|
||||
try:
|
||||
about = await device.get_about()
|
||||
except ClientConnectorError as err:
|
||||
await device.close()
|
||||
raise PlatformNotReady from err
|
||||
|
||||
async_add_entities([Enigma2Device(config[CONF_NAME], device, about)])
|
||||
|
Loading…
x
Reference in New Issue
Block a user