Only redact zwave_js values that are worth redacting (#78420)
* Only redact zwave_js values that are worth redacting * Tweak test * Use redacted fixture for testpull/78703/head
parent
8229e241f1
commit
a4749178f1
|
@ -51,6 +51,9 @@ VALUES_TO_REDACT = (
|
|||
|
||||
def redact_value_of_zwave_value(zwave_value: ValueDataType) -> ValueDataType:
|
||||
"""Redact value of a Z-Wave value."""
|
||||
# If the value has no value, there is nothing to redact
|
||||
if zwave_value.get("value") in (None, ""):
|
||||
return zwave_value
|
||||
for value_to_redact in VALUES_TO_REDACT:
|
||||
command_class = None
|
||||
if "commandClass" in zwave_value:
|
||||
|
|
|
@ -264,6 +264,12 @@ def config_entry_diagnostics_fixture():
|
|||
return json.loads(load_fixture("zwave_js/config_entry_diagnostics.json"))
|
||||
|
||||
|
||||
@pytest.fixture(name="config_entry_diagnostics_redacted", scope="session")
|
||||
def config_entry_diagnostics_redacted_fixture():
|
||||
"""Load the redacted config entry diagnostics fixture data."""
|
||||
return json.loads(load_fixture("zwave_js/config_entry_diagnostics_redacted.json"))
|
||||
|
||||
|
||||
@pytest.fixture(name="multisensor_6_state", scope="session")
|
||||
def multisensor_6_state_fixture():
|
||||
"""Load the multisensor 6 node state fixture data."""
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -4,7 +4,6 @@ from unittest.mock import patch
|
|||
import pytest
|
||||
from zwave_js_server.event import Event
|
||||
|
||||
from homeassistant.components.diagnostics.const import REDACTED
|
||||
from homeassistant.components.zwave_js.diagnostics import (
|
||||
ZwaveValueMatcher,
|
||||
async_get_device_diagnostics,
|
||||
|
@ -26,7 +25,11 @@ from tests.components.diagnostics import (
|
|||
|
||||
|
||||
async def test_config_entry_diagnostics(
|
||||
hass, hass_client, integration, config_entry_diagnostics
|
||||
hass,
|
||||
hass_client,
|
||||
integration,
|
||||
config_entry_diagnostics,
|
||||
config_entry_diagnostics_redacted,
|
||||
):
|
||||
"""Test the config entry level diagnostics data dump."""
|
||||
with patch(
|
||||
|
@ -36,16 +39,7 @@ async def test_config_entry_diagnostics(
|
|||
diagnostics = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, integration
|
||||
)
|
||||
assert len(diagnostics) == 3
|
||||
assert diagnostics[0]["homeId"] == REDACTED
|
||||
nodes = diagnostics[2]["result"]["state"]["nodes"]
|
||||
for node in nodes:
|
||||
assert "location" not in node or node["location"] == REDACTED
|
||||
for value in node["values"]:
|
||||
if value["commandClass"] == 99 and value["property"] == "userCode":
|
||||
assert value["value"] == REDACTED
|
||||
else:
|
||||
assert value.get("value") != REDACTED
|
||||
assert diagnostics == config_entry_diagnostics_redacted
|
||||
|
||||
|
||||
async def test_device_diagnostics(
|
||||
|
|
Loading…
Reference in New Issue