Skip to content

Commit f37df79

Browse files
authored
Redact serial from unknown component model name in diagnostics (home-assistant#176524)
1 parent 886f76c commit f37df79

2 files changed

Lines changed: 40 additions & 7 deletions

File tree

homeassistant/components/nobo_hub/diagnostics.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from typing import Any
44

5-
from pynobo import ComponentInfo
5+
from pynobo import ComponentInfo, nobo
66

7-
from homeassistant.components.diagnostics import async_redact_data
7+
from homeassistant.components.diagnostics import REDACTED, async_redact_data
88
from homeassistant.const import CONF_IP_ADDRESS, CONF_MAC
99
from homeassistant.core import HomeAssistant
1010

@@ -26,11 +26,12 @@
2626

2727

2828
def _component_to_dict(component: ComponentInfo) -> dict[str, Any]:
29-
formatted = dict(component)
30-
if (model := formatted.get("model")) is not None:
31-
formatted["model"] = {
32-
field: getattr(model, field, None) for field in _MODEL_FIELDS
33-
}
29+
model = component["model"]
30+
formatted: dict[str, Any] = dict(component)
31+
formatted["model"] = {field: getattr(model, field, None) for field in _MODEL_FIELDS}
32+
if model.type == nobo.Model.UNKNOWN:
33+
# Unknown models carry the serial number in the name.
34+
formatted["model"]["name"] = REDACTED
3435
return formatted
3536

3637

tests/components/nobo_hub/test_diagnostics.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
"""Tests for the Nobø Ecohub diagnostics."""
22

3+
from unittest.mock import MagicMock
4+
5+
from pynobo import nobo as pynobo_nobo
36
from syrupy.assertion import SnapshotAssertion
47

8+
from homeassistant.components.diagnostics import REDACTED
59
from homeassistant.core import HomeAssistant
610

711
from tests.common import MockConfigEntry
@@ -19,3 +23,31 @@ async def test_entry_diagnostics(
1923
result = await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
2024

2125
assert result == snapshot
26+
27+
28+
async def test_entry_diagnostics_redacts_unknown_model_name(
29+
hass: HomeAssistant,
30+
hass_client: ClientSessionGenerator,
31+
init_integration: MockConfigEntry,
32+
mock_nobo_hub: MagicMock,
33+
) -> None:
34+
"""An unknown model's name embeds the serial, so it is dropped; model_id is kept."""
35+
mock_nobo_hub.components = {
36+
"999000012345": {
37+
"serial": "999000012345",
38+
"name": "Mystery device",
39+
"zone_id": "1",
40+
"model": pynobo_nobo.Model(
41+
model_id="999",
42+
type=pynobo_nobo.Model.UNKNOWN,
43+
name="Unknown (serial number: 999 000 012 345)",
44+
),
45+
},
46+
}
47+
48+
result = await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
49+
50+
component = result["components"][0]
51+
assert component["serial"] == REDACTED
52+
assert component["model"]["model_id"] == "999"
53+
assert component["model"]["name"] == REDACTED

0 commit comments

Comments
 (0)