mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Add HomeKit discovery to Slide Local (#185924)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
16197908ff
commit
a76ddffdcf
@@ -183,13 +183,29 @@ class SlideConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
self, discovery_info: ZeroconfServiceInfo
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle zeroconf discovery."""
|
||||
|
||||
# id is in the format 'slide_000000000000'
|
||||
self._mac = format_mac(str(discovery_info.properties.get("id"))[6:])
|
||||
return await self._async_handle_discovery(
|
||||
str(discovery_info.properties.get("id"))[6:],
|
||||
str(discovery_info.ip_address),
|
||||
)
|
||||
|
||||
@override
|
||||
async def async_step_homekit(
|
||||
self, discovery_info: ZeroconfServiceInfo
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle HomeKit discovery."""
|
||||
# name is in the format 'Slide-000000000000._hap._tcp.local.'
|
||||
return await self._async_handle_discovery(
|
||||
discovery_info.name.split(".", 1)[0][6:],
|
||||
str(discovery_info.ip_address),
|
||||
)
|
||||
|
||||
async def _async_handle_discovery(self, mac: str, ip: str) -> ConfigFlowResult:
|
||||
"""Handle a discovered Slide device."""
|
||||
self._mac = format_mac(mac)
|
||||
|
||||
await self.async_set_unique_id(self._mac)
|
||||
|
||||
ip = str(discovery_info.ip_address)
|
||||
_LOGGER.debug("Slide device discovered, ip %s", ip)
|
||||
|
||||
self._abort_if_unique_id_configured({CONF_HOST: ip}, reload_on_update=True)
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
"codeowners": ["@dontinelli"],
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/slide_local",
|
||||
"homekit": {
|
||||
"models": ["Slide"]
|
||||
},
|
||||
"integration_type": "device",
|
||||
"iot_class": "local_polling",
|
||||
"quality_scale": "gold",
|
||||
|
||||
Generated
+4
@@ -256,6 +256,10 @@ HOMEKIT = {
|
||||
"always_discover": True,
|
||||
"domain": "sensibo",
|
||||
},
|
||||
"Slide": {
|
||||
"always_discover": True,
|
||||
"domain": "slide_local",
|
||||
},
|
||||
"Smart Bridge": {
|
||||
"always_discover": False,
|
||||
"domain": "lutron_caseta",
|
||||
|
||||
@@ -12,7 +12,7 @@ from goslideapi.goslideapi import (
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.slide_local.const import CONF_INVERT_POSITION, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
|
||||
from homeassistant.config_entries import SOURCE_HOMEKIT, SOURCE_USER, SOURCE_ZEROCONF
|
||||
from homeassistant.const import CONF_API_VERSION, CONF_HOST, CONF_PASSWORD, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
@@ -39,6 +39,33 @@ MOCK_ZEROCONF_DATA = ZeroconfServiceInfo(
|
||||
type="mock_type",
|
||||
)
|
||||
|
||||
MOCK_HOMEKIT_DATA = ZeroconfServiceInfo(
|
||||
ip_address=ip_address("127.0.0.2"),
|
||||
ip_addresses=[ip_address("127.0.0.2")],
|
||||
hostname="Slide-1234567890AB.local.",
|
||||
name="Slide-1234567890AB._hap._tcp.local.",
|
||||
port=9000,
|
||||
properties={
|
||||
"c#": "1",
|
||||
"ff": "0",
|
||||
"id": "72:14:B5:55:8A:33",
|
||||
"md": "Slide",
|
||||
"pv": "1.1",
|
||||
"s#": "1",
|
||||
"sf": "1",
|
||||
"ci": "14",
|
||||
},
|
||||
type="_hap._tcp.local.",
|
||||
)
|
||||
|
||||
DISCOVERY_PARAMS = pytest.mark.parametrize(
|
||||
("source", "discovery_info"),
|
||||
[
|
||||
pytest.param(SOURCE_ZEROCONF, MOCK_ZEROCONF_DATA, id="zeroconf"),
|
||||
pytest.param(SOURCE_HOMEKIT, MOCK_HOMEKIT_DATA, id="homekit"),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
async def test_user(
|
||||
hass: HomeAssistant, mock_slide_api: AsyncMock, mock_setup_entry: AsyncMock
|
||||
@@ -321,12 +348,18 @@ async def test_reconfigure(
|
||||
assert entry.data[CONF_HOST] == "127.0.0.3"
|
||||
|
||||
|
||||
@DISCOVERY_PARAMS
|
||||
@pytest.mark.usefixtures("mock_setup_entry")
|
||||
async def test_zeroconf(hass: HomeAssistant, mock_slide_api: AsyncMock) -> None:
|
||||
async def test_zeroconf(
|
||||
hass: HomeAssistant,
|
||||
mock_slide_api: AsyncMock,
|
||||
source: str,
|
||||
discovery_info: ZeroconfServiceInfo,
|
||||
) -> None:
|
||||
"""Test starting a flow from discovery."""
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_ZEROCONF}, data=MOCK_ZEROCONF_DATA
|
||||
DOMAIN, context={"source": source}, data=discovery_info
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "zeroconf_confirm"
|
||||
@@ -342,9 +375,13 @@ async def test_zeroconf(hass: HomeAssistant, mock_slide_api: AsyncMock) -> None:
|
||||
assert result["result"].unique_id == "12:34:56:78:90:ab"
|
||||
|
||||
|
||||
@DISCOVERY_PARAMS
|
||||
@pytest.mark.usefixtures("mock_setup_entry")
|
||||
async def test_zeroconf_duplicate_entry(
|
||||
hass: HomeAssistant, mock_slide_api: AsyncMock
|
||||
hass: HomeAssistant,
|
||||
mock_slide_api: AsyncMock,
|
||||
source: str,
|
||||
discovery_info: ZeroconfServiceInfo,
|
||||
) -> None:
|
||||
"""Test starting a flow from discovery."""
|
||||
|
||||
@@ -353,7 +390,7 @@ async def test_zeroconf_duplicate_entry(
|
||||
).add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_ZEROCONF}, data=MOCK_ZEROCONF_DATA
|
||||
DOMAIN, context={"source": source}, data=discovery_info
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
@@ -362,9 +399,13 @@ async def test_zeroconf_duplicate_entry(
|
||||
assert entries[0].data[CONF_HOST] == HOST
|
||||
|
||||
|
||||
@DISCOVERY_PARAMS
|
||||
@pytest.mark.usefixtures("mock_setup_entry")
|
||||
async def test_zeroconf_update_duplicate_entry(
|
||||
hass: HomeAssistant, mock_slide_api: AsyncMock
|
||||
hass: HomeAssistant,
|
||||
mock_slide_api: AsyncMock,
|
||||
source: str,
|
||||
discovery_info: ZeroconfServiceInfo,
|
||||
) -> None:
|
||||
"""Test updating an existing entry from discovery."""
|
||||
|
||||
@@ -373,7 +414,7 @@ async def test_zeroconf_update_duplicate_entry(
|
||||
).add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_ZEROCONF}, data=MOCK_ZEROCONF_DATA
|
||||
DOMAIN, context={"source": source}, data=discovery_info
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
@@ -392,9 +433,14 @@ async def test_zeroconf_update_duplicate_entry(
|
||||
(Exception),
|
||||
],
|
||||
)
|
||||
@DISCOVERY_PARAMS
|
||||
@pytest.mark.usefixtures("mock_setup_entry")
|
||||
async def test_zeroconf_connection_error(
|
||||
hass: HomeAssistant, exception: Exception, mock_slide_api: AsyncMock
|
||||
hass: HomeAssistant,
|
||||
exception: Exception,
|
||||
mock_slide_api: AsyncMock,
|
||||
source: str,
|
||||
discovery_info: ZeroconfServiceInfo,
|
||||
) -> None:
|
||||
"""Test starting a flow from discovery."""
|
||||
|
||||
@@ -405,7 +451,7 @@ async def test_zeroconf_connection_error(
|
||||
mock_slide_api.slide_info.side_effect = exception
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_ZEROCONF}, data=MOCK_ZEROCONF_DATA
|
||||
DOMAIN, context={"source": source}, data=discovery_info
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
|
||||
Reference in New Issue
Block a user