diff --git a/homeassistant/components/homee/diagnostics.py b/homeassistant/components/homee/diagnostics.py new file mode 100644 index 00000000000..f3848bce341 --- /dev/null +++ b/homeassistant/components/homee/diagnostics.py @@ -0,0 +1,43 @@ +"""Diagnostics for homee integration.""" + +from typing import Any + +from homeassistant.components.diagnostics import async_redact_data +from homeassistant.const import CONF_PASSWORD, CONF_USERNAME +from homeassistant.core import HomeAssistant +from homeassistant.helpers.device_registry import DeviceEntry + +from . import DOMAIN, HomeeConfigEntry + +TO_REDACT = [CONF_PASSWORD, CONF_USERNAME, "latitude", "longitude", "wlan_ssid"] + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: HomeeConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + + return { + "entry_data": async_redact_data(entry.data, TO_REDACT), + "settings": async_redact_data(entry.runtime_data.settings.raw_data, TO_REDACT), + "devices": [{"node": node.raw_data} for node in entry.runtime_data.nodes], + } + + +async def async_get_device_diagnostics( + hass: HomeAssistant, entry: HomeeConfigEntry, device: DeviceEntry +) -> dict[str, Any]: + """Return diagnostics for a device.""" + + # Extract node_id from the device identifiers + split_uid = next( + identifier[1] for identifier in device.identifiers if identifier[0] == DOMAIN + ).split("-") + # Homee hub itself only has MAC as identifier and a node_id of -1 + node_id = -1 if len(split_uid) < 2 else split_uid[1] + + node = entry.runtime_data.get_node_by_id(int(node_id)) + assert node is not None + return { + "homee node": node.raw_data, + } diff --git a/tests/components/homee/__init__.py b/tests/components/homee/__init__.py index 432e2d68516..e83e257427e 100644 --- a/tests/components/homee/__init__.py +++ b/tests/components/homee/__init__.py @@ -46,6 +46,7 @@ def build_mock_node(file: str) -> AsyncMock: def attribute_by_type(type, instance=0) -> HomeeAttribute | None: return {attr.type: attr for attr in mock_node.attributes}.get(type) + mock_node.raw_data = json_node mock_node.get_attribute_by_type = attribute_by_type return mock_node diff --git a/tests/components/homee/conftest.py b/tests/components/homee/conftest.py index 75fc3dc830b..f9fa95c593f 100644 --- a/tests/components/homee/conftest.py +++ b/tests/components/homee/conftest.py @@ -39,6 +39,7 @@ def mock_config_entry() -> MockConfigEntry: CONF_PASSWORD: TESTPASS, }, unique_id=HOMEE_ID, + entry_id="test_entry_id", ) @@ -68,5 +69,15 @@ def mock_homee() -> Generator[AsyncMock]: homee.connected = True homee.get_access_token.return_value = "test_token" + # Mock the Homee settings raw_data for diagnostics + homee.settings.raw_data = { + "uid": HOMEE_ID, + "homee_name": HOMEE_NAME, + "version": "1.2.3", + "mac_address": "00:05:55:11:ee:cc", + "wlan_ssid": "TestSSID", + "latitude": 52.5200, + "longitude": 13.4050, + } yield homee diff --git a/tests/components/homee/snapshots/test_diagnostics.ambr b/tests/components/homee/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..e3e66980037 --- /dev/null +++ b/tests/components/homee/snapshots/test_diagnostics.ambr @@ -0,0 +1,1082 @@ +# serializer version: 1 +# name: test_diagnostics_config_entry + dict({ + 'devices': list([ + dict({ + 'node': dict({ + 'added': 1680027411, + 'attributes': list([ + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 100.0, + 'data': '', + 'editable': 1, + 'id': 1, + 'instance': 0, + 'last_changed': 1624446307, + 'last_value': 100.0, + 'maximum': 100, + 'minimum': 0, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 0.5, + 'target_value': 100.0, + 'type': 349, + 'unit': '%', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 38.0, + 'data': '', + 'editable': 1, + 'id': 2, + 'instance': 0, + 'last_changed': 1624446307, + 'last_value': 38.0, + 'maximum': 75, + 'minimum': -75, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 38.0, + 'type': 350, + 'unit': '°', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 57.0, + 'data': '', + 'editable': 1, + 'id': 3, + 'instance': 0, + 'last_changed': 1615396252, + 'last_value': 90.0, + 'maximum': 240, + 'minimum': 4, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 57.0, + 'type': 111, + 'unit': 's', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 129.0, + 'data': '', + 'editable': 1, + 'id': 4, + 'instance': 0, + 'last_changed': 1672086680, + 'last_value': 1.0, + 'maximum': 130, + 'minimum': 0, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 129.0, + 'type': 325, + 'unit': 'n/a', + }), + dict({ + 'based_on': 1, + 'changed_by': 0, + 'changed_by_id': 0, + 'current_value': 10.0, + 'data': '', + 'editable': 0, + 'id': 5, + 'instance': 0, + 'last_changed': 1676204559, + 'last_value': 10.0, + 'maximum': 15300, + 'minimum': 1, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 1.0, + 'type': 28, + 'unit': 's', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 3.0, + 'data': '', + 'editable': 1, + 'id': 6, + 'instance': 0, + 'last_changed': 1666336770, + 'last_value': 2.0, + 'maximum': 3, + 'minimum': 0, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 3.0, + 'type': 261, + 'unit': '', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 30.0, + 'data': '', + 'editable': 1, + 'id': 7, + 'instance': 0, + 'last_changed': 1672086680, + 'last_value': 0.0, + 'maximum': 45, + 'minimum': 5, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 5.0, + 'target_value': 30.0, + 'type': 88, + 'unit': 'min', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 1.6, + 'data': '', + 'editable': 1, + 'id': 8, + 'instance': 0, + 'last_changed': 1615396156, + 'last_value': 0.0, + 'maximum': 24, + 'minimum': 0, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 0.1, + 'target_value': 1.6, + 'type': 114, + 'unit': 's', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 75.0, + 'data': '', + 'editable': 1, + 'id': 9, + 'instance': 0, + 'last_changed': 1615396156, + 'last_value': 0.0, + 'maximum': 127, + 'minimum': -127, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 75.0, + 'type': 323, + 'unit': '°', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': -75.0, + 'data': '', + 'editable': 1, + 'id': 10, + 'instance': 0, + 'last_changed': 1615396156, + 'last_value': 0.0, + 'maximum': 127, + 'minimum': -127, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': -75.0, + 'type': 322, + 'unit': '°', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 6.0, + 'data': '', + 'editable': 1, + 'id': 11, + 'instance': 0, + 'last_changed': 1672149083, + 'last_value': 1.0, + 'maximum': 20, + 'minimum': 1, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 6.0, + 'type': 174, + 'unit': 'n/a', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': -3, + 'data': '', + 'editable': 1, + 'id': 12, + 'instance': 0, + 'last_changed': 1711799534, + 'last_value': 128.0, + 'maximum': 128, + 'minimum': -5, + 'name': '', + 'node_id': 1, + 'state': 6, + 'step_value': 0.1, + 'target_value': -3, + 'type': 64, + 'unit': '°C', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 57.0, + 'data': '', + 'editable': 1, + 'id': 13, + 'instance': 0, + 'last_changed': 1615396246, + 'last_value': 90.0, + 'maximum': 240, + 'minimum': 4, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 57.0, + 'type': 110, + 'unit': 's', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 600.0, + 'data': '', + 'editable': 1, + 'id': 14, + 'instance': 0, + 'last_changed': 1739333970, + 'last_value': 600.0, + 'maximum': 7200, + 'minimum': 30, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 30.0, + 'target_value': 600.0, + 'type': 29, + 'unit': 'min', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 12.0, + 'data': 'fixed_value', + 'editable': 0, + 'id': 15, + 'instance': 0, + 'last_changed': 1735964135, + 'last_value': 12.0, + 'maximum': 240, + 'minimum': 0, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 12.0, + 'type': 29, + 'unit': 'h', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 2.0, + 'data': '', + 'editable': 1, + 'id': 16, + 'instance': 0, + 'last_changed': 1684668852, + 'last_value': 2.0, + 'maximum': 9, + 'minimum': 0, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 2.0, + 'type': 338, + 'unit': 'n/a', + }), + ]), + 'cube_type': 3, + 'favorite': 0, + 'history': 1, + 'id': 1, + 'image': 'default', + 'name': 'Test Number', + 'note': '', + 'order': 1, + 'owner': 2, + 'phonetic_name': '', + 'profile': 2011, + 'protocol': 3, + 'routing': 0, + 'security': 0, + 'services': 0, + 'state': 1, + 'state_changed': 1731020474, + }), + }), + dict({ + 'node': dict({ + 'added': 1655274291, + 'attributes': list([ + dict({ + 'based_on': 1, + 'changed_by': 3, + 'changed_by_id': 0, + 'current_value': 22.0, + 'data': '', + 'editable': 1, + 'id': 1, + 'instance': 0, + 'last_changed': 1713695529, + 'last_value': 12.0, + 'maximum': 30, + 'minimum': 15, + 'name': '', + 'node_id': 2, + 'options': dict({ + 'automations': list([ + 'step', + ]), + 'history': dict({ + 'day': 35, + 'month': 1, + 'stepped': True, + 'week': 5, + }), + }), + 'state': 2, + 'step_value': 0.1, + 'target_value': 13.0, + 'type': 6, + 'unit': '°C', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 19.55, + 'data': '', + 'editable': 0, + 'id': 2, + 'instance': 0, + 'last_changed': 1713695528, + 'last_value': 21.07, + 'maximum': 125, + 'minimum': -50, + 'name': '', + 'node_id': 2, + 'options': dict({ + 'history': dict({ + 'day': 1, + 'month': 6, + 'week': 26, + }), + 'observed_by': list([ + 240, + ]), + }), + 'state': 1, + 'step_value': 0.1, + 'target_value': 19.55, + 'type': 5, + 'unit': '°C', + }), + ]), + 'cube_type': 1, + 'favorite': 0, + 'history': 1, + 'id': 2, + 'image': 'default', + 'name': 'Test Thermostat 2', + 'note': '', + 'order': 32, + 'owner': 2, + 'phonetic_name': '', + 'profile': 3003, + 'protocol': 1, + 'routing': 0, + 'security': 0, + 'services': 7, + 'state': 1, + 'state_changed': 1712840187, + }), + }), + dict({ + 'node': dict({ + 'added': 1672086680, + 'attributes': list([ + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 1.0, + 'data': '', + 'editable': 1, + 'id': 1, + 'instance': 0, + 'last_changed': 1687175680, + 'last_value': 4.0, + 'maximum': 4, + 'minimum': 0, + 'name': '', + 'node_id': 3, + 'options': dict({ + 'automations': list([ + 'toggle', + ]), + 'can_observe': list([ + 300, + ]), + 'observes': list([ + 75, + ]), + }), + 'state': 1, + 'step_value': 1.0, + 'target_value': 1.0, + 'type': 135, + 'unit': 'n/a', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 0.0, + 'data': '', + 'editable': 1, + 'id': 2, + 'instance': 0, + 'last_changed': 1687175680, + 'last_value': 0.0, + 'maximum': 100, + 'minimum': 0, + 'name': '', + 'node_id': 3, + 'options': dict({ + 'automations': list([ + 'step', + ]), + 'history': dict({ + 'day': 35, + 'month': 1, + 'week': 5, + }), + }), + 'state': 1, + 'step_value': 0.5, + 'target_value': 0.0, + 'type': 15, + 'unit': '%', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': -45.0, + 'data': '', + 'editable': 1, + 'id': 3, + 'instance': 0, + 'last_changed': 1678284920, + 'last_value': -45.0, + 'maximum': 90, + 'minimum': -45, + 'name': '', + 'node_id': 3, + 'options': dict({ + 'automations': list([ + 'step', + ]), + }), + 'state': 1, + 'step_value': 1.0, + 'target_value': 0.0, + 'type': 113, + 'unit': '°', + }), + ]), + 'cube_type': 14, + 'favorite': 0, + 'history': 1, + 'id': 3, + 'image': 'default', + 'name': 'Test Cover', + 'note': 'TestCoverDevice', + 'order': 4, + 'owner': 2, + 'phonetic_name': '', + 'profile': 2002, + 'protocol': 23, + 'routing': 0, + 'security': 0, + 'services': 7, + 'state': 1, + 'state_changed': 1687175681, + }), + }), + ]), + 'entry_data': dict({ + 'host': '192.168.1.11', + 'password': '**REDACTED**', + 'username': '**REDACTED**', + }), + 'settings': dict({ + 'homee_name': 'TestHomee', + 'latitude': '**REDACTED**', + 'longitude': '**REDACTED**', + 'mac_address': '00:05:55:11:ee:cc', + 'uid': '00055511EECC', + 'version': '1.2.3', + 'wlan_ssid': '**REDACTED**', + }), + }) +# --- +# name: test_diagnostics_device + dict({ + 'homee node': dict({ + 'added': 1680027411, + 'attributes': list([ + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 100.0, + 'data': '', + 'editable': 1, + 'id': 1, + 'instance': 0, + 'last_changed': 1624446307, + 'last_value': 100.0, + 'maximum': 100, + 'minimum': 0, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 0.5, + 'target_value': 100.0, + 'type': 349, + 'unit': '%', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 38.0, + 'data': '', + 'editable': 1, + 'id': 2, + 'instance': 0, + 'last_changed': 1624446307, + 'last_value': 38.0, + 'maximum': 75, + 'minimum': -75, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 38.0, + 'type': 350, + 'unit': '°', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 57.0, + 'data': '', + 'editable': 1, + 'id': 3, + 'instance': 0, + 'last_changed': 1615396252, + 'last_value': 90.0, + 'maximum': 240, + 'minimum': 4, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 57.0, + 'type': 111, + 'unit': 's', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 129.0, + 'data': '', + 'editable': 1, + 'id': 4, + 'instance': 0, + 'last_changed': 1672086680, + 'last_value': 1.0, + 'maximum': 130, + 'minimum': 0, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 129.0, + 'type': 325, + 'unit': 'n/a', + }), + dict({ + 'based_on': 1, + 'changed_by': 0, + 'changed_by_id': 0, + 'current_value': 10.0, + 'data': '', + 'editable': 0, + 'id': 5, + 'instance': 0, + 'last_changed': 1676204559, + 'last_value': 10.0, + 'maximum': 15300, + 'minimum': 1, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 1.0, + 'type': 28, + 'unit': 's', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 3.0, + 'data': '', + 'editable': 1, + 'id': 6, + 'instance': 0, + 'last_changed': 1666336770, + 'last_value': 2.0, + 'maximum': 3, + 'minimum': 0, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 3.0, + 'type': 261, + 'unit': '', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 30.0, + 'data': '', + 'editable': 1, + 'id': 7, + 'instance': 0, + 'last_changed': 1672086680, + 'last_value': 0.0, + 'maximum': 45, + 'minimum': 5, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 5.0, + 'target_value': 30.0, + 'type': 88, + 'unit': 'min', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 1.6, + 'data': '', + 'editable': 1, + 'id': 8, + 'instance': 0, + 'last_changed': 1615396156, + 'last_value': 0.0, + 'maximum': 24, + 'minimum': 0, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 0.1, + 'target_value': 1.6, + 'type': 114, + 'unit': 's', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 75.0, + 'data': '', + 'editable': 1, + 'id': 9, + 'instance': 0, + 'last_changed': 1615396156, + 'last_value': 0.0, + 'maximum': 127, + 'minimum': -127, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 75.0, + 'type': 323, + 'unit': '°', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': -75.0, + 'data': '', + 'editable': 1, + 'id': 10, + 'instance': 0, + 'last_changed': 1615396156, + 'last_value': 0.0, + 'maximum': 127, + 'minimum': -127, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': -75.0, + 'type': 322, + 'unit': '°', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 6.0, + 'data': '', + 'editable': 1, + 'id': 11, + 'instance': 0, + 'last_changed': 1672149083, + 'last_value': 1.0, + 'maximum': 20, + 'minimum': 1, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 6.0, + 'type': 174, + 'unit': 'n/a', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': -3, + 'data': '', + 'editable': 1, + 'id': 12, + 'instance': 0, + 'last_changed': 1711799534, + 'last_value': 128.0, + 'maximum': 128, + 'minimum': -5, + 'name': '', + 'node_id': 1, + 'state': 6, + 'step_value': 0.1, + 'target_value': -3, + 'type': 64, + 'unit': '°C', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 57.0, + 'data': '', + 'editable': 1, + 'id': 13, + 'instance': 0, + 'last_changed': 1615396246, + 'last_value': 90.0, + 'maximum': 240, + 'minimum': 4, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 57.0, + 'type': 110, + 'unit': 's', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 600.0, + 'data': '', + 'editable': 1, + 'id': 14, + 'instance': 0, + 'last_changed': 1739333970, + 'last_value': 600.0, + 'maximum': 7200, + 'minimum': 30, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 30.0, + 'target_value': 600.0, + 'type': 29, + 'unit': 'min', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 12.0, + 'data': 'fixed_value', + 'editable': 0, + 'id': 15, + 'instance': 0, + 'last_changed': 1735964135, + 'last_value': 12.0, + 'maximum': 240, + 'minimum': 0, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 12.0, + 'type': 29, + 'unit': 'h', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 2.0, + 'data': '', + 'editable': 1, + 'id': 16, + 'instance': 0, + 'last_changed': 1684668852, + 'last_value': 2.0, + 'maximum': 9, + 'minimum': 0, + 'name': '', + 'node_id': 1, + 'state': 1, + 'step_value': 1.0, + 'target_value': 2.0, + 'type': 338, + 'unit': 'n/a', + }), + ]), + 'cube_type': 3, + 'favorite': 0, + 'history': 1, + 'id': 1, + 'image': 'default', + 'name': 'Test Number', + 'note': '', + 'order': 1, + 'owner': 2, + 'phonetic_name': '', + 'profile': 2011, + 'protocol': 3, + 'routing': 0, + 'security': 0, + 'services': 0, + 'state': 1, + 'state_changed': 1731020474, + }), + }) +# --- +# name: test_diagnostics_homee_device + dict({ + 'homee node': dict({ + 'added': 16, + 'attributes': list([ + dict({ + 'based_on': 1, + 'changed_by': 2, + 'changed_by_id': 4, + 'current_value': 0.0, + 'data': '', + 'editable': 1, + 'id': 1, + 'instance': 0, + 'last_changed': 1735815716, + 'last_value': 2.0, + 'maximum': 200, + 'minimum': 0, + 'name': '', + 'node_id': -1, + 'options': dict({ + 'history': dict({ + 'day': 182, + 'month': 6, + 'stepped': True, + 'week': 26, + }), + }), + 'state': 1, + 'step_value': 1.0, + 'target_value': 0.0, + 'type': 205, + 'unit': 'n/a', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 15.0, + 'data': '', + 'editable': 0, + 'id': 18, + 'instance': 0, + 'last_changed': 1739390161, + 'last_value': 15.0, + 'maximum': 100, + 'minimum': 0, + 'name': '', + 'node_id': -1, + 'options': dict({ + 'history': dict({ + 'day': 1, + 'month': 6, + 'week': 26, + }), + }), + 'state': 1, + 'step_value': 0.1, + 'target_value': 15.0, + 'type': 311, + 'unit': '%', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 5.0, + 'data': '', + 'editable': 0, + 'id': 19, + 'instance': 0, + 'last_changed': 1739390161, + 'last_value': 10.0, + 'maximum': 100, + 'minimum': 0, + 'name': '', + 'node_id': -1, + 'options': dict({ + 'history': dict({ + 'day': 1, + 'month': 6, + 'week': 26, + }), + }), + 'state': 1, + 'step_value': 0.1, + 'target_value': 5.0, + 'type': 312, + 'unit': '%', + }), + dict({ + 'based_on': 1, + 'changed_by': 1, + 'changed_by_id': 0, + 'current_value': 10.0, + 'data': '', + 'editable': 0, + 'id': 20, + 'instance': 0, + 'last_changed': 1739390161, + 'last_value': 10.0, + 'maximum': 100, + 'minimum': 0, + 'name': '', + 'node_id': -1, + 'options': dict({ + 'history': dict({ + 'day': 1, + 'month': 6, + 'week': 26, + }), + }), + 'state': 1, + 'step_value': 0.1, + 'target_value': 10.0, + 'type': 313, + 'unit': '%', + }), + ]), + 'cube_type': 0, + 'favorite': 0, + 'history': 1, + 'id': -1, + 'image': 'default', + 'name': 'homee', + 'note': '', + 'order': 0, + 'owner': 0, + 'phonetic_name': '', + 'profile': 1, + 'protocol': 0, + 'routing': 0, + 'security': 0, + 'services': 0, + 'state': 1, + 'state_changed': 16, + }), + }) +# --- diff --git a/tests/components/homee/test_diagnostics.py b/tests/components/homee/test_diagnostics.py new file mode 100644 index 00000000000..aedc3a78e19 --- /dev/null +++ b/tests/components/homee/test_diagnostics.py @@ -0,0 +1,93 @@ +"""Test homee diagnostics.""" + +from unittest.mock import MagicMock + +from syrupy.assertion import SnapshotAssertion + +from homeassistant.components.homee.const import DOMAIN +from homeassistant.core import HomeAssistant +from homeassistant.helpers import device_registry as dr + +from . import build_mock_node, setup_integration +from .conftest import HOMEE_ID + +from tests.common import MockConfigEntry +from tests.components.diagnostics import ( + get_diagnostics_for_config_entry, + get_diagnostics_for_device, +) +from tests.typing import ClientSessionGenerator + + +async def setup_mock_homee( + hass: HomeAssistant, mock_homee: MagicMock, mock_config_entry: MockConfigEntry +) -> None: + """Set up the number platform.""" + mock_homee.nodes = [ + build_mock_node("numbers.json"), + build_mock_node("thermostat_with_currenttemp.json"), + build_mock_node("cover_with_position_slats.json"), + ] + mock_homee.get_node_by_id = lambda node_id: mock_homee.nodes[node_id - 1] + await setup_integration(hass, mock_config_entry) + + +async def test_diagnostics_config_entry( + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + mock_homee: MagicMock, + mock_config_entry: MockConfigEntry, + snapshot: SnapshotAssertion, +) -> None: + """Test diagnostics for config entry.""" + await setup_mock_homee(hass, mock_homee, mock_config_entry) + result = await get_diagnostics_for_config_entry( + hass, hass_client, mock_config_entry + ) + assert result == snapshot + + +async def test_diagnostics_device( + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + mock_homee: MagicMock, + mock_config_entry: MockConfigEntry, + device_registry: dr.DeviceRegistry, + snapshot: SnapshotAssertion, +) -> None: + """Test diagnostics for a device.""" + await setup_mock_homee(hass, mock_homee, mock_config_entry) + + device_entry = device_registry.async_get_device( + identifiers={(DOMAIN, f"{HOMEE_ID}-1")} + ) + assert device_entry is not None + result = await get_diagnostics_for_device( + hass, hass_client, mock_config_entry, device_entry + ) + assert result == snapshot + + +async def test_diagnostics_homee_device( + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + mock_homee: MagicMock, + mock_config_entry: MockConfigEntry, + device_registry: dr.DeviceRegistry, + snapshot: SnapshotAssertion, +) -> None: + """Test diagnostics for the homee hub device.""" + mock_homee.nodes = [ + build_mock_node("homee.json"), + ] + mock_homee.get_node_by_id.return_value = mock_homee.nodes[0] + await setup_integration(hass, mock_config_entry) + + device_entry = device_registry.async_get_device( + identifiers={(DOMAIN, f"{HOMEE_ID}")} + ) + assert device_entry is not None + result = await get_diagnostics_for_device( + hass, hass_client, mock_config_entry, device_entry + ) + assert result == snapshot