diff --git a/homeassistant/components/aosmith/diagnostics.py b/homeassistant/components/aosmith/diagnostics.py new file mode 100644 index 00000000000000..a821c980faa3be --- /dev/null +++ b/homeassistant/components/aosmith/diagnostics.py @@ -0,0 +1,39 @@ +"""Diagnostics support for A. O. Smith.""" +from __future__ import annotations + +from typing import Any + +from homeassistant.components.diagnostics import async_redact_data +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant + +from . import AOSmithData +from .const import DOMAIN + +TO_REDACT = { + "address", + "city", + "contactId", + "dsn", + "email", + "firstName", + "heaterSsid", + "id", + "lastName", + "phone", + "postalCode", + "registeredOwner", + "serial", + "ssid", + "state", +} + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, config_entry: ConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + data: AOSmithData = hass.data[DOMAIN][config_entry.entry_id] + + all_device_info = await data.client.get_all_device_info() + return async_redact_data(all_device_info, TO_REDACT) diff --git a/homeassistant/components/aosmith/manifest.json b/homeassistant/components/aosmith/manifest.json index 895b03cf7fd9d6..7651086e1389cd 100644 --- a/homeassistant/components/aosmith/manifest.json +++ b/homeassistant/components/aosmith/manifest.json @@ -5,5 +5,5 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/aosmith", "iot_class": "cloud_polling", - "requirements": ["py-aosmith==1.0.1"] + "requirements": ["py-aosmith==1.0.4"] } diff --git a/requirements_all.txt b/requirements_all.txt index f802ee0cf2d1c8..58e452d2e92435 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1549,7 +1549,7 @@ pushover_complete==1.1.1 pvo==2.1.1 # homeassistant.components.aosmith -py-aosmith==1.0.1 +py-aosmith==1.0.4 # homeassistant.components.canary py-canary==0.5.3 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index b55ea4e71d17b3..07f3d2e35ae36b 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1192,7 +1192,7 @@ pushover_complete==1.1.1 pvo==2.1.1 # homeassistant.components.aosmith -py-aosmith==1.0.1 +py-aosmith==1.0.4 # homeassistant.components.canary py-canary==0.5.3 diff --git a/tests/components/aosmith/conftest.py b/tests/components/aosmith/conftest.py index 61c1fc9a562e92..f2c3ffc9c3c3eb 100644 --- a/tests/components/aosmith/conftest.py +++ b/tests/components/aosmith/conftest.py @@ -54,10 +54,16 @@ async def mock_client(get_devices_fixture: str) -> Generator[MagicMock, None, No get_energy_use_fixture = load_json_object_fixture( "get_energy_use_data.json", DOMAIN ) + get_all_device_info_fixture = load_json_object_fixture( + "get_all_device_info.json", DOMAIN + ) client_mock = MagicMock(AOSmithAPIClient) client_mock.get_devices = AsyncMock(return_value=get_devices_fixture) client_mock.get_energy_use_data = AsyncMock(return_value=get_energy_use_fixture) + client_mock.get_all_device_info = AsyncMock( + return_value=get_all_device_info_fixture + ) return client_mock diff --git a/tests/components/aosmith/fixtures/get_all_device_info.json b/tests/components/aosmith/fixtures/get_all_device_info.json new file mode 100644 index 00000000000000..4d19a80a3adf7a --- /dev/null +++ b/tests/components/aosmith/fixtures/get_all_device_info.json @@ -0,0 +1,247 @@ +{ + "devices": [ + { + "alertSettings": { + "faultCode": { + "major": { + "email": true, + "sms": false + }, + "minor": { + "email": false, + "sms": false + } + }, + "operatingSetPoint": { + "email": false, + "sms": false + }, + "tankTemperature": { + "highTemperature": { + "email": false, + "sms": false, + "value": 160 + }, + "lowTemperature": { + "email": false, + "sms": false, + "value": 120 + } + } + }, + "brand": "aosmith", + "deviceType": "NEXT_GEN_HEAT_PUMP", + "dsn": "dsn", + "hardware": { + "hasBluetooth": true, + "interface": "CONTROL_PANEL" + }, + "id": "id", + "install": { + "address": "sample_address", + "city": "sample_city", + "country": "United States", + "date": "2023-09-29", + "email": "sample_email", + "group": "Residential", + "location": "Basement", + "phone": "sample_phone", + "postalCode": "sample_postal_code", + "professional": false, + "registeredOwner": "sample_owner", + "registrationDate": "2023-12-24", + "state": "sample_state" + }, + "isRegistered": true, + "junctionId": "junctionId", + "lastUpdate": 1703386473737, + "model": "HPTS-50 200 202172000", + "name": "Water Heater", + "permissions": "USER", + "productId": "100350404", + "serial": "sample_serial", + "users": [ + { + "contactId": "sample_contact_id", + "email": "sample_email", + "firstName": "sample_first_name", + "isSelf": true, + "lastName": "sample_last_name", + "permissions": "USER" + } + ], + "data": { + "activeAlerts": [], + "alertHistory": [], + "isOnline": true, + "isWifi": true, + "lastUpdate": 1703138389000, + "signalStrength": null, + "heaterSsid": "sample_heater_ssid", + "ssid": "sample_ssid", + "temperatureSetpoint": 145, + "temperatureSetpointPending": false, + "temperatureSetpointPrevious": 145, + "temperatureSetpointMaximum": 145, + "error": "", + "modes": [ + { + "mode": "HYBRID", + "controls": null + }, + { + "mode": "HEAT_PUMP", + "controls": null + }, + { + "mode": "ELECTRIC", + "controls": "SELECT_DAYS" + }, + { + "mode": "VACATION", + "controls": "SELECT_DAYS" + } + ], + "firmwareVersion": "2.14", + "hotWaterStatus": "HIGH", + "isAdvancedLoadUpMore": false, + "isCtaUcmPresent": false, + "isDemandResponsePaused": false, + "isEnrolled": false, + "mode": "HEAT_PUMP", + "modePending": false, + "vacationModeRemainingDays": 0, + "electricModeRemainingDays": 100, + "isLowes": false, + "canEditTimeOfUse": false, + "timeOfUseData": null, + "consumerScheduleData": null + } + } + ], + "energy_use_data": { + "junctionId": { + "average": 2.4744000000000006, + "graphData": [ + { + "date": "2023-11-26T04:00:00.000Z", + "kwh": 0.936 + }, + { + "date": "2023-11-27T04:00:00.000Z", + "kwh": 4.248 + }, + { + "date": "2023-11-28T04:00:00.000Z", + "kwh": 1.002 + }, + { + "date": "2023-11-29T04:00:00.000Z", + "kwh": 3.078 + }, + { + "date": "2023-11-30T04:00:00.000Z", + "kwh": 1.896 + }, + { + "date": "2023-12-01T04:00:00.000Z", + "kwh": 1.98 + }, + { + "date": "2023-12-02T04:00:00.000Z", + "kwh": 2.112 + }, + { + "date": "2023-12-03T04:00:00.000Z", + "kwh": 3.222 + }, + { + "date": "2023-12-04T04:00:00.000Z", + "kwh": 4.254 + }, + { + "date": "2023-12-05T04:00:00.000Z", + "kwh": 4.05 + }, + { + "date": "2023-12-06T04:00:00.000Z", + "kwh": 3.312 + }, + { + "date": "2023-12-07T04:00:00.000Z", + "kwh": 2.334 + }, + { + "date": "2023-12-08T04:00:00.000Z", + "kwh": 2.418 + }, + { + "date": "2023-12-09T04:00:00.000Z", + "kwh": 2.19 + }, + { + "date": "2023-12-10T04:00:00.000Z", + "kwh": 3.786 + }, + { + "date": "2023-12-11T04:00:00.000Z", + "kwh": 5.292 + }, + { + "date": "2023-12-12T04:00:00.000Z", + "kwh": 1.38 + }, + { + "date": "2023-12-13T04:00:00.000Z", + "kwh": 3.324 + }, + { + "date": "2023-12-14T04:00:00.000Z", + "kwh": 1.092 + }, + { + "date": "2023-12-15T04:00:00.000Z", + "kwh": 0.606 + }, + { + "date": "2023-12-16T04:00:00.000Z", + "kwh": 0 + }, + { + "date": "2023-12-17T04:00:00.000Z", + "kwh": 2.838 + }, + { + "date": "2023-12-18T04:00:00.000Z", + "kwh": 2.382 + }, + { + "date": "2023-12-19T04:00:00.000Z", + "kwh": 2.904 + }, + { + "date": "2023-12-20T04:00:00.000Z", + "kwh": 1.914 + }, + { + "date": "2023-12-21T04:00:00.000Z", + "kwh": 3.93 + }, + { + "date": "2023-12-22T04:00:00.000Z", + "kwh": 3.666 + }, + { + "date": "2023-12-23T04:00:00.000Z", + "kwh": 2.766 + }, + { + "date": "2023-12-24T04:00:00.000Z", + "kwh": 1.32 + } + ], + "lifetimeKwh": 203.259, + "startDate": "Nov 26" + } + } +} diff --git a/tests/components/aosmith/snapshots/test_diagnostics.ambr b/tests/components/aosmith/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000000..8704cdaa214ffd --- /dev/null +++ b/tests/components/aosmith/snapshots/test_diagnostics.ambr @@ -0,0 +1,252 @@ +# serializer version: 1 +# name: test_diagnostics + dict({ + 'devices': list([ + dict({ + 'alertSettings': dict({ + 'faultCode': dict({ + 'major': dict({ + 'email': '**REDACTED**', + 'sms': False, + }), + 'minor': dict({ + 'email': '**REDACTED**', + 'sms': False, + }), + }), + 'operatingSetPoint': dict({ + 'email': '**REDACTED**', + 'sms': False, + }), + 'tankTemperature': dict({ + 'highTemperature': dict({ + 'email': '**REDACTED**', + 'sms': False, + 'value': 160, + }), + 'lowTemperature': dict({ + 'email': '**REDACTED**', + 'sms': False, + 'value': 120, + }), + }), + }), + 'brand': 'aosmith', + 'data': dict({ + 'activeAlerts': list([ + ]), + 'alertHistory': list([ + ]), + 'canEditTimeOfUse': False, + 'consumerScheduleData': None, + 'electricModeRemainingDays': 100, + 'error': '', + 'firmwareVersion': '2.14', + 'heaterSsid': '**REDACTED**', + 'hotWaterStatus': 'HIGH', + 'isAdvancedLoadUpMore': False, + 'isCtaUcmPresent': False, + 'isDemandResponsePaused': False, + 'isEnrolled': False, + 'isLowes': False, + 'isOnline': True, + 'isWifi': True, + 'lastUpdate': 1703138389000, + 'mode': 'HEAT_PUMP', + 'modePending': False, + 'modes': list([ + dict({ + 'controls': None, + 'mode': 'HYBRID', + }), + dict({ + 'controls': None, + 'mode': 'HEAT_PUMP', + }), + dict({ + 'controls': 'SELECT_DAYS', + 'mode': 'ELECTRIC', + }), + dict({ + 'controls': 'SELECT_DAYS', + 'mode': 'VACATION', + }), + ]), + 'signalStrength': None, + 'ssid': '**REDACTED**', + 'temperatureSetpoint': 145, + 'temperatureSetpointMaximum': 145, + 'temperatureSetpointPending': False, + 'temperatureSetpointPrevious': 145, + 'timeOfUseData': None, + 'vacationModeRemainingDays': 0, + }), + 'deviceType': 'NEXT_GEN_HEAT_PUMP', + 'dsn': '**REDACTED**', + 'hardware': dict({ + 'hasBluetooth': True, + 'interface': 'CONTROL_PANEL', + }), + 'id': '**REDACTED**', + 'install': dict({ + 'address': '**REDACTED**', + 'city': '**REDACTED**', + 'country': 'United States', + 'date': '2023-09-29', + 'email': '**REDACTED**', + 'group': 'Residential', + 'location': 'Basement', + 'phone': '**REDACTED**', + 'postalCode': '**REDACTED**', + 'professional': False, + 'registeredOwner': '**REDACTED**', + 'registrationDate': '2023-12-24', + 'state': '**REDACTED**', + }), + 'isRegistered': True, + 'junctionId': 'junctionId', + 'lastUpdate': 1703386473737, + 'model': 'HPTS-50 200 202172000', + 'name': 'Water Heater', + 'permissions': 'USER', + 'productId': '100350404', + 'serial': '**REDACTED**', + 'users': list([ + dict({ + 'contactId': '**REDACTED**', + 'email': '**REDACTED**', + 'firstName': '**REDACTED**', + 'isSelf': True, + 'lastName': '**REDACTED**', + 'permissions': 'USER', + }), + ]), + }), + ]), + 'energy_use_data': dict({ + 'junctionId': dict({ + 'average': 2.4744000000000006, + 'graphData': list([ + dict({ + 'date': '2023-11-26T04:00:00.000Z', + 'kwh': 0.936, + }), + dict({ + 'date': '2023-11-27T04:00:00.000Z', + 'kwh': 4.248, + }), + dict({ + 'date': '2023-11-28T04:00:00.000Z', + 'kwh': 1.002, + }), + dict({ + 'date': '2023-11-29T04:00:00.000Z', + 'kwh': 3.078, + }), + dict({ + 'date': '2023-11-30T04:00:00.000Z', + 'kwh': 1.896, + }), + dict({ + 'date': '2023-12-01T04:00:00.000Z', + 'kwh': 1.98, + }), + dict({ + 'date': '2023-12-02T04:00:00.000Z', + 'kwh': 2.112, + }), + dict({ + 'date': '2023-12-03T04:00:00.000Z', + 'kwh': 3.222, + }), + dict({ + 'date': '2023-12-04T04:00:00.000Z', + 'kwh': 4.254, + }), + dict({ + 'date': '2023-12-05T04:00:00.000Z', + 'kwh': 4.05, + }), + dict({ + 'date': '2023-12-06T04:00:00.000Z', + 'kwh': 3.312, + }), + dict({ + 'date': '2023-12-07T04:00:00.000Z', + 'kwh': 2.334, + }), + dict({ + 'date': '2023-12-08T04:00:00.000Z', + 'kwh': 2.418, + }), + dict({ + 'date': '2023-12-09T04:00:00.000Z', + 'kwh': 2.19, + }), + dict({ + 'date': '2023-12-10T04:00:00.000Z', + 'kwh': 3.786, + }), + dict({ + 'date': '2023-12-11T04:00:00.000Z', + 'kwh': 5.292, + }), + dict({ + 'date': '2023-12-12T04:00:00.000Z', + 'kwh': 1.38, + }), + dict({ + 'date': '2023-12-13T04:00:00.000Z', + 'kwh': 3.324, + }), + dict({ + 'date': '2023-12-14T04:00:00.000Z', + 'kwh': 1.092, + }), + dict({ + 'date': '2023-12-15T04:00:00.000Z', + 'kwh': 0.606, + }), + dict({ + 'date': '2023-12-16T04:00:00.000Z', + 'kwh': 0, + }), + dict({ + 'date': '2023-12-17T04:00:00.000Z', + 'kwh': 2.838, + }), + dict({ + 'date': '2023-12-18T04:00:00.000Z', + 'kwh': 2.382, + }), + dict({ + 'date': '2023-12-19T04:00:00.000Z', + 'kwh': 2.904, + }), + dict({ + 'date': '2023-12-20T04:00:00.000Z', + 'kwh': 1.914, + }), + dict({ + 'date': '2023-12-21T04:00:00.000Z', + 'kwh': 3.93, + }), + dict({ + 'date': '2023-12-22T04:00:00.000Z', + 'kwh': 3.666, + }), + dict({ + 'date': '2023-12-23T04:00:00.000Z', + 'kwh': 2.766, + }), + dict({ + 'date': '2023-12-24T04:00:00.000Z', + 'kwh': 1.32, + }), + ]), + 'lifetimeKwh': 203.259, + 'startDate': 'Nov 26', + }), + }), + }) +# --- diff --git a/tests/components/aosmith/test_diagnostics.py b/tests/components/aosmith/test_diagnostics.py new file mode 100644 index 00000000000000..9090ef5e7b77d5 --- /dev/null +++ b/tests/components/aosmith/test_diagnostics.py @@ -0,0 +1,23 @@ +"""Tests for the diagnostics data provided by the A. O. Smith integration.""" + +from syrupy import SnapshotAssertion + +from homeassistant.core import HomeAssistant + +from tests.common import MockConfigEntry +from tests.components.diagnostics import get_diagnostics_for_config_entry +from tests.typing import ClientSessionGenerator + + +async def test_diagnostics( + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + init_integration: MockConfigEntry, + snapshot: SnapshotAssertion, +) -> None: + """Test diagnostics.""" + + assert ( + await get_diagnostics_for_config_entry(hass, hass_client, init_integration) + == snapshot + )