Use ZeroconfServiceInfo in rachio (#60054)
This commit is contained in:
parent
435eb97495
commit
8ec30aa9ad
2 changed files with 15 additions and 7 deletions
|
@ -7,8 +7,10 @@ from requests.exceptions import ConnectTimeout
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries, core, exceptions
|
from homeassistant import config_entries, core, exceptions
|
||||||
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.const import CONF_API_KEY
|
from homeassistant.const import CONF_API_KEY
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_MANUAL_RUN_MINS,
|
CONF_MANUAL_RUN_MINS,
|
||||||
|
@ -78,13 +80,14 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
step_id="user", data_schema=DATA_SCHEMA, errors=errors
|
step_id="user", data_schema=DATA_SCHEMA, errors=errors
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_homekit(self, discovery_info):
|
async def async_step_homekit(
|
||||||
|
self, discovery_info: zeroconf.ZeroconfServiceInfo
|
||||||
|
) -> FlowResult:
|
||||||
"""Handle HomeKit discovery."""
|
"""Handle HomeKit discovery."""
|
||||||
self._async_abort_entries_match()
|
self._async_abort_entries_match()
|
||||||
properties = {
|
await self.async_set_unique_id(
|
||||||
key.lower(): value for (key, value) in discovery_info["properties"].items()
|
discovery_info[zeroconf.ATTR_PROPERTIES][zeroconf.ATTR_PROPERTIES_ID]
|
||||||
}
|
)
|
||||||
await self.async_set_unique_id(properties["id"])
|
|
||||||
return await self.async_step_user()
|
return await self.async_step_user()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.components.rachio.const import (
|
from homeassistant.components.rachio.const import (
|
||||||
CONF_CUSTOM_URL,
|
CONF_CUSTOM_URL,
|
||||||
CONF_MANUAL_RUN_MINS,
|
CONF_MANUAL_RUN_MINS,
|
||||||
|
@ -111,7 +112,9 @@ async def test_form_homekit(hass):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_HOMEKIT},
|
context={"source": config_entries.SOURCE_HOMEKIT},
|
||||||
data={"properties": {"id": "AA:BB:CC:DD:EE:FF"}},
|
data=zeroconf.ZeroconfServiceInfo(
|
||||||
|
properties={zeroconf.ATTR_PROPERTIES_ID: "AA:BB:CC:DD:EE:FF"}
|
||||||
|
),
|
||||||
)
|
)
|
||||||
assert result["type"] == "form"
|
assert result["type"] == "form"
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
@ -128,7 +131,9 @@ async def test_form_homekit(hass):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_HOMEKIT},
|
context={"source": config_entries.SOURCE_HOMEKIT},
|
||||||
data={"properties": {"id": "AA:BB:CC:DD:EE:FF"}},
|
data=zeroconf.ZeroconfServiceInfo(
|
||||||
|
properties={zeroconf.ATTR_PROPERTIES_ID: "AA:BB:CC:DD:EE:FF"}
|
||||||
|
),
|
||||||
)
|
)
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == "abort"
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
Loading…
Add table
Reference in a new issue