Update model info from SSDP in SamsungTV (#71992)

* Update model info from SSDP in SamsungTV

* Add tests
This commit is contained in:
epenet 2022-05-17 21:49:19 +02:00 committed by GitHub
parent a78f183b64
commit afe2b71b2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View file

@ -167,6 +167,8 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
updates = {CONF_HOST: self._host}
if self._mac:
updates[CONF_MAC] = self._mac
if self._model:
updates[CONF_MODEL] = self._model
if self._ssdp_rendering_control_location:
updates[
CONF_SSDP_RENDERING_CONTROL_LOCATION
@ -380,10 +382,12 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
!= self._ssdp_main_tv_agent_location
)
update_mac = self._mac and not data.get(CONF_MAC)
update_model = self._model and not data.get(CONF_MODEL)
if (
update_ssdp_rendering_control_location
or update_ssdp_main_tv_agent_location
or update_mac
or update_model
):
if update_ssdp_rendering_control_location:
data[
@ -395,6 +399,8 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
] = self._ssdp_main_tv_agent_location
if update_mac:
data[CONF_MAC] = self._mac
if update_model:
data[CONF_MODEL] = self._model
entry_kw_args["data"] = data
if not entry_kw_args:
return None

View file

@ -1420,6 +1420,36 @@ async def test_update_missing_mac_unique_id_added_from_zeroconf(
assert entry.unique_id == "be9554b9-c9fb-41f4-8920-22da015376a4"
@pytest.mark.usefixtures("remote", "rest_api_failing")
async def test_update_missing_model_added_from_ssdp(hass: HomeAssistant) -> None:
"""Test missing model added via ssdp on legacy models."""
entry = MockConfigEntry(
domain=DOMAIN,
data=MOCK_OLD_ENTRY,
unique_id=None,
)
entry.add_to_hass(hass)
with patch(
"homeassistant.components.samsungtv.async_setup",
return_value=True,
) as mock_setup, patch(
"homeassistant.components.samsungtv.async_setup_entry",
return_value=True,
) as mock_setup_entry:
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_SSDP},
data=MOCK_SSDP_DATA,
)
await hass.async_block_till_done()
assert len(mock_setup.mock_calls) == 1
assert len(mock_setup_entry.mock_calls) == 1
assert result["type"] == "abort"
assert result["reason"] == "already_configured"
assert entry.data[CONF_MODEL] == "fake_model"
@pytest.mark.usefixtures("remotews", "rest_api", "remoteencws_failing")
async def test_update_missing_mac_unique_id_ssdp_location_added_from_ssdp(
hass: HomeAssistant,