From aa9ccc7dfb819aeffdc676342c86f16b4c3b6be9 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 24 Jan 2022 10:15:57 +0100 Subject: [PATCH] Add coordinator data to Renault diagnostics (#64783) * Add coordinator data to renault diagnostics * Adjust tests * Adjust tests * Add GPS coordinates to redacted information --- .../components/renault/diagnostics.py | 21 ++++++++++---- tests/components/renault/test_diagnostics.py | 29 +++++++++++++++++-- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/renault/diagnostics.py b/homeassistant/components/renault/diagnostics.py index f2a4e0f7cba..f8b0a0d926e 100644 --- a/homeassistant/components/renault/diagnostics.py +++ b/homeassistant/components/renault/diagnostics.py @@ -11,6 +11,7 @@ from homeassistant.helpers.device_registry import DeviceEntry from . import RenaultHub from .const import CONF_KAMEREON_ACCOUNT_ID, DOMAIN +from .renault_vehicle import RenaultVehicleProxy TO_REDACT = { CONF_KAMEREON_ACCOUNT_ID, @@ -19,6 +20,8 @@ TO_REDACT = { "radioCode", "registrationNumber", "vin", + "gpsLatitude", + "gpsLongitude", } @@ -34,7 +37,7 @@ async def async_get_config_entry_diagnostics( "data": async_redact_data(entry.data, TO_REDACT), }, "vehicles": [ - async_redact_data(vehicle.details.raw_data, TO_REDACT) + _get_vehicle_diagnostics(vehicle) for vehicle in renault_hub.vehicles.values() ], } @@ -42,13 +45,21 @@ async def async_get_config_entry_diagnostics( async def async_get_device_diagnostics( hass: HomeAssistant, entry: ConfigEntry, device: DeviceEntry -) -> dict: +) -> dict[str, Any]: """Return diagnostics for a device.""" renault_hub: RenaultHub = hass.data[DOMAIN][entry.entry_id] vin = next(iter(device.identifiers))[1] + vehicle = renault_hub.vehicles[vin] + return _get_vehicle_diagnostics(vehicle) + + +def _get_vehicle_diagnostics(vehicle: RenaultVehicleProxy) -> dict[str, Any]: + """Return diagnostics for a device.""" return { - "details": async_redact_data( - renault_hub.vehicles[vin].details.raw_data, TO_REDACT - ), + "details": async_redact_data(vehicle.details.raw_data, TO_REDACT), + "data": { + key: async_redact_data(coordinator.data.raw_data, TO_REDACT) + for key, coordinator in vehicle.coordinators.items() + }, } diff --git a/tests/components/renault/test_diagnostics.py b/tests/components/renault/test_diagnostics.py index e3ea6254237..1a61859ac93 100644 --- a/tests/components/renault/test_diagnostics.py +++ b/tests/components/renault/test_diagnostics.py @@ -134,6 +134,31 @@ VEHICLE_DETAILS = { "radioCode": REDACTED, } +VEHICLE_DATA = { + "battery": { + "batteryAutonomy": 141, + "batteryAvailableEnergy": 31, + "batteryCapacity": 0, + "batteryLevel": 60, + "batteryTemperature": 20, + "chargingInstantaneousPower": 27, + "chargingRemainingTime": 145, + "chargingStatus": 1.0, + "plugStatus": 1, + "timestamp": "2020-01-12T21:40:16Z", + }, + "charge_mode": { + "chargeMode": "always", + }, + "cockpit": { + "totalMileage": 49114.27, + }, + "hvac_status": { + "externalTemperature": 8.0, + "hvacStatus": "off", + }, +} + @pytest.mark.usefixtures("fixtures_with_data") @pytest.mark.parametrize("vehicle_type", ["zoe_40"], indirect=True) @@ -154,7 +179,7 @@ async def test_entry_diagnostics( }, "title": "Mock Title", }, - "vehicles": [VEHICLE_DETAILS], + "vehicles": [{"details": VEHICLE_DETAILS, "data": VEHICLE_DATA}], } @@ -174,4 +199,4 @@ async def test_device_diagnostics( assert await get_diagnostics_for_device( hass, hass_client, config_entry, device - ) == {"details": VEHICLE_DETAILS} + ) == {"details": VEHICLE_DETAILS, "data": VEHICLE_DATA}