Add options to UniFi Protect diagnostics (#82062)
parent
298c95d9f0
commit
ae436d46fc
|
@ -18,4 +18,5 @@ async def async_get_config_entry_diagnostics(
|
||||||
"""Return diagnostics for a config entry."""
|
"""Return diagnostics for a config entry."""
|
||||||
|
|
||||||
data: ProtectData = hass.data[DOMAIN][config_entry.entry_id]
|
data: ProtectData = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
return cast(dict[str, Any], anonymize_data(data.api.bootstrap.unifi_dict()))
|
bootstrap = cast(dict[str, Any], anonymize_data(data.api.bootstrap.unifi_dict()))
|
||||||
|
return {"bootstrap": bootstrap, "options": dict(config_entry.options)}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
from pyunifiprotect.data import NVR, Light
|
from pyunifiprotect.data import NVR, Light
|
||||||
|
|
||||||
|
from homeassistant.components.unifiprotect.const import CONF_ALLOW_EA
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .utils import MockUFPFixture, init_entry
|
from .utils import MockUFPFixture, init_entry
|
||||||
|
@ -16,12 +17,23 @@ async def test_diagnostics(
|
||||||
|
|
||||||
await init_entry(hass, ufp, [light])
|
await init_entry(hass, ufp, [light])
|
||||||
|
|
||||||
|
options = dict(ufp.entry.options)
|
||||||
|
options[CONF_ALLOW_EA] = True
|
||||||
|
hass.config_entries.async_update_entry(ufp.entry, options=options)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
diag = await get_diagnostics_for_config_entry(hass, hass_client, ufp.entry)
|
diag = await get_diagnostics_for_config_entry(hass, hass_client, ufp.entry)
|
||||||
|
|
||||||
|
assert "options" in diag and isinstance(diag["options"], dict)
|
||||||
|
options = diag["options"]
|
||||||
|
assert options[CONF_ALLOW_EA] is True
|
||||||
|
|
||||||
|
assert "bootstrap" in diag and isinstance(diag["bootstrap"], dict)
|
||||||
|
bootstrap = diag["bootstrap"]
|
||||||
nvr: NVR = ufp.api.bootstrap.nvr
|
nvr: NVR = ufp.api.bootstrap.nvr
|
||||||
# validate some of the data
|
# validate some of the data
|
||||||
assert "nvr" in diag and isinstance(diag["nvr"], dict)
|
assert "nvr" in bootstrap and isinstance(bootstrap["nvr"], dict)
|
||||||
nvr_dict = diag["nvr"]
|
nvr_dict = bootstrap["nvr"]
|
||||||
# should have been anonymized
|
# should have been anonymized
|
||||||
assert nvr_dict["id"] != nvr.id
|
assert nvr_dict["id"] != nvr.id
|
||||||
assert nvr_dict["mac"] != nvr.mac
|
assert nvr_dict["mac"] != nvr.mac
|
||||||
|
@ -32,11 +44,11 @@ async def test_diagnostics(
|
||||||
assert nvr_dict["type"] == nvr.type
|
assert nvr_dict["type"] == nvr.type
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
"lights" in diag
|
"lights" in bootstrap
|
||||||
and isinstance(diag["lights"], list)
|
and isinstance(bootstrap["lights"], list)
|
||||||
and len(diag["lights"]) == 1
|
and len(bootstrap["lights"]) == 1
|
||||||
)
|
)
|
||||||
light_dict = diag["lights"][0]
|
light_dict = bootstrap["lights"][0]
|
||||||
# should have been anonymized
|
# should have been anonymized
|
||||||
assert light_dict["id"] != light.id
|
assert light_dict["id"] != light.id
|
||||||
assert light_dict["name"] != light.mac
|
assert light_dict["name"] != light.mac
|
||||||
|
|
Loading…
Reference in New Issue