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