Add coordinator data to Renault diagnostics (#64783)
* Add coordinator data to renault diagnostics * Adjust tests * Adjust tests * Add GPS coordinates to redacted information
This commit is contained in:
parent
17d7dc991f
commit
aa9ccc7dfb
2 changed files with 43 additions and 7 deletions
|
@ -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()
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue