mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Use ZeroconfServiceInfo in shelly (#60098)
This commit is contained in:
parent
fa9465d003
commit
4555820987
@ -189,16 +189,17 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
self, discovery_info: zeroconf.ZeroconfServiceInfo
|
||||
) -> FlowResult:
|
||||
"""Handle zeroconf discovery."""
|
||||
host = discovery_info[zeroconf.ATTR_HOST]
|
||||
try:
|
||||
self.info = await self._async_get_info(discovery_info["host"])
|
||||
self.info = await self._async_get_info(host)
|
||||
except HTTP_CONNECT_ERRORS:
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except aioshelly.exceptions.FirmwareUnsupported:
|
||||
return self.async_abort(reason="unsupported_firmware")
|
||||
|
||||
await self.async_set_unique_id(self.info["mac"])
|
||||
self._abort_if_unique_id_configured({CONF_HOST: discovery_info["host"]})
|
||||
self.host = discovery_info["host"]
|
||||
self._abort_if_unique_id_configured({CONF_HOST: host})
|
||||
self.host = host
|
||||
|
||||
self.context["title_placeholders"] = {
|
||||
"name": discovery_info.get("name", "").split(".")[0]
|
||||
|
@ -8,6 +8,7 @@ import aioshelly
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.components.shelly.const import DOMAIN
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
@ -16,11 +17,11 @@ MOCK_SETTINGS = {
|
||||
"name": "Test name",
|
||||
"device": {"mac": "test-mac", "hostname": "test-host", "type": "SHSW-1"},
|
||||
}
|
||||
DISCOVERY_INFO = {
|
||||
"host": "1.1.1.1",
|
||||
"name": "shelly1pm-12345",
|
||||
"properties": {"id": "shelly1pm-12345"},
|
||||
}
|
||||
DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo(
|
||||
host="1.1.1.1",
|
||||
name="shelly1pm-12345",
|
||||
properties={"id": "shelly1pm-12345"},
|
||||
)
|
||||
MOCK_CONFIG = {
|
||||
"wifi": {"ap": {"ssid": "Test name"}},
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user