Bump aiowebostv to 0.6.0 (#136206)

This commit is contained in:
Shay Levy 2025-01-23 14:51:24 +02:00 committed by GitHub
parent 40ed0562bc
commit 66f945e852
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 34 additions and 28 deletions

View File

@ -19,6 +19,7 @@ from homeassistant.const import (
from homeassistant.core import Event, HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers import config_validation as cv, discovery
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.typing import ConfigType
from .const import (
@ -50,7 +51,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: WebOsTvConfigEntry) -> b
key = entry.data[CONF_CLIENT_SECRET]
# Attempt a connection, but fail gracefully if tv is off for example.
entry.runtime_data = client = WebOsClient(host, key)
entry.runtime_data = client = WebOsClient(
host, key, client_session=async_get_clientsession(hass)
)
with suppress(*WEBOSTV_EXCEPTIONS):
try:
await client.connect()
@ -96,9 +99,15 @@ async def async_update_options(hass: HomeAssistant, entry: WebOsTvConfigEntry) -
await hass.config_entries.async_reload(entry.entry_id)
async def async_control_connect(host: str, key: str | None) -> WebOsClient:
async def async_control_connect(
hass: HomeAssistant, host: str, key: str | None
) -> WebOsClient:
"""LG Connection."""
client = WebOsClient(host, key)
client = WebOsClient(
host,
key,
client_session=async_get_clientsession(hass),
)
try:
await client.connect()
except WebOsTvPairError:

View File

@ -69,7 +69,7 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
if user_input is not None:
try:
client = await async_control_connect(self._host, None)
client = await async_control_connect(self.hass, self._host, None)
except WebOsTvPairError:
errors["base"] = "error_pairing"
except WEBOSTV_EXCEPTIONS:
@ -130,7 +130,7 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
if user_input is not None:
try:
client = await async_control_connect(self._host, None)
client = await async_control_connect(self.hass, self._host, None)
except WebOsTvPairError:
errors["base"] = "error_pairing"
except WEBOSTV_EXCEPTIONS:
@ -154,7 +154,7 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
client_key = reconfigure_entry.data.get(CONF_CLIENT_SECRET)
try:
client = await async_control_connect(host, client_key)
client = await async_control_connect(self.hass, host, client_key)
except WebOsTvPairError:
errors["base"] = "error_pairing"
except WEBOSTV_EXCEPTIONS:
@ -195,7 +195,7 @@ class OptionsFlowHandler(OptionsFlow):
options_input = {CONF_SOURCES: user_input[CONF_SOURCES]}
return self.async_create_entry(title="", data=options_input)
# Get sources
sources_list = await async_get_sources(self.host, self.key)
sources_list = await async_get_sources(self.hass, self.host, self.key)
if not sources_list:
errors["base"] = "cannot_retrieve"

View File

@ -2,8 +2,8 @@
import asyncio
import aiohttp
from aiowebostv import WebOsTvCommandError
from websockets.exceptions import ConnectionClosed, ConnectionClosedOK
from homeassistant.const import Platform
@ -27,11 +27,10 @@ SERVICE_SELECT_SOUND_OUTPUT = "select_sound_output"
LIVE_TV_APP_ID = "com.webos.app.livetv"
WEBOSTV_EXCEPTIONS = (
OSError,
ConnectionClosed,
ConnectionClosedOK,
ConnectionRefusedError,
ConnectionResetError,
WebOsTvCommandError,
TimeoutError,
aiohttp.ClientConnectorError,
aiohttp.ServerDisconnectedError,
asyncio.CancelledError,
asyncio.TimeoutError,
)

View File

@ -72,10 +72,10 @@ def async_get_client_by_device_entry(
)
async def async_get_sources(host: str, key: str) -> list[str]:
async def async_get_sources(hass: HomeAssistant, host: str, key: str) -> list[str]:
"""Construct sources list."""
try:
client = await async_control_connect(host, key)
client = await async_control_connect(hass, host, key)
except WEBOSTV_EXCEPTIONS:
return []

View File

@ -1,12 +1,12 @@
{
"domain": "webostv",
"name": "LG webOS Smart TV",
"name": "LG webOS TV",
"codeowners": ["@thecode"],
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/webostv",
"iot_class": "local_push",
"loggers": ["aiowebostv"],
"requirements": ["aiowebostv==0.5.0"],
"requirements": ["aiowebostv==0.6.0"],
"ssdp": [
{
"st": "urn:lge-com:service:webos-second-screen:1"

View File

@ -72,7 +72,5 @@ rules:
# Platinum
async-dependency: done
inject-websession:
status: todo
comment: migrate to aiohttp
inject-websession: done
strict-typing: done

View File

@ -3340,7 +3340,7 @@
"integration_type": "hub",
"config_flow": true,
"iot_class": "local_push",
"name": "LG webOS Smart TV"
"name": "LG webOS TV"
}
}
},

2
requirements_all.txt generated
View File

@ -416,7 +416,7 @@ aiowaqi==3.1.0
aiowatttime==0.1.1
# homeassistant.components.webostv
aiowebostv==0.5.0
aiowebostv==0.6.0
# homeassistant.components.withings
aiowithings==3.1.4

View File

@ -398,7 +398,7 @@ aiowaqi==3.1.0
aiowatttime==0.1.1
# homeassistant.components.webostv
aiowebostv==0.5.0
aiowebostv==0.6.0
# homeassistant.components.withings
aiowithings==3.1.4

View File

@ -107,7 +107,7 @@ async def test_options_flow_cannot_retrieve(hass: HomeAssistant, client) -> None
"""Test options config flow cannot retrieve sources."""
entry = await setup_webostv(hass)
client.connect.side_effect = ConnectionRefusedError
client.connect.side_effect = ConnectionResetError
result = await hass.config_entries.options.async_init(entry.entry_id)
await hass.async_block_till_done()
@ -141,7 +141,7 @@ async def test_form_cannot_connect(hass: HomeAssistant, client) -> None:
data=MOCK_USER_CONFIG,
)
client.connect.side_effect = ConnectionRefusedError
client.connect.side_effect = ConnectionResetError
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={}
)
@ -305,7 +305,7 @@ async def test_reauth_successful(hass: HomeAssistant, client) -> None:
("side_effect", "error"),
[
(WebOsTvPairError, "error_pairing"),
(ConnectionRefusedError, "cannot_connect"),
(ConnectionResetError, "cannot_connect"),
],
)
async def test_reauth_errors(hass: HomeAssistant, client, side_effect, error) -> None:
@ -360,7 +360,7 @@ async def test_reconfigure_successful(hass: HomeAssistant, client) -> None:
("side_effect", "error"),
[
(WebOsTvPairError, "error_pairing"),
(ConnectionRefusedError, "cannot_connect"),
(ConnectionResetError, "cannot_connect"),
],
)
async def test_reconfigure_errors(

View File

@ -125,7 +125,7 @@ async def test_icon_not_found(
("side_effect", "error"),
[
(WebOsTvPairError, "Pairing with TV failed"),
(ConnectionRefusedError, "TV unreachable"),
(ConnectionResetError, "TV unreachable"),
],
)
async def test_connection_errors(