Use generic SamsungTVBridge for SamsungTV type hints (#67942)
Co-authored-by: epenet <epenet@users.noreply.github.com>pull/67555/head^2
parent
cb7e492e81
commit
86b775e46a
|
@ -25,13 +25,7 @@ from homeassistant.exceptions import ConfigEntryNotReady
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .bridge import (
|
||||
SamsungTVBridge,
|
||||
SamsungTVLegacyBridge,
|
||||
SamsungTVWSBridge,
|
||||
async_get_device_info,
|
||||
mac_from_device_info,
|
||||
)
|
||||
from .bridge import SamsungTVBridge, async_get_device_info, mac_from_device_info
|
||||
from .const import (
|
||||
CONF_MODEL,
|
||||
CONF_ON_ACTION,
|
||||
|
@ -101,7 +95,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
@callback
|
||||
def _async_get_device_bridge(
|
||||
hass: HomeAssistant, data: dict[str, Any]
|
||||
) -> SamsungTVLegacyBridge | SamsungTVWSBridge:
|
||||
) -> SamsungTVBridge:
|
||||
"""Get device bridge."""
|
||||
return SamsungTVBridge.get_bridge(
|
||||
hass,
|
||||
|
@ -144,7 +138,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
async def _async_create_bridge_with_updated_data(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
) -> SamsungTVLegacyBridge | SamsungTVWSBridge:
|
||||
) -> SamsungTVBridge:
|
||||
"""Create a bridge object and update any missing data in the config entry."""
|
||||
updated_data: dict[str, str | int] = {}
|
||||
host: str = entry.data[CONF_HOST]
|
||||
|
|
|
@ -57,7 +57,7 @@ def mac_from_device_info(info: dict[str, Any]) -> str | None:
|
|||
|
||||
async def async_get_device_info(
|
||||
hass: HomeAssistant,
|
||||
bridge: SamsungTVWSBridge | SamsungTVLegacyBridge | None,
|
||||
bridge: SamsungTVBridge | None,
|
||||
host: str,
|
||||
) -> tuple[int | None, str | None, dict[str, Any] | None]:
|
||||
"""Fetch the port, method, and device info."""
|
||||
|
@ -87,7 +87,7 @@ class SamsungTVBridge(ABC):
|
|||
host: str,
|
||||
port: int | None = None,
|
||||
token: str | None = None,
|
||||
) -> SamsungTVLegacyBridge | SamsungTVWSBridge:
|
||||
) -> SamsungTVBridge:
|
||||
"""Get Bridge instance."""
|
||||
if method == METHOD_LEGACY or port == LEGACY_PORT:
|
||||
return SamsungTVLegacyBridge(hass, method, host, port)
|
||||
|
@ -114,7 +114,7 @@ class SamsungTVBridge(ABC):
|
|||
self._new_token_callback = func
|
||||
|
||||
@abstractmethod
|
||||
async def async_try_connect(self) -> str | None:
|
||||
async def async_try_connect(self) -> str:
|
||||
"""Try to connect to the TV."""
|
||||
|
||||
@abstractmethod
|
||||
|
|
|
@ -23,13 +23,7 @@ from homeassistant.const import (
|
|||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.device_registry import format_mac
|
||||
|
||||
from .bridge import (
|
||||
SamsungTVBridge,
|
||||
SamsungTVLegacyBridge,
|
||||
SamsungTVWSBridge,
|
||||
async_get_device_info,
|
||||
mac_from_device_info,
|
||||
)
|
||||
from .bridge import SamsungTVBridge, async_get_device_info, mac_from_device_info
|
||||
from .const import (
|
||||
CONF_MANUFACTURER,
|
||||
CONF_MODEL,
|
||||
|
@ -77,7 +71,7 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
self._name: str | None = None
|
||||
self._title: str = ""
|
||||
self._id: int | None = None
|
||||
self._bridge: SamsungTVLegacyBridge | SamsungTVWSBridge | None = None
|
||||
self._bridge: SamsungTVBridge | None = None
|
||||
self._device_info: dict[str, Any] | None = None
|
||||
|
||||
def _get_entry_from_bridge(self) -> data_entry_flow.FlowResult:
|
||||
|
|
|
@ -8,7 +8,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.const import CONF_TOKEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .bridge import SamsungTVLegacyBridge, SamsungTVWSBridge
|
||||
from .bridge import SamsungTVBridge
|
||||
from .const import DOMAIN
|
||||
|
||||
TO_REDACT = {CONF_TOKEN}
|
||||
|
@ -18,9 +18,7 @@ async def async_get_config_entry_diagnostics(
|
|||
hass: HomeAssistant, entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
bridge: SamsungTVLegacyBridge | SamsungTVWSBridge = hass.data[DOMAIN][
|
||||
entry.entry_id
|
||||
]
|
||||
bridge: SamsungTVBridge = hass.data[DOMAIN][entry.entry_id]
|
||||
return {
|
||||
"entry": async_redact_data(entry.as_dict(), TO_REDACT),
|
||||
"device_info": await bridge.async_device_info(),
|
||||
|
|
|
@ -36,7 +36,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
from homeassistant.helpers.script import Script
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .bridge import SamsungTVLegacyBridge, SamsungTVWSBridge
|
||||
from .bridge import SamsungTVBridge, SamsungTVWSBridge
|
||||
from .const import (
|
||||
CONF_MANUFACTURER,
|
||||
CONF_MODEL,
|
||||
|
@ -92,7 +92,7 @@ class SamsungTVDevice(MediaPlayerEntity):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
bridge: SamsungTVLegacyBridge | SamsungTVWSBridge,
|
||||
bridge: SamsungTVBridge,
|
||||
config_entry: ConfigEntry,
|
||||
on_script: Script | None,
|
||||
) -> None:
|
||||
|
|
Loading…
Reference in New Issue