mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Add message for unsupported models in samsungtv (#67549)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
b8420a7e3b
commit
9db3e321e4
@ -33,6 +33,7 @@ from .bridge import (
|
|||||||
mac_from_device_info,
|
mac_from_device_info,
|
||||||
)
|
)
|
||||||
from .const import (
|
from .const import (
|
||||||
|
CONF_MODEL,
|
||||||
CONF_ON_ACTION,
|
CONF_ON_ACTION,
|
||||||
DEFAULT_NAME,
|
DEFAULT_NAME,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -149,6 +150,7 @@ async def _async_create_bridge_with_updated_data(
|
|||||||
host: str = entry.data[CONF_HOST]
|
host: str = entry.data[CONF_HOST]
|
||||||
port: int | None = entry.data.get(CONF_PORT)
|
port: int | None = entry.data.get(CONF_PORT)
|
||||||
method: str | None = entry.data.get(CONF_METHOD)
|
method: str | None = entry.data.get(CONF_METHOD)
|
||||||
|
load_info_attempted = False
|
||||||
info: dict[str, Any] | None = None
|
info: dict[str, Any] | None = None
|
||||||
|
|
||||||
if not port or not method:
|
if not port or not method:
|
||||||
@ -159,6 +161,7 @@ async def _async_create_bridge_with_updated_data(
|
|||||||
# When we imported from yaml we didn't setup the method
|
# When we imported from yaml we didn't setup the method
|
||||||
# because we didn't know it
|
# because we didn't know it
|
||||||
port, method, info = await async_get_device_info(hass, None, host)
|
port, method, info = await async_get_device_info(hass, None, host)
|
||||||
|
load_info_attempted = True
|
||||||
if not port or not method:
|
if not port or not method:
|
||||||
raise ConfigEntryNotReady(
|
raise ConfigEntryNotReady(
|
||||||
"Failed to determine connection method, make sure the device is on."
|
"Failed to determine connection method, make sure the device is on."
|
||||||
@ -171,12 +174,14 @@ async def _async_create_bridge_with_updated_data(
|
|||||||
bridge = _async_get_device_bridge(hass, {**entry.data, **updated_data})
|
bridge = _async_get_device_bridge(hass, {**entry.data, **updated_data})
|
||||||
|
|
||||||
mac: str | None = entry.data.get(CONF_MAC)
|
mac: str | None = entry.data.get(CONF_MAC)
|
||||||
|
model: str | None = entry.data.get(CONF_MODEL)
|
||||||
|
if (not mac or not model) and not load_info_attempted:
|
||||||
|
info = await bridge.async_device_info()
|
||||||
|
|
||||||
if not mac:
|
if not mac:
|
||||||
LOGGER.debug("Attempting to get mac for %s", host)
|
LOGGER.debug("Attempting to get mac for %s", host)
|
||||||
if info:
|
if info:
|
||||||
mac = mac_from_device_info(info)
|
mac = mac_from_device_info(info)
|
||||||
else:
|
|
||||||
mac = await bridge.async_mac_from_device()
|
|
||||||
|
|
||||||
if not mac:
|
if not mac:
|
||||||
mac = await hass.async_add_executor_job(
|
mac = await hass.async_add_executor_job(
|
||||||
@ -189,6 +194,22 @@ async def _async_create_bridge_with_updated_data(
|
|||||||
else:
|
else:
|
||||||
LOGGER.info("Failed to get mac for %s", host)
|
LOGGER.info("Failed to get mac for %s", host)
|
||||||
|
|
||||||
|
if not model:
|
||||||
|
LOGGER.debug("Attempting to get model for %s", host)
|
||||||
|
if info:
|
||||||
|
model = info.get("device", {}).get("modelName")
|
||||||
|
if model:
|
||||||
|
LOGGER.info("Updated model to %s for %s", model, host)
|
||||||
|
updated_data[CONF_MODEL] = model
|
||||||
|
|
||||||
|
if model and len(model) > 4 and model[4] in ("H", "J"):
|
||||||
|
LOGGER.info(
|
||||||
|
"Detected model %s for %s. Some televisions from H and J series use "
|
||||||
|
"an encrypted protocol that may not be supported in this integration",
|
||||||
|
model,
|
||||||
|
host,
|
||||||
|
)
|
||||||
|
|
||||||
if updated_data:
|
if updated_data:
|
||||||
data = {**entry.data, **updated_data}
|
data = {**entry.data, **updated_data}
|
||||||
hass.config_entries.async_update_entry(entry, data=data)
|
hass.config_entries.async_update_entry(entry, data=data)
|
||||||
|
@ -119,10 +119,6 @@ class SamsungTVBridge(ABC):
|
|||||||
async def async_device_info(self) -> dict[str, Any] | None:
|
async def async_device_info(self) -> dict[str, Any] | None:
|
||||||
"""Try to gather infos of this TV."""
|
"""Try to gather infos of this TV."""
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def async_mac_from_device(self) -> str | None:
|
|
||||||
"""Try to fetch the mac address of the TV."""
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def async_get_app_list(self) -> dict[str, str] | None:
|
async def async_get_app_list(self) -> dict[str, str] | None:
|
||||||
"""Get installed app list."""
|
"""Get installed app list."""
|
||||||
@ -169,10 +165,6 @@ class SamsungTVLegacyBridge(SamsungTVBridge):
|
|||||||
}
|
}
|
||||||
self._remote: Remote | None = None
|
self._remote: Remote | None = None
|
||||||
|
|
||||||
async def async_mac_from_device(self) -> None:
|
|
||||||
"""Try to fetch the mac address of the TV."""
|
|
||||||
return None
|
|
||||||
|
|
||||||
async def async_get_app_list(self) -> dict[str, str]:
|
async def async_get_app_list(self) -> dict[str, str]:
|
||||||
"""Get installed app list."""
|
"""Get installed app list."""
|
||||||
return {}
|
return {}
|
||||||
@ -304,11 +296,6 @@ class SamsungTVWSBridge(SamsungTVBridge):
|
|||||||
self._remote: SamsungTVWSAsyncRemote | None = None
|
self._remote: SamsungTVWSAsyncRemote | None = None
|
||||||
self._remote_lock = asyncio.Lock()
|
self._remote_lock = asyncio.Lock()
|
||||||
|
|
||||||
async def async_mac_from_device(self) -> str | None:
|
|
||||||
"""Try to fetch the mac address of the TV."""
|
|
||||||
info = await self.async_device_info()
|
|
||||||
return mac_from_device_info(info) if info else None
|
|
||||||
|
|
||||||
async def async_get_app_list(self) -> dict[str, str] | None:
|
async def async_get_app_list(self) -> dict[str, str] | None:
|
||||||
"""Get installed app list."""
|
"""Get installed app list."""
|
||||||
if self._app_list is None:
|
if self._app_list is None:
|
||||||
|
@ -42,6 +42,7 @@ async def test_entry_diagnostics(
|
|||||||
"ip_address": "test",
|
"ip_address": "test",
|
||||||
"mac": "aa:bb:cc:dd:ee:ff",
|
"mac": "aa:bb:cc:dd:ee:ff",
|
||||||
"method": "websocket",
|
"method": "websocket",
|
||||||
|
"model": "82GXARRS",
|
||||||
"name": "fake",
|
"name": "fake",
|
||||||
"port": 8002,
|
"port": 8002,
|
||||||
"token": REDACTED,
|
"token": REDACTED,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"""Tests for the Samsung TV Integration."""
|
"""Tests for the Samsung TV Integration."""
|
||||||
from unittest.mock import patch
|
from copy import deepcopy
|
||||||
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -132,3 +133,18 @@ async def test_setup_duplicate_entries(hass: HomeAssistant) -> None:
|
|||||||
assert len(hass.states.async_all("media_player")) == 1
|
assert len(hass.states.async_all("media_player")) == 1
|
||||||
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
||||||
assert len(hass.states.async_all("media_player")) == 1
|
assert len(hass.states.async_all("media_player")) == 1
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("remotews")
|
||||||
|
async def test_setup_h_j_model(
|
||||||
|
hass: HomeAssistant, rest_api: Mock, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
|
"""Test Samsung TV integration is setup."""
|
||||||
|
device_info = deepcopy(rest_api.rest_device_info.return_value)
|
||||||
|
device_info["device"]["modelName"] = "UE48JU6400"
|
||||||
|
rest_api.rest_device_info.return_value = device_info
|
||||||
|
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
state = hass.states.get(ENTITY_ID)
|
||||||
|
assert state
|
||||||
|
assert "H and J series use an encrypted protocol" in caplog.text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user