Samsung TV refinements (#31248)
* use st not deviceType * show model in flow title * Update strings.json * add re-auth to entity * add re-auth to config_flow * handle auth popup better * use media player domain const * fix tests * rename not_found to not_successful * authz not authn * Update media_player.py * Update config_flow.py * Update media_player.py * Update test_media_player.py * finalize re-auth * fix ssd tests * better naming * fix ip-address-mock serialization * fix turn_on_action serialization * add type of hass object * fix acces denied test * remove half-added typing * async get ip address * fix pylint
This commit is contained in:
1 parent
9bb8b2bc00
commit
2f2146c989
10 files changed
+138
-71
No files matched your search
@@ -42,7 +42,7 @@ AUTODETECT_WEBSOCKET = {
|
||||
"method": "websocket",
|
||||
"port": None,
|
||||
"host": "fake_host",
|
||||
"timeout": 1,
|
||||
"timeout": 31,
|
||||
}
|
||||
AUTODETECT_LEGACY = {
|
||||
"name": "HomeAssistant",
|
||||
@@ -51,7 +51,7 @@ AUTODETECT_LEGACY = {
|
||||
"method": "legacy",
|
||||
"port": None,
|
||||
"host": "fake_host",
|
||||
"timeout": 1,
|
||||
"timeout": 31,
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ async def test_user(hass, remote):
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["title"] == "fake_name"
|
||||
assert result["data"][CONF_HOST] == "fake_host"
|
||||
assert result["data"][CONF_NAME] is None
|
||||
assert result["data"][CONF_NAME] == "fake_name"
|
||||
assert result["data"][CONF_MANUFACTURER] is None
|
||||
assert result["data"][CONF_MODEL] is None
|
||||
assert result["data"][CONF_ID] is None
|
||||
@@ -123,19 +123,19 @@ async def test_user_not_supported(hass):
|
||||
assert result["reason"] == "not_supported"
|
||||
|
||||
|
||||
async def test_user_not_found(hass):
|
||||
"""Test starting a flow by user but no device found."""
|
||||
async def test_user_not_successful(hass):
|
||||
"""Test starting a flow by user but no connection found."""
|
||||
with patch(
|
||||
"homeassistant.components.samsungtv.config_flow.Remote",
|
||||
side_effect=OSError("Boom"),
|
||||
), patch("homeassistant.components.samsungtv.config_flow.socket"):
|
||||
|
||||
# device not found
|
||||
# device not connectable
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA
|
||||
)
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "not_found"
|
||||
assert result["reason"] == "not_successful"
|
||||
|
||||
|
||||
async def test_user_already_configured(hass, remote):
|
||||
@@ -170,9 +170,9 @@ async def test_ssdp(hass, remote):
|
||||
result["flow_id"], user_input="whatever"
|
||||
)
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["title"] == "fake_name (fake_model)"
|
||||
assert result["title"] == "fake_model"
|
||||
assert result["data"][CONF_HOST] == "fake_host"
|
||||
assert result["data"][CONF_NAME] == "fake_name"
|
||||
assert result["data"][CONF_NAME] == "Samsung fake_model"
|
||||
assert result["data"][CONF_MANUFACTURER] == "fake_manufacturer"
|
||||
assert result["data"][CONF_MODEL] == "fake_model"
|
||||
assert result["data"][CONF_ID] == "fake_uuid"
|
||||
@@ -193,9 +193,9 @@ async def test_ssdp_noprefix(hass, remote):
|
||||
result["flow_id"], user_input="whatever"
|
||||
)
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["title"] == "fake2_name (fake2_model)"
|
||||
assert result["title"] == "fake2_model"
|
||||
assert result["data"][CONF_HOST] == "fake2_host"
|
||||
assert result["data"][CONF_NAME] == "fake2_name"
|
||||
assert result["data"][CONF_NAME] == "Samsung fake2_model"
|
||||
assert result["data"][CONF_MANUFACTURER] == "fake2_manufacturer"
|
||||
assert result["data"][CONF_MODEL] == "fake2_model"
|
||||
assert result["data"][CONF_ID] == "fake2_uuid"
|
||||
@@ -245,7 +245,7 @@ async def test_ssdp_not_supported(hass):
|
||||
assert result["reason"] == "not_supported"
|
||||
|
||||
|
||||
async def test_ssdp_not_found(hass):
|
||||
async def test_ssdp_not_successful(hass):
|
||||
"""Test starting a flow from discovery but no device found."""
|
||||
with patch(
|
||||
"homeassistant.components.samsungtv.config_flow.Remote",
|
||||
@@ -264,7 +264,7 @@ async def test_ssdp_not_found(hass):
|
||||
result["flow_id"], user_input="whatever"
|
||||
)
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "not_found"
|
||||
assert result["reason"] == "not_successful"
|
||||
|
||||
|
||||
async def test_ssdp_already_in_progress(hass, remote):
|
||||
@@ -380,7 +380,7 @@ async def test_autodetect_none(hass, remote):
|
||||
DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA
|
||||
)
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "not_found"
|
||||
assert result["reason"] == "not_successful"
|
||||
assert remote.call_count == 2
|
||||
assert remote.call_args_list == [
|
||||
call(AUTODETECT_WEBSOCKET),
|
||||
|
||||
@@ -32,7 +32,7 @@ MOCK_CONFIG = {
|
||||
}
|
||||
REMOTE_CALL = {
|
||||
"name": "HomeAssistant",
|
||||
"description": MOCK_CONFIG[SAMSUNGTV_DOMAIN][0][CONF_NAME],
|
||||
"description": "HomeAssistant",
|
||||
"id": "ha.component.samsung",
|
||||
"method": "websocket",
|
||||
"port": MOCK_CONFIG[SAMSUNGTV_DOMAIN][0][CONF_PORT],
|
||||
@@ -44,11 +44,13 @@ REMOTE_CALL = {
|
||||
@pytest.fixture(name="remote")
|
||||
def remote_fixture():
|
||||
"""Patch the samsungctl Remote."""
|
||||
with patch("homeassistant.components.samsungtv.socket"), patch(
|
||||
with patch("homeassistant.components.samsungtv.socket") as socket1, patch(
|
||||
"homeassistant.components.samsungtv.config_flow.socket"
|
||||
), patch("homeassistant.components.samsungtv.config_flow.Remote"), patch(
|
||||
) as socket2, patch("homeassistant.components.samsungtv.config_flow.Remote"), patch(
|
||||
"homeassistant.components.samsungtv.media_player.SamsungRemote"
|
||||
) as remote:
|
||||
socket1.gethostbyname.return_value = "FAKE_IP_ADDRESS"
|
||||
socket2.gethostbyname.return_value = "FAKE_IP_ADDRESS"
|
||||
yield remote
|
||||
|
||||
|
||||
|
||||
@@ -75,15 +75,17 @@ MOCK_CONFIG_NOTURNON = {
|
||||
@pytest.fixture(name="remote")
|
||||
def remote_fixture():
|
||||
"""Patch the samsungctl Remote."""
|
||||
with patch("homeassistant.components.samsungtv.config_flow.socket"), patch(
|
||||
"homeassistant.components.samsungtv.config_flow.Remote"
|
||||
), patch(
|
||||
with patch("homeassistant.components.samsungtv.config_flow.Remote"), patch(
|
||||
"homeassistant.components.samsungtv.config_flow.socket"
|
||||
) as socket1, patch(
|
||||
"homeassistant.components.samsungtv.media_player.SamsungRemote"
|
||||
) as remote_class, patch(
|
||||
"homeassistant.components.samsungtv.socket"
|
||||
):
|
||||
) as socket2:
|
||||
remote = mock.Mock()
|
||||
remote_class.return_value = remote
|
||||
socket1.gethostbyname.return_value = "FAKE_IP_ADDRESS"
|
||||
socket2.gethostbyname.return_value = "FAKE_IP_ADDRESS"
|
||||
yield remote
|
||||
|
||||
|
||||
@@ -135,11 +137,12 @@ async def test_update_on(hass, remote, mock_now):
|
||||
|
||||
async def test_update_off(hass, remote, mock_now):
|
||||
"""Testing update tv off."""
|
||||
await setup_samsungtv(hass, MOCK_CONFIG)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.samsungtv.media_player.SamsungRemote",
|
||||
side_effect=[OSError("Boom"), mock.DEFAULT],
|
||||
), patch("homeassistant.components.samsungtv.config_flow.socket"):
|
||||
await setup_samsungtv(hass, MOCK_CONFIG)
|
||||
):
|
||||
|
||||
next_update = mock_now + timedelta(minutes=5)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=next_update):
|
||||
@@ -150,13 +153,35 @@ async def test_update_off(hass, remote, mock_now):
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_update_access_denied(hass, remote, mock_now):
|
||||
"""Testing update tv unhandled response exception."""
|
||||
await setup_samsungtv(hass, MOCK_CONFIG)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.samsungtv.media_player.SamsungRemote",
|
||||
side_effect=exceptions.AccessDenied("Boom"),
|
||||
):
|
||||
|
||||
next_update = mock_now + timedelta(minutes=5)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=next_update):
|
||||
async_fire_time_changed(hass, next_update)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert [
|
||||
flow
|
||||
for flow in hass.config_entries.flow.async_progress()
|
||||
if flow["context"]["source"] == "reauth"
|
||||
]
|
||||
|
||||
|
||||
async def test_update_unhandled_response(hass, remote, mock_now):
|
||||
"""Testing update tv unhandled response exception."""
|
||||
await setup_samsungtv(hass, MOCK_CONFIG)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.samsungtv.media_player.SamsungRemote",
|
||||
side_effect=[exceptions.UnhandledResponse("Boom"), mock.DEFAULT],
|
||||
), patch("homeassistant.components.samsungtv.config_flow.socket"):
|
||||
await setup_samsungtv(hass, MOCK_CONFIG)
|
||||
):
|
||||
|
||||
next_update = mock_now + timedelta(minutes=5)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=next_update):
|
||||
|
||||
Reference in new issue
Block a user