Do not redact diagnostics empty key (#69160)

pull/69191/head
ollo69 2022-04-03 13:17:08 +02:00 committed by GitHub
parent d7992c1e87
commit 0876239927
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 2 deletions

View File

@ -33,6 +33,10 @@ def async_redact_data(data: _T, to_redact: Iterable[Any]) -> _T:
redacted = {**data} redacted = {**data}
for key, value in redacted.items(): for key, value in redacted.items():
if value is None:
continue
if isinstance(value, str) and not value:
continue
if key in to_redact: if key in to_redact:
redacted[key] = REDACTED redacted[key] = REDACTED
elif isinstance(value, Mapping): elif isinstance(value, Mapping):

View File

@ -15,7 +15,7 @@ from tests.components.diagnostics import get_diagnostics_for_config_entry
async def test_entry_diagnostics(hass, hass_client): async def test_entry_diagnostics(hass, hass_client):
"""Test config entry diagnostics.""" """Test config entry diagnostics."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, data={CONF_API_KEY: "", "location": ""} domain=DOMAIN, data={CONF_API_KEY: "api_key", "location": ""}
) )
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
with patch("CO2Signal.get_latest", return_value=VALID_PAYLOAD): with patch("CO2Signal.get_latest", return_value=VALID_PAYLOAD):

View File

@ -13,12 +13,18 @@ def test_redact():
"key4_2": ["value4_2a", "value4_2b"], "key4_2": ["value4_2a", "value4_2b"],
"key4_3": [["value4_3a", "value4_3b"], ["value4_3c", "value4_3d"]], "key4_3": [["value4_3a", "value4_3b"], ["value4_3c", "value4_3d"]],
}, },
"key5": None,
"key6": "",
"key7": False,
} }
to_redact = { to_redact = {
"key1", "key1",
"key3", "key3",
"key4_1", "key4_1",
"key5",
"key6",
"key7",
} }
assert async_redact_data(data, to_redact) == { assert async_redact_data(data, to_redact) == {
@ -30,4 +36,7 @@ def test_redact():
"key4_2": ["value4_2a", "value4_2b"], "key4_2": ["value4_2a", "value4_2b"],
"key4_3": [["value4_3a", "value4_3b"], ["value4_3c", "value4_3d"]], "key4_3": [["value4_3a", "value4_3b"], ["value4_3c", "value4_3d"]],
}, },
"key5": None,
"key6": "",
"key7": REDACTED,
} }

View File

@ -22,7 +22,7 @@ def mock_config_entry() -> MockConfigEntry:
data={ data={
CONF_HOST: "192.168.1.2", CONF_HOST: "192.168.1.2",
CONF_PORT: 6053, CONF_PORT: 6053,
CONF_PASSWORD: "", CONF_PASSWORD: "pwd",
CONF_NOISE_PSK: "12345678123456781234567812345678", CONF_NOISE_PSK: "12345678123456781234567812345678",
}, },
unique_id="esphome-device", unique_id="esphome-device",