Add new security keys to zwave_js config flow (#115835)

This commit is contained in:
Raman Gupta
2024-06-08 11:31:05 -04:00
committed by GitHub
parent 43343ea44a
commit 2c41451abc
5 changed files with 254 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ from contextlib import suppress
import logging
from typing import Any
from awesomeversion import AwesomeVersion
from zwave_js_server.client import Client as ZwaveClient
from zwave_js_server.const import CommandClass, RemoveNodeReason
from zwave_js_server.exceptions import BaseZwaveJSServerError, InvalidServerVersion
@@ -78,6 +79,8 @@ from .const import (
ATTR_VALUE,
ATTR_VALUE_RAW,
CONF_ADDON_DEVICE,
CONF_ADDON_LR_S2_ACCESS_CONTROL_KEY,
CONF_ADDON_LR_S2_AUTHENTICATED_KEY,
CONF_ADDON_NETWORK_KEY,
CONF_ADDON_S0_LEGACY_KEY,
CONF_ADDON_S2_ACCESS_CONTROL_KEY,
@@ -85,6 +88,8 @@ from .const import (
CONF_ADDON_S2_UNAUTHENTICATED_KEY,
CONF_DATA_COLLECTION_OPTED_IN,
CONF_INTEGRATION_CREATED_ADDON,
CONF_LR_S2_ACCESS_CONTROL_KEY,
CONF_LR_S2_AUTHENTICATED_KEY,
CONF_NETWORK_KEY,
CONF_S0_LEGACY_KEY,
CONF_S2_ACCESS_CONTROL_KEY,
@@ -97,6 +102,7 @@ from .const import (
EVENT_DEVICE_ADDED_TO_REGISTRY,
LIB_LOGGER,
LOGGER,
LR_ADDON_VERSION,
USER_AGENT,
ZWAVE_JS_NOTIFICATION_EVENT,
ZWAVE_JS_VALUE_NOTIFICATION_EVENT,
@@ -1051,8 +1057,9 @@ async def async_ensure_addon_running(hass: HomeAssistant, entry: ConfigEntry) ->
s2_access_control_key: str = entry.data.get(CONF_S2_ACCESS_CONTROL_KEY, "")
s2_authenticated_key: str = entry.data.get(CONF_S2_AUTHENTICATED_KEY, "")
s2_unauthenticated_key: str = entry.data.get(CONF_S2_UNAUTHENTICATED_KEY, "")
lr_s2_access_control_key: str = entry.data.get(CONF_LR_S2_ACCESS_CONTROL_KEY, "")
lr_s2_authenticated_key: str = entry.data.get(CONF_LR_S2_AUTHENTICATED_KEY, "")
addon_state = addon_info.state
addon_config = {
CONF_ADDON_DEVICE: usb_path,
CONF_ADDON_S0_LEGACY_KEY: s0_legacy_key,
@@ -1060,6 +1067,9 @@ async def async_ensure_addon_running(hass: HomeAssistant, entry: ConfigEntry) ->
CONF_ADDON_S2_AUTHENTICATED_KEY: s2_authenticated_key,
CONF_ADDON_S2_UNAUTHENTICATED_KEY: s2_unauthenticated_key,
}
if addon_info.version and AwesomeVersion(addon_info.version) >= LR_ADDON_VERSION:
addon_config[CONF_ADDON_LR_S2_ACCESS_CONTROL_KEY] = lr_s2_access_control_key
addon_config[CONF_ADDON_LR_S2_AUTHENTICATED_KEY] = lr_s2_authenticated_key
if addon_state == AddonState.NOT_INSTALLED:
addon_manager.async_schedule_install_setup_addon(
@@ -1099,6 +1109,21 @@ async def async_ensure_addon_running(hass: HomeAssistant, entry: ConfigEntry) ->
updates[CONF_S2_AUTHENTICATED_KEY] = addon_s2_authenticated_key
if s2_unauthenticated_key != addon_s2_unauthenticated_key:
updates[CONF_S2_UNAUTHENTICATED_KEY] = addon_s2_unauthenticated_key
if addon_info.version and AwesomeVersion(addon_info.version) >= AwesomeVersion(
LR_ADDON_VERSION
):
addon_lr_s2_access_control_key = addon_options.get(
CONF_ADDON_LR_S2_ACCESS_CONTROL_KEY, ""
)
addon_lr_s2_authenticated_key = addon_options.get(
CONF_ADDON_LR_S2_AUTHENTICATED_KEY, ""
)
if lr_s2_access_control_key != addon_lr_s2_access_control_key:
updates[CONF_LR_S2_ACCESS_CONTROL_KEY] = addon_lr_s2_access_control_key
if lr_s2_authenticated_key != addon_lr_s2_authenticated_key:
updates[CONF_LR_S2_AUTHENTICATED_KEY] = addon_lr_s2_authenticated_key
if updates:
hass.config_entries.async_update_entry(entry, data={**entry.data, **updates})

View File

@@ -46,12 +46,16 @@ from .const import (
CONF_ADDON_DEVICE,
CONF_ADDON_EMULATE_HARDWARE,
CONF_ADDON_LOG_LEVEL,
CONF_ADDON_LR_S2_ACCESS_CONTROL_KEY,
CONF_ADDON_LR_S2_AUTHENTICATED_KEY,
CONF_ADDON_NETWORK_KEY,
CONF_ADDON_S0_LEGACY_KEY,
CONF_ADDON_S2_ACCESS_CONTROL_KEY,
CONF_ADDON_S2_AUTHENTICATED_KEY,
CONF_ADDON_S2_UNAUTHENTICATED_KEY,
CONF_INTEGRATION_CREATED_ADDON,
CONF_LR_S2_ACCESS_CONTROL_KEY,
CONF_LR_S2_AUTHENTICATED_KEY,
CONF_S0_LEGACY_KEY,
CONF_S2_ACCESS_CONTROL_KEY,
CONF_S2_AUTHENTICATED_KEY,
@@ -86,6 +90,8 @@ ADDON_USER_INPUT_MAP = {
CONF_ADDON_S2_ACCESS_CONTROL_KEY: CONF_S2_ACCESS_CONTROL_KEY,
CONF_ADDON_S2_AUTHENTICATED_KEY: CONF_S2_AUTHENTICATED_KEY,
CONF_ADDON_S2_UNAUTHENTICATED_KEY: CONF_S2_UNAUTHENTICATED_KEY,
CONF_ADDON_LR_S2_ACCESS_CONTROL_KEY: CONF_LR_S2_ACCESS_CONTROL_KEY,
CONF_ADDON_LR_S2_AUTHENTICATED_KEY: CONF_LR_S2_AUTHENTICATED_KEY,
CONF_ADDON_LOG_LEVEL: CONF_LOG_LEVEL,
CONF_ADDON_EMULATE_HARDWARE: CONF_EMULATE_HARDWARE,
}
@@ -172,6 +178,8 @@ class BaseZwaveJSFlow(ConfigEntryBaseFlow, ABC):
self.s2_access_control_key: str | None = None
self.s2_authenticated_key: str | None = None
self.s2_unauthenticated_key: str | None = None
self.lr_s2_access_control_key: str | None = None
self.lr_s2_authenticated_key: str | None = None
self.usb_path: str | None = None
self.ws_address: str | None = None
self.restart_addon: bool = False
@@ -565,6 +573,12 @@ class ZWaveJSConfigFlow(BaseZwaveJSFlow, ConfigFlow, domain=DOMAIN):
self.s2_unauthenticated_key = addon_config.get(
CONF_ADDON_S2_UNAUTHENTICATED_KEY, ""
)
self.lr_s2_access_control_key = addon_config.get(
CONF_ADDON_LR_S2_ACCESS_CONTROL_KEY, ""
)
self.lr_s2_authenticated_key = addon_config.get(
CONF_ADDON_LR_S2_AUTHENTICATED_KEY, ""
)
return await self.async_step_finish_addon_setup()
if addon_info.state == AddonState.NOT_RUNNING:
@@ -584,6 +598,8 @@ class ZWaveJSConfigFlow(BaseZwaveJSFlow, 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.lr_s2_access_control_key = user_input[CONF_LR_S2_ACCESS_CONTROL_KEY]
self.lr_s2_authenticated_key = user_input[CONF_LR_S2_AUTHENTICATED_KEY]
if not self._usb_discovery:
self.usb_path = user_input[CONF_USB_PATH]
@@ -594,6 +610,8 @@ class ZWaveJSConfigFlow(BaseZwaveJSFlow, ConfigFlow, domain=DOMAIN):
CONF_ADDON_S2_ACCESS_CONTROL_KEY: self.s2_access_control_key,
CONF_ADDON_S2_AUTHENTICATED_KEY: self.s2_authenticated_key,
CONF_ADDON_S2_UNAUTHENTICATED_KEY: self.s2_unauthenticated_key,
CONF_ADDON_LR_S2_ACCESS_CONTROL_KEY: self.lr_s2_access_control_key,
CONF_ADDON_LR_S2_AUTHENTICATED_KEY: self.lr_s2_authenticated_key,
}
if new_addon_config != addon_config:
@@ -614,6 +632,12 @@ class ZWaveJSConfigFlow(BaseZwaveJSFlow, ConfigFlow, domain=DOMAIN):
s2_unauthenticated_key = addon_config.get(
CONF_ADDON_S2_UNAUTHENTICATED_KEY, self.s2_unauthenticated_key or ""
)
lr_s2_access_control_key = addon_config.get(
CONF_ADDON_LR_S2_ACCESS_CONTROL_KEY, self.lr_s2_access_control_key or ""
)
lr_s2_authenticated_key = addon_config.get(
CONF_ADDON_LR_S2_AUTHENTICATED_KEY, self.lr_s2_authenticated_key or ""
)
schema = {
vol.Optional(CONF_S0_LEGACY_KEY, default=s0_legacy_key): str,
@@ -624,6 +648,12 @@ class ZWaveJSConfigFlow(BaseZwaveJSFlow, ConfigFlow, domain=DOMAIN):
vol.Optional(
CONF_S2_UNAUTHENTICATED_KEY, default=s2_unauthenticated_key
): str,
vol.Optional(
CONF_LR_S2_ACCESS_CONTROL_KEY, default=lr_s2_access_control_key
): str,
vol.Optional(
CONF_LR_S2_AUTHENTICATED_KEY, default=lr_s2_authenticated_key
): str,
}
if not self._usb_discovery:
@@ -670,6 +700,8 @@ class ZWaveJSConfigFlow(BaseZwaveJSFlow, ConfigFlow, domain=DOMAIN):
CONF_S2_ACCESS_CONTROL_KEY: self.s2_access_control_key,
CONF_S2_AUTHENTICATED_KEY: self.s2_authenticated_key,
CONF_S2_UNAUTHENTICATED_KEY: self.s2_unauthenticated_key,
CONF_LR_S2_ACCESS_CONTROL_KEY: self.lr_s2_access_control_key,
CONF_LR_S2_AUTHENTICATED_KEY: self.lr_s2_authenticated_key,
}
)
return self._async_create_entry_from_vars()
@@ -690,6 +722,8 @@ class ZWaveJSConfigFlow(BaseZwaveJSFlow, ConfigFlow, domain=DOMAIN):
CONF_S2_ACCESS_CONTROL_KEY: self.s2_access_control_key,
CONF_S2_AUTHENTICATED_KEY: self.s2_authenticated_key,
CONF_S2_UNAUTHENTICATED_KEY: self.s2_unauthenticated_key,
CONF_LR_S2_ACCESS_CONTROL_KEY: self.lr_s2_access_control_key,
CONF_LR_S2_AUTHENTICATED_KEY: self.lr_s2_authenticated_key,
CONF_USE_ADDON: self.use_addon,
CONF_INTEGRATION_CREATED_ADDON: self.integration_created_addon,
},
@@ -801,6 +835,8 @@ class OptionsFlowHandler(BaseZwaveJSFlow, OptionsFlow):
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.lr_s2_access_control_key = user_input[CONF_LR_S2_ACCESS_CONTROL_KEY]
self.lr_s2_authenticated_key = user_input[CONF_LR_S2_AUTHENTICATED_KEY]
self.usb_path = user_input[CONF_USB_PATH]
new_addon_config = {
@@ -810,6 +846,8 @@ class OptionsFlowHandler(BaseZwaveJSFlow, OptionsFlow):
CONF_ADDON_S2_ACCESS_CONTROL_KEY: self.s2_access_control_key,
CONF_ADDON_S2_AUTHENTICATED_KEY: self.s2_authenticated_key,
CONF_ADDON_S2_UNAUTHENTICATED_KEY: self.s2_unauthenticated_key,
CONF_ADDON_LR_S2_ACCESS_CONTROL_KEY: self.lr_s2_access_control_key,
CONF_ADDON_LR_S2_AUTHENTICATED_KEY: self.lr_s2_authenticated_key,
CONF_ADDON_LOG_LEVEL: user_input[CONF_LOG_LEVEL],
CONF_ADDON_EMULATE_HARDWARE: user_input.get(
CONF_EMULATE_HARDWARE, False
@@ -850,6 +888,12 @@ class OptionsFlowHandler(BaseZwaveJSFlow, OptionsFlow):
s2_unauthenticated_key = addon_config.get(
CONF_ADDON_S2_UNAUTHENTICATED_KEY, self.s2_unauthenticated_key or ""
)
lr_s2_access_control_key = addon_config.get(
CONF_ADDON_LR_S2_ACCESS_CONTROL_KEY, self.lr_s2_access_control_key or ""
)
lr_s2_authenticated_key = addon_config.get(
CONF_ADDON_LR_S2_AUTHENTICATED_KEY, self.lr_s2_authenticated_key or ""
)
log_level = addon_config.get(CONF_ADDON_LOG_LEVEL, "info")
emulate_hardware = addon_config.get(CONF_ADDON_EMULATE_HARDWARE, False)
@@ -868,6 +912,12 @@ class OptionsFlowHandler(BaseZwaveJSFlow, OptionsFlow):
vol.Optional(
CONF_S2_UNAUTHENTICATED_KEY, default=s2_unauthenticated_key
): str,
vol.Optional(
CONF_LR_S2_ACCESS_CONTROL_KEY, default=lr_s2_access_control_key
): str,
vol.Optional(
CONF_LR_S2_AUTHENTICATED_KEY, default=lr_s2_authenticated_key
): str,
vol.Optional(CONF_LOG_LEVEL, default=log_level): vol.In(
ADDON_LOG_LEVELS
),
@@ -921,6 +971,8 @@ class OptionsFlowHandler(BaseZwaveJSFlow, OptionsFlow):
CONF_S2_ACCESS_CONTROL_KEY: self.s2_access_control_key,
CONF_S2_AUTHENTICATED_KEY: self.s2_authenticated_key,
CONF_S2_UNAUTHENTICATED_KEY: self.s2_unauthenticated_key,
CONF_LR_S2_ACCESS_CONTROL_KEY: self.lr_s2_access_control_key,
CONF_LR_S2_AUTHENTICATED_KEY: self.lr_s2_authenticated_key,
CONF_USE_ADDON: True,
CONF_INTEGRATION_CREATED_ADDON: self.integration_created_addon,
}

View File

@@ -4,12 +4,15 @@ from __future__ import annotations
import logging
from awesomeversion import AwesomeVersion
from zwave_js_server.const.command_class.window_covering import (
WindowCoveringPropertyKey,
)
from homeassistant.const import APPLICATION_NAME, __version__ as HA_VERSION
LR_ADDON_VERSION = AwesomeVersion("0.5.0")
USER_AGENT = {APPLICATION_NAME: HA_VERSION}
CONF_ADDON_DEVICE = "device"
@@ -20,12 +23,16 @@ CONF_ADDON_S0_LEGACY_KEY = "s0_legacy_key"
CONF_ADDON_S2_ACCESS_CONTROL_KEY = "s2_access_control_key"
CONF_ADDON_S2_AUTHENTICATED_KEY = "s2_authenticated_key"
CONF_ADDON_S2_UNAUTHENTICATED_KEY = "s2_unauthenticated_key"
CONF_ADDON_LR_S2_ACCESS_CONTROL_KEY = "lr_s2_access_control_key"
CONF_ADDON_LR_S2_AUTHENTICATED_KEY = "lr_s2_authenticated_key"
CONF_INTEGRATION_CREATED_ADDON = "integration_created_addon"
CONF_NETWORK_KEY = "network_key"
CONF_S0_LEGACY_KEY = "s0_legacy_key"
CONF_S2_ACCESS_CONTROL_KEY = "s2_access_control_key"
CONF_S2_AUTHENTICATED_KEY = "s2_authenticated_key"
CONF_S2_UNAUTHENTICATED_KEY = "s2_unauthenticated_key"
CONF_LR_S2_ACCESS_CONTROL_KEY = "lr_s2_access_control_key"
CONF_LR_S2_AUTHENTICATED_KEY = "lr_s2_authenticated_key"
CONF_USB_PATH = "usb_path"
CONF_USE_ADDON = "use_addon"
CONF_DATA_COLLECTION_OPTED_IN = "data_collection_opted_in"

View File

@@ -222,6 +222,8 @@ async def test_manual(hass: HomeAssistant) -> None:
"s2_access_control_key": None,
"s2_authenticated_key": None,
"s2_unauthenticated_key": None,
"lr_s2_access_control_key": None,
"lr_s2_authenticated_key": None,
"use_addon": False,
"integration_created_addon": False,
}
@@ -343,6 +345,8 @@ async def test_supervisor_discovery(
addon_options["s2_access_control_key"] = "new456"
addon_options["s2_authenticated_key"] = "new789"
addon_options["s2_unauthenticated_key"] = "new987"
addon_options["lr_s2_access_control_key"] = "new654"
addon_options["lr_s2_authenticated_key"] = "new321"
result = await hass.config_entries.flow.async_init(
DOMAIN,
@@ -376,6 +380,8 @@ async def test_supervisor_discovery(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
"use_addon": True,
"integration_created_addon": False,
}
@@ -422,6 +428,8 @@ async def test_clean_discovery_on_user_create(
addon_options["s2_access_control_key"] = "new456"
addon_options["s2_authenticated_key"] = "new789"
addon_options["s2_unauthenticated_key"] = "new987"
addon_options["lr_s2_access_control_key"] = "new654"
addon_options["lr_s2_authenticated_key"] = "new321"
result = await hass.config_entries.flow.async_init(
DOMAIN,
@@ -477,6 +485,8 @@ async def test_clean_discovery_on_user_create(
"s2_access_control_key": None,
"s2_authenticated_key": None,
"s2_unauthenticated_key": None,
"lr_s2_access_control_key": None,
"lr_s2_authenticated_key": None,
"use_addon": False,
"integration_created_addon": False,
}
@@ -606,6 +616,8 @@ async def test_usb_discovery(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
},
)
@@ -619,6 +631,8 @@ async def test_usb_discovery(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
}
},
)
@@ -650,6 +664,8 @@ async def test_usb_discovery(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
"use_addon": True,
"integration_created_addon": True,
}
@@ -690,6 +706,8 @@ async def test_usb_discovery_addon_not_running(
"s2_access_control_key": "",
"s2_authenticated_key": "",
"s2_unauthenticated_key": "",
"lr_s2_access_control_key": "",
"lr_s2_authenticated_key": "",
}
result = await hass.config_entries.flow.async_configure(
@@ -699,6 +717,8 @@ async def test_usb_discovery_addon_not_running(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
},
)
@@ -712,6 +732,8 @@ async def test_usb_discovery_addon_not_running(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
}
},
)
@@ -743,6 +765,8 @@ async def test_usb_discovery_addon_not_running(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
"use_addon": True,
"integration_created_addon": False,
}
@@ -788,6 +812,8 @@ async def test_discovery_addon_not_running(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
},
)
@@ -801,6 +827,8 @@ async def test_discovery_addon_not_running(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
}
},
)
@@ -832,6 +860,8 @@ async def test_discovery_addon_not_running(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
"use_addon": True,
"integration_created_addon": False,
}
@@ -885,6 +915,8 @@ async def test_discovery_addon_not_installed(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
},
)
@@ -898,6 +930,8 @@ async def test_discovery_addon_not_installed(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
}
},
)
@@ -929,6 +963,8 @@ async def test_discovery_addon_not_installed(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
"use_addon": True,
"integration_created_addon": True,
}
@@ -1068,6 +1104,8 @@ async def test_not_addon(hass: HomeAssistant, supervisor) -> None:
"s2_access_control_key": None,
"s2_authenticated_key": None,
"s2_unauthenticated_key": None,
"lr_s2_access_control_key": None,
"lr_s2_authenticated_key": None,
"use_addon": False,
"integration_created_addon": False,
}
@@ -1089,6 +1127,8 @@ async def test_addon_running(
addon_options["s2_access_control_key"] = "new456"
addon_options["s2_authenticated_key"] = "new789"
addon_options["s2_unauthenticated_key"] = "new987"
addon_options["lr_s2_access_control_key"] = "new654"
addon_options["lr_s2_authenticated_key"] = "new321"
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
@@ -1120,6 +1160,8 @@ async def test_addon_running(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
"use_addon": True,
"integration_created_addon": False,
}
@@ -1207,6 +1249,9 @@ async def test_addon_running_already_configured(
addon_options["s2_access_control_key"] = "new456"
addon_options["s2_authenticated_key"] = "new789"
addon_options["s2_unauthenticated_key"] = "new987"
addon_options["lr_s2_access_control_key"] = "new654"
addon_options["lr_s2_authenticated_key"] = "new321"
entry = MockConfigEntry(
domain=DOMAIN,
data={
@@ -1217,6 +1262,8 @@ async def test_addon_running_already_configured(
"s2_access_control_key": "old456",
"s2_authenticated_key": "old789",
"s2_unauthenticated_key": "old987",
"lr_s2_access_control_key": "old654",
"lr_s2_authenticated_key": "old321",
},
title=TITLE,
unique_id=1234, # Unique ID is purposely set to int to test migration logic
@@ -1243,6 +1290,8 @@ async def test_addon_running_already_configured(
assert entry.data["s2_access_control_key"] == "new456"
assert entry.data["s2_authenticated_key"] == "new789"
assert entry.data["s2_unauthenticated_key"] == "new987"
assert entry.data["lr_s2_access_control_key"] == "new654"
assert entry.data["lr_s2_authenticated_key"] == "new321"
@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}])
@@ -1279,6 +1328,8 @@ async def test_addon_installed(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
},
)
@@ -1292,6 +1343,8 @@ async def test_addon_installed(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
}
},
)
@@ -1323,6 +1376,8 @@ async def test_addon_installed(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
"use_addon": True,
"integration_created_addon": False,
}
@@ -1367,6 +1422,8 @@ async def test_addon_installed_start_failure(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
},
)
@@ -1380,6 +1437,8 @@ async def test_addon_installed_start_failure(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
}
},
)
@@ -1442,6 +1501,8 @@ async def test_addon_installed_failures(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
},
)
@@ -1455,6 +1516,8 @@ async def test_addon_installed_failures(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
}
},
)
@@ -1508,6 +1571,8 @@ async def test_addon_installed_set_options_failure(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
},
)
@@ -1521,6 +1586,8 @@ async def test_addon_installed_set_options_failure(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
}
},
)
@@ -1552,6 +1619,8 @@ async def test_addon_installed_already_configured(
"s2_access_control_key": "old456",
"s2_authenticated_key": "old789",
"s2_unauthenticated_key": "old987",
"lr_s2_access_control_key": "old654",
"lr_s2_authenticated_key": "old321",
},
title=TITLE,
unique_id="1234",
@@ -1580,6 +1649,8 @@ async def test_addon_installed_already_configured(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
},
)
@@ -1593,6 +1664,8 @@ async def test_addon_installed_already_configured(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
}
},
)
@@ -1613,6 +1686,8 @@ async def test_addon_installed_already_configured(
assert entry.data["s2_access_control_key"] == "new456"
assert entry.data["s2_authenticated_key"] == "new789"
assert entry.data["s2_unauthenticated_key"] == "new987"
assert entry.data["lr_s2_access_control_key"] == "new654"
assert entry.data["lr_s2_authenticated_key"] == "new321"
@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}])
@@ -1659,6 +1734,8 @@ async def test_addon_not_installed(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
},
)
@@ -1672,6 +1749,8 @@ async def test_addon_not_installed(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
}
},
)
@@ -1703,6 +1782,8 @@ async def test_addon_not_installed(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
"use_addon": True,
"integration_created_addon": True,
}
@@ -1844,6 +1925,8 @@ async def test_options_not_addon(
"s2_access_control_key": "old456",
"s2_authenticated_key": "old789",
"s2_unauthenticated_key": "old987",
"lr_s2_access_control_key": "old654",
"lr_s2_authenticated_key": "old321",
},
{
"usb_path": "/new",
@@ -1851,6 +1934,8 @@ async def test_options_not_addon(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
"log_level": "info",
"emulate_hardware": False,
},
@@ -1866,6 +1951,8 @@ async def test_options_not_addon(
"s2_access_control_key": "old456",
"s2_authenticated_key": "old789",
"s2_unauthenticated_key": "old987",
"lr_s2_access_control_key": "old654",
"lr_s2_authenticated_key": "old321",
},
{
"usb_path": "/new",
@@ -1873,6 +1960,8 @@ async def test_options_not_addon(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
"log_level": "info",
"emulate_hardware": False,
},
@@ -1956,6 +2045,14 @@ async def test_options_addon_running(
entry.data["s2_unauthenticated_key"]
== new_addon_options["s2_unauthenticated_key"]
)
assert (
entry.data["lr_s2_access_control_key"]
== new_addon_options["lr_s2_access_control_key"]
)
assert (
entry.data["lr_s2_authenticated_key"]
== new_addon_options["lr_s2_authenticated_key"]
)
assert entry.data["use_addon"] is True
assert entry.data["integration_created_addon"] is False
assert client.connect.call_count == 2
@@ -1975,6 +2072,8 @@ async def test_options_addon_running(
"s2_access_control_key": "old456",
"s2_authenticated_key": "old789",
"s2_unauthenticated_key": "old987",
"lr_s2_access_control_key": "old654",
"lr_s2_authenticated_key": "old321",
"log_level": "info",
"emulate_hardware": False,
},
@@ -1984,6 +2083,8 @@ async def test_options_addon_running(
"s2_access_control_key": "old456",
"s2_authenticated_key": "old789",
"s2_unauthenticated_key": "old987",
"lr_s2_access_control_key": "old654",
"lr_s2_authenticated_key": "old321",
"log_level": "info",
"emulate_hardware": False,
},
@@ -2053,6 +2154,14 @@ async def test_options_addon_running_no_changes(
entry.data["s2_unauthenticated_key"]
== new_addon_options["s2_unauthenticated_key"]
)
assert (
entry.data["lr_s2_access_control_key"]
== new_addon_options["lr_s2_access_control_key"]
)
assert (
entry.data["lr_s2_authenticated_key"]
== new_addon_options["lr_s2_authenticated_key"]
)
assert entry.data["use_addon"] is True
assert entry.data["integration_created_addon"] is False
assert client.connect.call_count == 2
@@ -2090,6 +2199,8 @@ async def different_device_server_version(*args):
"s2_access_control_key": "old456",
"s2_authenticated_key": "old789",
"s2_unauthenticated_key": "old987",
"lr_s2_access_control_key": "old654",
"lr_s2_authenticated_key": "old321",
"log_level": "info",
"emulate_hardware": False,
},
@@ -2099,6 +2210,8 @@ async def different_device_server_version(*args):
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
"log_level": "info",
"emulate_hardware": False,
},
@@ -2115,6 +2228,8 @@ async def different_device_server_version(*args):
"s2_access_control_key": "old456",
"s2_authenticated_key": "old789",
"s2_unauthenticated_key": "old987",
"lr_s2_access_control_key": "old654",
"lr_s2_authenticated_key": "old321",
"log_level": "info",
},
{
@@ -2123,6 +2238,8 @@ async def different_device_server_version(*args):
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
"log_level": "info",
"emulate_hardware": False,
},
@@ -2244,6 +2361,8 @@ async def test_options_different_device(
"s2_access_control_key": "old456",
"s2_authenticated_key": "old789",
"s2_unauthenticated_key": "old987",
"lr_s2_access_control_key": "old654",
"lr_s2_authenticated_key": "old321",
"log_level": "info",
"emulate_hardware": False,
},
@@ -2253,6 +2372,8 @@ async def test_options_different_device(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
"log_level": "info",
"emulate_hardware": False,
},
@@ -2269,6 +2390,8 @@ async def test_options_different_device(
"s2_access_control_key": "old456",
"s2_authenticated_key": "old789",
"s2_unauthenticated_key": "old987",
"lr_s2_access_control_key": "old654",
"lr_s2_authenticated_key": "old321",
"log_level": "info",
"emulate_hardware": False,
},
@@ -2278,6 +2401,8 @@ async def test_options_different_device(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
"log_level": "info",
"emulate_hardware": False,
},
@@ -2399,6 +2524,8 @@ async def test_options_addon_restart_failed(
"s2_access_control_key": "old456",
"s2_authenticated_key": "old789",
"s2_unauthenticated_key": "old987",
"lr_s2_access_control_key": "old654",
"lr_s2_authenticated_key": "old321",
"log_level": "info",
"emulate_hardware": False,
},
@@ -2408,6 +2535,8 @@ async def test_options_addon_restart_failed(
"s2_access_control_key": "old456",
"s2_authenticated_key": "old789",
"s2_unauthenticated_key": "old987",
"lr_s2_access_control_key": "old654",
"lr_s2_authenticated_key": "old321",
"log_level": "info",
"emulate_hardware": False,
},
@@ -2488,6 +2617,8 @@ async def test_options_addon_running_server_info_failure(
"s2_access_control_key": "old456",
"s2_authenticated_key": "old789",
"s2_unauthenticated_key": "old987",
"lr_s2_access_control_key": "old654",
"lr_s2_authenticated_key": "old321",
},
{
"usb_path": "/new",
@@ -2495,6 +2626,8 @@ async def test_options_addon_running_server_info_failure(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
"log_level": "info",
"emulate_hardware": False,
},
@@ -2510,6 +2643,8 @@ async def test_options_addon_running_server_info_failure(
"s2_access_control_key": "old456",
"s2_authenticated_key": "old789",
"s2_unauthenticated_key": "old987",
"lr_s2_access_control_key": "old654",
"lr_s2_authenticated_key": "old321",
},
{
"usb_path": "/new",
@@ -2517,6 +2652,8 @@ async def test_options_addon_running_server_info_failure(
"s2_access_control_key": "new456",
"s2_authenticated_key": "new789",
"s2_unauthenticated_key": "new987",
"lr_s2_access_control_key": "new654",
"lr_s2_authenticated_key": "new321",
"log_level": "info",
"emulate_hardware": False,
},
@@ -2647,6 +2784,8 @@ async def test_import_addon_installed(
"s2_access_control_key": "",
"s2_authenticated_key": "",
"s2_unauthenticated_key": "",
"lr_s2_access_control_key": "",
"lr_s2_authenticated_key": "",
}
result = await hass.config_entries.flow.async_configure(
@@ -2663,6 +2802,8 @@ async def test_import_addon_installed(
"s2_access_control_key": "",
"s2_authenticated_key": "",
"s2_unauthenticated_key": "",
"lr_s2_access_control_key": "",
"lr_s2_authenticated_key": "",
}
},
)
@@ -2694,6 +2835,8 @@ async def test_import_addon_installed(
"s2_access_control_key": "",
"s2_authenticated_key": "",
"s2_unauthenticated_key": "",
"lr_s2_access_control_key": "",
"lr_s2_authenticated_key": "",
"use_addon": True,
"integration_created_addon": False,
}
@@ -2742,6 +2885,8 @@ async def test_zeroconf(hass: HomeAssistant) -> None:
"s2_access_control_key": None,
"s2_authenticated_key": None,
"s2_unauthenticated_key": None,
"lr_s2_access_control_key": None,
"lr_s2_authenticated_key": None,
"use_addon": False,
"integration_created_addon": False,
}

View File

@@ -519,12 +519,16 @@ async def test_start_addon(
s2_access_control_key = "s2_access_control"
s2_authenticated_key = "s2_authenticated"
s2_unauthenticated_key = "s2_unauthenticated"
lr_s2_access_control_key = "lr_s2_access_control"
lr_s2_authenticated_key = "lr_s2_authenticated"
addon_options = {
"device": device,
"s0_legacy_key": s0_legacy_key,
"s2_access_control_key": s2_access_control_key,
"s2_authenticated_key": s2_authenticated_key,
"s2_unauthenticated_key": s2_unauthenticated_key,
"lr_s2_access_control_key": lr_s2_access_control_key,
"lr_s2_authenticated_key": lr_s2_authenticated_key,
}
entry = MockConfigEntry(
domain=DOMAIN,
@@ -536,6 +540,8 @@ async def test_start_addon(
"s2_access_control_key": s2_access_control_key,
"s2_authenticated_key": s2_authenticated_key,
"s2_unauthenticated_key": s2_unauthenticated_key,
"lr_s2_access_control_key": lr_s2_access_control_key,
"lr_s2_authenticated_key": lr_s2_authenticated_key,
},
)
entry.add_to_hass(hass)
@@ -641,6 +647,10 @@ async def test_addon_info_failure(
"new_s2_authenticated_key",
"old_s2_unauthenticated_key",
"new_s2_unauthenticated_key",
"old_lr_s2_access_control_key",
"new_lr_s2_access_control_key",
"old_lr_s2_authenticated_key",
"new_lr_s2_authenticated_key",
),
[
(
@@ -654,6 +664,10 @@ async def test_addon_info_failure(
"new789",
"old987",
"new987",
"old654",
"new654",
"old321",
"new321",
)
],
)
@@ -675,6 +689,10 @@ async def test_addon_options_changed(
new_s2_authenticated_key,
old_s2_unauthenticated_key,
new_s2_unauthenticated_key,
old_lr_s2_access_control_key,
new_lr_s2_access_control_key,
old_lr_s2_authenticated_key,
new_lr_s2_authenticated_key,
) -> None:
"""Test update config entry data on entry setup if add-on options changed."""
addon_options["device"] = new_device
@@ -682,6 +700,8 @@ async def test_addon_options_changed(
addon_options["s2_access_control_key"] = new_s2_access_control_key
addon_options["s2_authenticated_key"] = new_s2_authenticated_key
addon_options["s2_unauthenticated_key"] = new_s2_unauthenticated_key
addon_options["lr_s2_access_control_key"] = new_lr_s2_access_control_key
addon_options["lr_s2_authenticated_key"] = new_lr_s2_authenticated_key
entry = MockConfigEntry(
domain=DOMAIN,
title="Z-Wave JS",
@@ -693,6 +713,8 @@ async def test_addon_options_changed(
"s2_access_control_key": old_s2_access_control_key,
"s2_authenticated_key": old_s2_authenticated_key,
"s2_unauthenticated_key": old_s2_unauthenticated_key,
"lr_s2_access_control_key": old_lr_s2_access_control_key,
"lr_s2_authenticated_key": old_lr_s2_authenticated_key,
},
)
entry.add_to_hass(hass)
@@ -706,6 +728,8 @@ async def test_addon_options_changed(
assert entry.data["s2_access_control_key"] == new_s2_access_control_key
assert entry.data["s2_authenticated_key"] == new_s2_authenticated_key
assert entry.data["s2_unauthenticated_key"] == new_s2_unauthenticated_key
assert entry.data["lr_s2_access_control_key"] == new_lr_s2_access_control_key
assert entry.data["lr_s2_authenticated_key"] == new_lr_s2_authenticated_key
assert install_addon.call_count == 0
assert start_addon.call_count == 0