mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Enable SkyConnect config flow and use correct case in USB matching (#81522)
* Ensure `USBCallbackMatcher` uses the appropriate case for each field * Enable the config flow for the SkyConnect integration * Update unit test
This commit is contained in:
parent
3788a950e6
commit
604cd46ec9
@ -1,16 +1,29 @@
|
|||||||
"""The Home Assistant Sky Connect integration."""
|
"""The Home Assistant Sky Connect integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import cast
|
|
||||||
|
|
||||||
from homeassistant.components import usb
|
from homeassistant.components import usb
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up a Home Assistant Sky Connect config entry."""
|
"""Set up a Home Assistant Sky Connect config entry."""
|
||||||
|
matcher = usb.USBCallbackMatcher(
|
||||||
|
domain=DOMAIN,
|
||||||
|
vid=entry.data["vid"].upper(),
|
||||||
|
pid=entry.data["pid"].upper(),
|
||||||
|
serial_number=entry.data["serial_number"].lower(),
|
||||||
|
manufacturer=entry.data["manufacturer"].lower(),
|
||||||
|
description=entry.data["description"].lower(),
|
||||||
|
)
|
||||||
|
|
||||||
|
if not usb.async_is_plugged_in(hass, matcher):
|
||||||
|
# The USB dongle is not plugged in
|
||||||
|
raise ConfigEntryNotReady
|
||||||
|
|
||||||
usb_info = usb.UsbServiceInfo(
|
usb_info = usb.UsbServiceInfo(
|
||||||
device=entry.data["device"],
|
device=entry.data["device"],
|
||||||
vid=entry.data["vid"],
|
vid=entry.data["vid"],
|
||||||
@ -19,9 +32,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
manufacturer=entry.data["manufacturer"],
|
manufacturer=entry.data["manufacturer"],
|
||||||
description=entry.data["description"],
|
description=entry.data["description"],
|
||||||
)
|
)
|
||||||
if not usb.async_is_plugged_in(hass, cast(usb.USBCallbackMatcher, entry.data)):
|
|
||||||
# The USB dongle is not plugged in
|
|
||||||
raise ConfigEntryNotReady
|
|
||||||
|
|
||||||
await hass.config_entries.flow.async_init(
|
await hass.config_entries.flow.async_init(
|
||||||
"zha",
|
"zha",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"domain": "homeassistant_sky_connect",
|
"domain": "homeassistant_sky_connect",
|
||||||
"name": "Home Assistant Sky Connect",
|
"name": "Home Assistant Sky Connect",
|
||||||
"config_flow": false,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/homeassistant_sky_connect",
|
"documentation": "https://www.home-assistant.io/integrations/homeassistant_sky_connect",
|
||||||
"dependencies": ["hardware", "usb"],
|
"dependencies": ["hardware", "usb"],
|
||||||
"codeowners": ["@home-assistant/core"],
|
"codeowners": ["@home-assistant/core"],
|
||||||
|
@ -161,6 +161,7 @@ FLOWS = {
|
|||||||
"hlk_sw16",
|
"hlk_sw16",
|
||||||
"home_connect",
|
"home_connect",
|
||||||
"home_plus_control",
|
"home_plus_control",
|
||||||
|
"homeassistant_sky_connect",
|
||||||
"homekit",
|
"homekit",
|
||||||
"homekit_controller",
|
"homekit_controller",
|
||||||
"homematicip_cloud",
|
"homematicip_cloud",
|
||||||
|
@ -4,6 +4,12 @@ To update, run python3 -m script.hassfest
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
USB = [
|
USB = [
|
||||||
|
{
|
||||||
|
"domain": "homeassistant_sky_connect",
|
||||||
|
"vid": "10C4",
|
||||||
|
"pid": "EA60",
|
||||||
|
"description": "*skyconnect v1.0*",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"domain": "insteon",
|
"domain": "insteon",
|
||||||
"vid": "10BF",
|
"vid": "10BF",
|
||||||
|
@ -13,12 +13,12 @@ from homeassistant.core import HomeAssistant
|
|||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
CONFIG_ENTRY_DATA = {
|
CONFIG_ENTRY_DATA = {
|
||||||
"device": "bla_device",
|
"device": "/dev/serial/by-id/usb-Nabu_Casa_SkyConnect_v1.0_9e2adbd75b8beb119fe564a0f320645d-if00-port0",
|
||||||
"vid": "bla_vid",
|
"vid": "10C4",
|
||||||
"pid": "bla_pid",
|
"pid": "EA60",
|
||||||
"serial_number": "bla_serial_number",
|
"serial_number": "3c0ed67c628beb11b1cd64a0f320645d",
|
||||||
"manufacturer": "bla_manufacturer",
|
"manufacturer": "Nabu Casa",
|
||||||
"description": "bla_description",
|
"description": "SkyConnect v1.0",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -67,6 +67,13 @@ async def test_setup_entry(
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(mock_is_plugged_in.mock_calls) == 1
|
assert len(mock_is_plugged_in.mock_calls) == 1
|
||||||
|
|
||||||
|
matcher = mock_is_plugged_in.mock_calls[0].args[1]
|
||||||
|
assert matcher["vid"].isupper()
|
||||||
|
assert matcher["pid"].isupper()
|
||||||
|
assert matcher["serial_number"].islower()
|
||||||
|
assert matcher["manufacturer"].islower()
|
||||||
|
assert matcher["description"].islower()
|
||||||
|
|
||||||
# Finish setting up ZHA
|
# Finish setting up ZHA
|
||||||
if num_entries > 0:
|
if num_entries > 0:
|
||||||
zha_flows = hass.config_entries.flow.async_progress_by_handler("zha")
|
zha_flows = hass.config_entries.flow.async_progress_by_handler("zha")
|
||||||
@ -119,12 +126,12 @@ async def test_setup_zha(mock_zha_config_flow_setup, hass: HomeAssistant) -> Non
|
|||||||
"device": {
|
"device": {
|
||||||
"baudrate": 115200,
|
"baudrate": 115200,
|
||||||
"flow_control": "software",
|
"flow_control": "software",
|
||||||
"path": "bla_device",
|
"path": CONFIG_ENTRY_DATA["device"],
|
||||||
},
|
},
|
||||||
"radio_type": "ezsp",
|
"radio_type": "ezsp",
|
||||||
}
|
}
|
||||||
assert config_entry.options == {}
|
assert config_entry.options == {}
|
||||||
assert config_entry.title == "bla_description"
|
assert config_entry.title == CONFIG_ENTRY_DATA["description"]
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_entry_wait_usb(hass: HomeAssistant) -> None:
|
async def test_setup_entry_wait_usb(hass: HomeAssistant) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user