Add options to UniFi Protect diagnostics (#82062)

pull/82058/head
Christopher Bailey 2022-11-13 18:57:09 -05:00 committed by GitHub
parent 298c95d9f0
commit ae436d46fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

View File

@ -18,4 +18,5 @@ async def async_get_config_entry_diagnostics(
"""Return diagnostics for a config entry."""
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)}

View File

@ -2,6 +2,7 @@
from pyunifiprotect.data import NVR, Light
from homeassistant.components.unifiprotect.const import CONF_ALLOW_EA
from homeassistant.core import HomeAssistant
from .utils import MockUFPFixture, init_entry
@ -16,12 +17,23 @@ async def test_diagnostics(
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)
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
# validate some of the data
assert "nvr" in diag and isinstance(diag["nvr"], dict)
nvr_dict = diag["nvr"]
assert "nvr" in bootstrap and isinstance(bootstrap["nvr"], dict)
nvr_dict = bootstrap["nvr"]
# should have been anonymized
assert nvr_dict["id"] != nvr.id
assert nvr_dict["mac"] != nvr.mac
@ -32,11 +44,11 @@ async def test_diagnostics(
assert nvr_dict["type"] == nvr.type
assert (
"lights" in diag
and isinstance(diag["lights"], list)
and len(diag["lights"]) == 1
"lights" in bootstrap
and isinstance(bootstrap["lights"], list)
and len(bootstrap["lights"]) == 1
)
light_dict = diag["lights"][0]
light_dict = bootstrap["lights"][0]
# should have been anonymized
assert light_dict["id"] != light.id
assert light_dict["name"] != light.mac