Simplify zwave_js USB discovery add-on form (#60845)

pull/59205/head^2
Martin Hjelmare 2021-12-02 16:30:01 +01:00 committed by GitHub
parent bf6ca2527d
commit c8781bbe3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 21 deletions

View File

@ -301,6 +301,7 @@ class ConfigFlow(BaseZwaveJSFlow, config_entries.ConfigFlow, domain=DOMAIN):
super().__init__()
self.use_addon = False
self._title: str | None = None
self._usb_discovery = False
@property
def flow_manager(self) -> config_entries.ConfigEntriesFlowManager:
@ -387,6 +388,8 @@ class ConfigFlow(BaseZwaveJSFlow, config_entries.ConfigFlow, domain=DOMAIN):
data_schema=vol.Schema({}),
)
self._usb_discovery = True
return await self.async_step_on_supervisor({CONF_USE_ADDON: True})
async def async_step_manual(
@ -504,7 +507,8 @@ class ConfigFlow(BaseZwaveJSFlow, config_entries.ConfigFlow, domain=DOMAIN):
self.s2_access_control_key = user_input[CONF_S2_ACCESS_CONTROL_KEY]
self.s2_authenticated_key = user_input[CONF_S2_AUTHENTICATED_KEY]
self.s2_unauthenticated_key = user_input[CONF_S2_UNAUTHENTICATED_KEY]
self.usb_path = user_input[CONF_USB_PATH]
if not self._usb_discovery:
self.usb_path = user_input[CONF_USB_PATH]
new_addon_config = {
**addon_config,
@ -534,21 +538,21 @@ class ConfigFlow(BaseZwaveJSFlow, config_entries.ConfigFlow, domain=DOMAIN):
CONF_ADDON_S2_UNAUTHENTICATED_KEY, self.s2_unauthenticated_key or ""
)
data_schema = vol.Schema(
{
vol.Required(CONF_USB_PATH, default=usb_path): str,
vol.Optional(CONF_S0_LEGACY_KEY, default=s0_legacy_key): str,
vol.Optional(
CONF_S2_ACCESS_CONTROL_KEY, default=s2_access_control_key
): str,
vol.Optional(
CONF_S2_AUTHENTICATED_KEY, default=s2_authenticated_key
): str,
vol.Optional(
CONF_S2_UNAUTHENTICATED_KEY, default=s2_unauthenticated_key
): str,
}
)
schema = {
vol.Optional(CONF_S0_LEGACY_KEY, default=s0_legacy_key): str,
vol.Optional(
CONF_S2_ACCESS_CONTROL_KEY, default=s2_access_control_key
): str,
vol.Optional(CONF_S2_AUTHENTICATED_KEY, default=s2_authenticated_key): str,
vol.Optional(
CONF_S2_UNAUTHENTICATED_KEY, default=s2_unauthenticated_key
): str,
}
if not self._usb_discovery:
schema = {vol.Required(CONF_USB_PATH, default=usb_path): str, **schema}
data_schema = vol.Schema(schema)
return self.async_show_form(step_id="configure_addon", data_schema=data_schema)

View File

@ -475,7 +475,6 @@ async def test_usb_discovery(
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
"usb_path": "/test",
"s0_legacy_key": "new123",
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
@ -488,7 +487,7 @@ async def test_usb_discovery(
"core_zwave_js",
{
"options": {
"device": "/test",
"device": USB_DISCOVERY_INFO["device"],
"s0_legacy_key": "new123",
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
@ -516,7 +515,7 @@ async def test_usb_discovery(
assert result["title"] == TITLE
assert result["data"] == {
"url": "ws://host1:3001",
"usb_path": "/test",
"usb_path": USB_DISCOVERY_INFO["device"],
"s0_legacy_key": "new123",
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
@ -557,7 +556,6 @@ async def test_usb_discovery_addon_not_running(
# Make sure the discovered usb device is preferred.
data_schema = result["data_schema"]
assert data_schema({}) == {
"usb_path": USB_DISCOVERY_INFO["device"],
"s0_legacy_key": "",
"s2_access_control_key": "",
"s2_authenticated_key": "",
@ -567,7 +565,6 @@ async def test_usb_discovery_addon_not_running(
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
"usb_path": USB_DISCOVERY_INFO["device"],
"s0_legacy_key": "new123",
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",