Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return raw API data for subaru device diagnostics #114119

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions homeassistant/components/subaru/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

from typing import Any

from subarulink.const import LATITUDE, LONGITUDE, ODOMETER, VEHICLE_NAME
from subarulink.const import (
LATITUDE,
LONGITUDE,
ODOMETER,
RAW_API_FIELDS_TO_REDACT,
VEHICLE_NAME,
)

from homeassistant.components.diagnostics.util import async_redact_data
from homeassistant.config_entries import ConfigEntry
Expand All @@ -13,7 +19,7 @@
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.device_registry import DeviceEntry

from .const import DOMAIN, ENTRY_COORDINATOR, VEHICLE_VIN
from .const import DOMAIN, ENTRY_CONTROLLER, ENTRY_COORDINATOR, VEHICLE_VIN

CONFIG_FIELDS_TO_REDACT = [CONF_USERNAME, CONF_PASSWORD, CONF_PIN, CONF_DEVICE_ID]
DATA_FIELDS_TO_REDACT = [VEHICLE_VIN, VEHICLE_NAME, LATITUDE, LONGITUDE, ODOMETER]
Expand All @@ -39,7 +45,9 @@ async def async_get_device_diagnostics(
hass: HomeAssistant, config_entry: ConfigEntry, device: DeviceEntry
) -> dict[str, Any]:
"""Return diagnostics for a device."""
coordinator = hass.data[DOMAIN][config_entry.entry_id][ENTRY_COORDINATOR]
entry = hass.data[DOMAIN][config_entry.entry_id]
coordinator = entry[ENTRY_COORDINATOR]
controller = entry[ENTRY_CONTROLLER]

vin = next(iter(device.identifiers))[1]

Expand All @@ -50,6 +58,9 @@ async def async_get_device_diagnostics(
),
"options": async_redact_data(config_entry.options, []),
"data": async_redact_data(info, DATA_FIELDS_TO_REDACT),
"raw_data": async_redact_data(
controller.get_raw_data(vin), RAW_API_FIELDS_TO_REDACT
),
}

raise HomeAssistantError("Device not found")
1 change: 1 addition & 0 deletions tests/components/subaru/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
MOCK_API_GET_SAFETY_STATUS = f"{MOCK_API}get_safety_status"
MOCK_API_GET_SUBSCRIPTION_STATUS = f"{MOCK_API}get_subscription_status"
MOCK_API_GET_DATA = f"{MOCK_API}get_data"
MOCK_API_GET_RAW_DATA = f"{MOCK_API}get_raw_data"
MOCK_API_UPDATE = f"{MOCK_API}update"
MOCK_API_FETCH = f"{MOCK_API}fetch"

Expand Down
82 changes: 0 additions & 82 deletions tests/components/subaru/fixtures/diagnostics_config_entry.json

This file was deleted.

80 changes: 0 additions & 80 deletions tests/components/subaru/fixtures/diagnostics_device.json

This file was deleted.

Loading