mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Fix Shelly devices missing properties field (#44279)
This commit is contained in:
parent
36eebd92dd
commit
fd24baa1f6
@ -27,12 +27,6 @@ HOST_SCHEMA = vol.Schema({vol.Required(CONF_HOST): str})
|
|||||||
HTTP_CONNECT_ERRORS = (asyncio.TimeoutError, aiohttp.ClientError)
|
HTTP_CONNECT_ERRORS = (asyncio.TimeoutError, aiohttp.ClientError)
|
||||||
|
|
||||||
|
|
||||||
def _remove_prefix(shelly_str):
|
|
||||||
if shelly_str.startswith("shellyswitch"):
|
|
||||||
return shelly_str[6:]
|
|
||||||
return shelly_str
|
|
||||||
|
|
||||||
|
|
||||||
async def validate_input(hass: core.HomeAssistant, host, data):
|
async def validate_input(hass: core.HomeAssistant, host, data):
|
||||||
"""Validate the user input allows us to connect.
|
"""Validate the user input allows us to connect.
|
||||||
|
|
||||||
@ -159,7 +153,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
self.host = zeroconf_info["host"]
|
self.host = zeroconf_info["host"]
|
||||||
# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
|
# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
|
||||||
self.context["title_placeholders"] = {
|
self.context["title_placeholders"] = {
|
||||||
"name": _remove_prefix(zeroconf_info["properties"]["id"])
|
"name": zeroconf_info.get("name", "").split(".")[0]
|
||||||
}
|
}
|
||||||
return await self.async_step_confirm_discovery()
|
return await self.async_step_confirm_discovery()
|
||||||
|
|
||||||
|
@ -20,11 +20,6 @@ DISCOVERY_INFO = {
|
|||||||
"name": "shelly1pm-12345",
|
"name": "shelly1pm-12345",
|
||||||
"properties": {"id": "shelly1pm-12345"},
|
"properties": {"id": "shelly1pm-12345"},
|
||||||
}
|
}
|
||||||
SWITCH25_DISCOVERY_INFO = {
|
|
||||||
"host": "1.1.1.1",
|
|
||||||
"name": "shellyswitch25-12345",
|
|
||||||
"properties": {"id": "shellyswitch25-12345"},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_form(hass):
|
async def test_form(hass):
|
||||||
@ -67,7 +62,7 @@ async def test_form(hass):
|
|||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_title_without_name_and_prefix(hass):
|
async def test_title_without_name(hass):
|
||||||
"""Test we set the title to the hostname when the device doesn't have a name."""
|
"""Test we set the title to the hostname when the device doesn't have a name."""
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -360,29 +355,6 @@ async def test_zeroconf(hass):
|
|||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_zeroconf_with_switch_prefix(hass):
|
|
||||||
"""Test we get remove shelly from the prefix."""
|
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"aioshelly.get_info",
|
|
||||||
return_value={"mac": "test-mac", "type": "SHSW-1", "auth": False},
|
|
||||||
):
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
data=SWITCH25_DISCOVERY_INFO,
|
|
||||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
|
||||||
)
|
|
||||||
assert result["type"] == "form"
|
|
||||||
assert result["errors"] == {}
|
|
||||||
context = next(
|
|
||||||
flow["context"]
|
|
||||||
for flow in hass.config_entries.flow.async_progress()
|
|
||||||
if flow["flow_id"] == result["flow_id"]
|
|
||||||
)
|
|
||||||
assert context["title_placeholders"]["name"] == "switch25-12345"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"error", [(asyncio.TimeoutError, "cannot_connect"), (ValueError, "unknown")]
|
"error", [(asyncio.TimeoutError, "cannot_connect"), (ValueError, "unknown")]
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user