Add samsungtv dhcp and zeroconf discovery (#48022)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
aa9b99713c
commit
b9a0fb93eb
17 changed files with 1174 additions and 415 deletions
|
@ -1,21 +1,22 @@
|
|||
"""Tests for the Samsung TV Integration."""
|
||||
from unittest.mock import Mock, call, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.media_player.const import DOMAIN, SUPPORT_TURN_ON
|
||||
from homeassistant.components.samsungtv.const import (
|
||||
CONF_ON_ACTION,
|
||||
DOMAIN as SAMSUNGTV_DOMAIN,
|
||||
METHOD_WEBSOCKET,
|
||||
)
|
||||
from homeassistant.components.samsungtv.media_player import SUPPORT_SAMSUNGTV
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
CONF_HOST,
|
||||
CONF_METHOD,
|
||||
CONF_NAME,
|
||||
SERVICE_VOLUME_UP,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
ENTITY_ID = f"{DOMAIN}.fake_name"
|
||||
|
@ -25,6 +26,7 @@ MOCK_CONFIG = {
|
|||
CONF_HOST: "fake_host",
|
||||
CONF_NAME: "fake_name",
|
||||
CONF_ON_ACTION: [{"delay": "00:00:01"}],
|
||||
CONF_METHOD: METHOD_WEBSOCKET,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -32,37 +34,22 @@ REMOTE_CALL = {
|
|||
"name": "HomeAssistant",
|
||||
"description": "HomeAssistant",
|
||||
"id": "ha.component.samsung",
|
||||
"method": "legacy",
|
||||
"host": MOCK_CONFIG[SAMSUNGTV_DOMAIN][0][CONF_HOST],
|
||||
"method": "legacy",
|
||||
"port": None,
|
||||
"timeout": 1,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(name="remote")
|
||||
def remote_fixture():
|
||||
"""Patch the samsungctl Remote."""
|
||||
with patch(
|
||||
"homeassistant.components.samsungtv.bridge.Remote"
|
||||
) as remote_class, patch(
|
||||
"homeassistant.components.samsungtv.config_flow.socket"
|
||||
) as socket1, patch(
|
||||
"homeassistant.components.samsungtv.socket"
|
||||
) as socket2:
|
||||
remote = Mock()
|
||||
remote.__enter__ = Mock()
|
||||
remote.__exit__ = Mock()
|
||||
remote_class.return_value = remote
|
||||
socket1.gethostbyname.return_value = "FAKE_IP_ADDRESS"
|
||||
socket2.gethostbyname.return_value = "FAKE_IP_ADDRESS"
|
||||
yield remote
|
||||
|
||||
|
||||
async def test_setup(hass, remote):
|
||||
async def test_setup(hass: HomeAssistant, remote: Mock):
|
||||
"""Test Samsung TV integration is setup."""
|
||||
with patch("homeassistant.components.samsungtv.bridge.Remote") as remote:
|
||||
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
with patch("homeassistant.components.samsungtv.bridge.Remote") as remote, patch(
|
||||
"homeassistant.components.samsungtv.config_flow.socket.gethostbyname",
|
||||
return_value="fake_host",
|
||||
):
|
||||
with patch("homeassistant.components.samsungtv.bridge.Remote") as remote:
|
||||
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_ID)
|
||||
|
||||
# test name and turn_on
|
||||
|
@ -80,7 +67,7 @@ async def test_setup(hass, remote):
|
|||
assert remote.call_args == call(REMOTE_CALL)
|
||||
|
||||
|
||||
async def test_setup_duplicate_config(hass, remote, caplog):
|
||||
async def test_setup_duplicate_config(hass: HomeAssistant, remote: Mock, caplog):
|
||||
"""Test duplicate setup of platform."""
|
||||
DUPLICATE = {
|
||||
SAMSUNGTV_DOMAIN: [
|
||||
|
@ -95,7 +82,7 @@ async def test_setup_duplicate_config(hass, remote, caplog):
|
|||
assert "duplicate host entries found" in caplog.text
|
||||
|
||||
|
||||
async def test_setup_duplicate_entries(hass, remote, caplog):
|
||||
async def test_setup_duplicate_entries(hass: HomeAssistant, remote: Mock, caplog):
|
||||
"""Test duplicate setup of platform."""
|
||||
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue