diff --git a/homeassistant/components/subaru/diagnostics.py b/homeassistant/components/subaru/diagnostics.py index 726457aa341c8..5d95cd0464bbf 100644 --- a/homeassistant/components/subaru/diagnostics.py +++ b/homeassistant/components/subaru/diagnostics.py @@ -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 @@ -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] @@ -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] @@ -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") diff --git a/tests/components/subaru/conftest.py b/tests/components/subaru/conftest.py index 446f025e07710..307199d43ac77 100644 --- a/tests/components/subaru/conftest.py +++ b/tests/components/subaru/conftest.py @@ -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" diff --git a/tests/components/subaru/fixtures/diagnostics_config_entry.json b/tests/components/subaru/fixtures/diagnostics_config_entry.json deleted file mode 100644 index 327b0c4817414..0000000000000 --- a/tests/components/subaru/fixtures/diagnostics_config_entry.json +++ /dev/null @@ -1,82 +0,0 @@ -{ - "config_entry": { - "username": "**REDACTED**", - "password": "**REDACTED**", - "country": "USA", - "pin": "**REDACTED**", - "device_id": "**REDACTED**" - }, - "options": { - "update_enabled": true - }, - "data": [ - { - "vehicle_status": { - "AVG_FUEL_CONSUMPTION": 2.3, - "DISTANCE_TO_EMPTY_FUEL": 707, - "DOOR_BOOT_LOCK_STATUS": "UNKNOWN", - "DOOR_BOOT_POSITION": "CLOSED", - "DOOR_ENGINE_HOOD_LOCK_STATUS": "UNKNOWN", - "DOOR_ENGINE_HOOD_POSITION": "CLOSED", - "DOOR_FRONT_LEFT_LOCK_STATUS": "UNKNOWN", - "DOOR_FRONT_LEFT_POSITION": "CLOSED", - "DOOR_FRONT_RIGHT_LOCK_STATUS": "UNKNOWN", - "DOOR_FRONT_RIGHT_POSITION": "CLOSED", - "DOOR_REAR_LEFT_LOCK_STATUS": "UNKNOWN", - "DOOR_REAR_LEFT_POSITION": "CLOSED", - "DOOR_REAR_RIGHT_LOCK_STATUS": "UNKNOWN", - "DOOR_REAR_RIGHT_POSITION": "CLOSED", - "EV_CHARGER_STATE_TYPE": "CHARGING", - "EV_CHARGE_SETTING_AMPERE_TYPE": "MAXIMUM", - "EV_CHARGE_VOLT_TYPE": "CHARGE_LEVEL_1", - "EV_DISTANCE_TO_EMPTY": 1, - "EV_IS_PLUGGED_IN": "UNLOCKED_CONNECTED", - "EV_STATE_OF_CHARGE_MODE": "EV_MODE", - "EV_STATE_OF_CHARGE_PERCENT": 20, - "EV_TIME_TO_FULLY_CHARGED_UTC": "2020-07-24T03:06:40+00:00", - "ODOMETER": "**REDACTED**", - "POSITION_HEADING_DEGREE": 150, - "POSITION_SPEED_KMPH": "0", - "POSITION_TIMESTAMP": 1595560000.0, - "SEAT_BELT_STATUS_FRONT_LEFT": "BELTED", - "SEAT_BELT_STATUS_FRONT_MIDDLE": "NOT_EQUIPPED", - "SEAT_BELT_STATUS_FRONT_RIGHT": "BELTED", - "SEAT_BELT_STATUS_SECOND_LEFT": "UNKNOWN", - "SEAT_BELT_STATUS_SECOND_MIDDLE": "UNKNOWN", - "SEAT_BELT_STATUS_SECOND_RIGHT": "UNKNOWN", - "SEAT_BELT_STATUS_THIRD_LEFT": "UNKNOWN", - "SEAT_BELT_STATUS_THIRD_MIDDLE": "UNKNOWN", - "SEAT_BELT_STATUS_THIRD_RIGHT": "UNKNOWN", - "SEAT_OCCUPATION_STATUS_FRONT_LEFT": "UNKNOWN", - "SEAT_OCCUPATION_STATUS_FRONT_MIDDLE": "NOT_EQUIPPED", - "SEAT_OCCUPATION_STATUS_FRONT_RIGHT": "UNKNOWN", - "SEAT_OCCUPATION_STATUS_SECOND_LEFT": "UNKNOWN", - "SEAT_OCCUPATION_STATUS_SECOND_MIDDLE": "UNKNOWN", - "SEAT_OCCUPATION_STATUS_SECOND_RIGHT": "UNKNOWN", - "SEAT_OCCUPATION_STATUS_THIRD_LEFT": "UNKNOWN", - "SEAT_OCCUPATION_STATUS_THIRD_MIDDLE": "UNKNOWN", - "SEAT_OCCUPATION_STATUS_THIRD_RIGHT": "UNKNOWN", - "TIMESTAMP": 1595560000.0, - "TRANSMISSION_MODE": "UNKNOWN", - "TYRE_PRESSURE_FRONT_LEFT": 0, - "TYRE_PRESSURE_FRONT_RIGHT": 2550, - "TYRE_PRESSURE_REAR_LEFT": 2450, - "TYRE_PRESSURE_REAR_RIGHT": null, - "TYRE_STATUS_FRONT_LEFT": "UNKNOWN", - "TYRE_STATUS_FRONT_RIGHT": "UNKNOWN", - "TYRE_STATUS_REAR_LEFT": "UNKNOWN", - "TYRE_STATUS_REAR_RIGHT": "UNKNOWN", - "VEHICLE_STATE_TYPE": "IGNITION_OFF", - "WINDOW_BACK_STATUS": "UNKNOWN", - "WINDOW_FRONT_LEFT_STATUS": "VENTED", - "WINDOW_FRONT_RIGHT_STATUS": "VENTED", - "WINDOW_REAR_LEFT_STATUS": "UNKNOWN", - "WINDOW_REAR_RIGHT_STATUS": "UNKNOWN", - "WINDOW_SUNROOF_STATUS": "UNKNOWN", - "HEADING": 170, - "LATITUDE": "**REDACTED**", - "LONGITUDE": "**REDACTED**" - } - } - ] -} diff --git a/tests/components/subaru/fixtures/diagnostics_device.json b/tests/components/subaru/fixtures/diagnostics_device.json deleted file mode 100644 index f67be94a17155..0000000000000 --- a/tests/components/subaru/fixtures/diagnostics_device.json +++ /dev/null @@ -1,80 +0,0 @@ -{ - "config_entry": { - "username": "**REDACTED**", - "password": "**REDACTED**", - "country": "USA", - "pin": "**REDACTED**", - "device_id": "**REDACTED**" - }, - "options": { - "update_enabled": true - }, - "data": { - "vehicle_status": { - "AVG_FUEL_CONSUMPTION": 2.3, - "DISTANCE_TO_EMPTY_FUEL": 707, - "DOOR_BOOT_LOCK_STATUS": "UNKNOWN", - "DOOR_BOOT_POSITION": "CLOSED", - "DOOR_ENGINE_HOOD_LOCK_STATUS": "UNKNOWN", - "DOOR_ENGINE_HOOD_POSITION": "CLOSED", - "DOOR_FRONT_LEFT_LOCK_STATUS": "UNKNOWN", - "DOOR_FRONT_LEFT_POSITION": "CLOSED", - "DOOR_FRONT_RIGHT_LOCK_STATUS": "UNKNOWN", - "DOOR_FRONT_RIGHT_POSITION": "CLOSED", - "DOOR_REAR_LEFT_LOCK_STATUS": "UNKNOWN", - "DOOR_REAR_LEFT_POSITION": "CLOSED", - "DOOR_REAR_RIGHT_LOCK_STATUS": "UNKNOWN", - "DOOR_REAR_RIGHT_POSITION": "CLOSED", - "EV_CHARGER_STATE_TYPE": "CHARGING", - "EV_CHARGE_SETTING_AMPERE_TYPE": "MAXIMUM", - "EV_CHARGE_VOLT_TYPE": "CHARGE_LEVEL_1", - "EV_DISTANCE_TO_EMPTY": 1, - "EV_IS_PLUGGED_IN": "UNLOCKED_CONNECTED", - "EV_STATE_OF_CHARGE_MODE": "EV_MODE", - "EV_STATE_OF_CHARGE_PERCENT": 20, - "EV_TIME_TO_FULLY_CHARGED_UTC": "2020-07-24T03:06:40+00:00", - "ODOMETER": "**REDACTED**", - "POSITION_HEADING_DEGREE": 150, - "POSITION_SPEED_KMPH": "0", - "POSITION_TIMESTAMP": 1595560000.0, - "SEAT_BELT_STATUS_FRONT_LEFT": "BELTED", - "SEAT_BELT_STATUS_FRONT_MIDDLE": "NOT_EQUIPPED", - "SEAT_BELT_STATUS_FRONT_RIGHT": "BELTED", - "SEAT_BELT_STATUS_SECOND_LEFT": "UNKNOWN", - "SEAT_BELT_STATUS_SECOND_MIDDLE": "UNKNOWN", - "SEAT_BELT_STATUS_SECOND_RIGHT": "UNKNOWN", - "SEAT_BELT_STATUS_THIRD_LEFT": "UNKNOWN", - "SEAT_BELT_STATUS_THIRD_MIDDLE": "UNKNOWN", - "SEAT_BELT_STATUS_THIRD_RIGHT": "UNKNOWN", - "SEAT_OCCUPATION_STATUS_FRONT_LEFT": "UNKNOWN", - "SEAT_OCCUPATION_STATUS_FRONT_MIDDLE": "NOT_EQUIPPED", - "SEAT_OCCUPATION_STATUS_FRONT_RIGHT": "UNKNOWN", - "SEAT_OCCUPATION_STATUS_SECOND_LEFT": "UNKNOWN", - "SEAT_OCCUPATION_STATUS_SECOND_MIDDLE": "UNKNOWN", - "SEAT_OCCUPATION_STATUS_SECOND_RIGHT": "UNKNOWN", - "SEAT_OCCUPATION_STATUS_THIRD_LEFT": "UNKNOWN", - "SEAT_OCCUPATION_STATUS_THIRD_MIDDLE": "UNKNOWN", - "SEAT_OCCUPATION_STATUS_THIRD_RIGHT": "UNKNOWN", - "TIMESTAMP": 1595560000.0, - "TRANSMISSION_MODE": "UNKNOWN", - "TYRE_PRESSURE_FRONT_LEFT": 0, - "TYRE_PRESSURE_FRONT_RIGHT": 2550, - "TYRE_PRESSURE_REAR_LEFT": 2450, - "TYRE_PRESSURE_REAR_RIGHT": null, - "TYRE_STATUS_FRONT_LEFT": "UNKNOWN", - "TYRE_STATUS_FRONT_RIGHT": "UNKNOWN", - "TYRE_STATUS_REAR_LEFT": "UNKNOWN", - "TYRE_STATUS_REAR_RIGHT": "UNKNOWN", - "VEHICLE_STATE_TYPE": "IGNITION_OFF", - "WINDOW_BACK_STATUS": "UNKNOWN", - "WINDOW_FRONT_LEFT_STATUS": "VENTED", - "WINDOW_FRONT_RIGHT_STATUS": "VENTED", - "WINDOW_REAR_LEFT_STATUS": "UNKNOWN", - "WINDOW_REAR_RIGHT_STATUS": "UNKNOWN", - "WINDOW_SUNROOF_STATUS": "UNKNOWN", - "HEADING": 170, - "LATITUDE": "**REDACTED**", - "LONGITUDE": "**REDACTED**" - } - } -} diff --git a/tests/components/subaru/fixtures/raw_api_data.json b/tests/components/subaru/fixtures/raw_api_data.json new file mode 100644 index 0000000000000..61274ddc761fa --- /dev/null +++ b/tests/components/subaru/fixtures/raw_api_data.json @@ -0,0 +1,232 @@ +{ + "switchVehicle": { + "customer": { + "sessionCustomer": "123", + "email": "Abc@email.com", + "firstName": "Hass", + "lastName": "User", + "oemCustId": "ABC", + "zip": "123456", + "phone": "123-456-4565" + }, + "vehicleName": "Subaru", + "stolenVehicle": false, + "features": [ + "ABS_MIL", + "AHBL_MIL", + "ATF_MIL", + "AWD_MIL", + "BSD", + "BSDRCT_MIL", + "CEL_MIL", + "EBD_MIL", + "EOL_MIL", + "EPAS_MIL", + "EPB_MIL", + "ESS_MIL", + "EYESIGHT", + "HEVCM_MIL", + "HEV_MIL", + "NAV_TOMTOM", + "OPL_MIL", + "PHEV", + "RAB_MIL", + "RCC", + "REARBRK", + "RPOIA", + "SRS_MIL", + "TEL_MIL", + "TIF_36", + "TIR_35", + "TPMS_MIL", + "VDC_MIL", + "WASH_MIL", + "g2" + ], + "vin": "JF2ABCDE6L0000001", + "modelYear": "2019", + "modelCode": "KRH", + "engineSize": 2.0, + "nickname": "Subaru", + "vehicleKey": 123456, + "active": true, + "licensePlate": "ABC-DEF", + "licensePlateState": "AA", + "email": "test@test.com", + "firstName": "Test", + "lastName": "User", + "subscriptionFeatures": ["REMOTE", "SAFETY", "RetailPHEV"], + "accessLevel": 1, + "oemCustId": "123-ABC-456", + "zip": "12345", + "vehicleMileage": 123456, + "phone": "123-456-4565", + "userOemCustId": "123-ABC-456", + "subscriptionStatus": "ACTIVE", + "authorizedVehicle": true, + "preferredDealer": "Dealer", + "cachedStateCode": "AA", + "subscriptionPlans": [], + "crmRightToRepair": false, + "needMileagePrompt": false, + "phev": null, + "sunsetUpgraded": true, + "extDescrip": "Cool-Gray Khaki", + "intDescrip": "Navy", + "modelName": "Crosstrek", + "transCode": "CVT", + "provisioned": true, + "remoteServicePinExist": true, + "needEmergencyContactPrompt": false, + "vehicleGeoPosition": { + "latitude": 40, + "longitude": -100.0, + "speed": null, + "heading": null, + "timestamp": "2020-07-24T03:06:40" + }, + "show3gSunsetBanner": false, + "timeZone": "America/New_York" + }, + "vehicleStatus": { + "success": true, + "errorCode": null, + "dataName": null, + "data": { + "vhsId": 123456789, + "odometerValue": 123456, + "odometerValueKilometers": 123456, + "eventDate": 1595560000000, + "eventDateStr": "2020-07-24T03:06+0000", + "latitude": 40.0, + "longitude": -100.0, + "positionHeadingDegree": "261", + "tirePressureFrontLeft": "2600", + "tirePressureFrontRight": "2700", + "tirePressureRearLeft": "2650", + "tirePressureRearRight": "2650", + "tirePressureFrontLeftPsi": "37.71", + "tirePressureFrontRightPsi": "39.16", + "tirePressureRearLeftPsi": "38.44", + "tirePressureRearRightPsi": "38.44", + "distanceToEmptyFuelMiles": 529.41, + "distanceToEmptyFuelKilometers": 852, + "avgFuelConsumptionMpg": 52.3, + "avgFuelConsumptionLitersPer100Kilometers": 4.5, + "evStateOfChargePercent": 14, + "evDistanceToEmptyMiles": 529.41, + "evDistanceToEmptyKilometers": 852, + "evDistanceToEmptyByStateMiles": null, + "evDistanceToEmptyByStateKilometers": null, + "vehicleStateType": "IGNITION_OFF", + "windowFrontLeftStatus": "VENTED", + "windowFrontRightStatus": "VENTED", + "windowRearLeftStatus": "UNKNOWN", + "windowRearRightStatus": "UNKNOWN", + "windowSunroofStatus": "UNKNOWN", + "tyreStatusFrontLeft": "UNKNOWN", + "tyreStatusFrontRight": "UNKNOWN", + "tyreStatusRearLeft": "UNKNOWN", + "tyreStatusRearRight": "UNKNOWN", + "remainingFuelPercent": null, + "distanceToEmptyFuelMiles10s": 530, + "distanceToEmptyFuelKilometers10s": 850 + } + }, + "condition": { + "success": true, + "errorCode": null, + "dataName": "remoteServiceStatus", + "data": { + "serviceRequestId": null, + "success": true, + "cancelled": false, + "remoteServiceType": "condition", + "remoteServiceState": "finished", + "subState": null, + "errorCode": null, + "result": { + "avgFuelConsumption": null, + "avgFuelConsumptionUnit": "MPG", + "distanceToEmptyFuel": null, + "distanceToEmptyFuelUnit": "MILES", + "odometer": 123456, + "odometerUnit": "MILES", + "tirePressureFrontLeft": null, + "tirePressureFrontLeftUnit": "PSI", + "tirePressureFrontRight": null, + "tirePressureFrontRightUnit": "PSI", + "tirePressureRearLeft": null, + "tirePressureRearLeftUnit": "PSI", + "tirePressureRearRight": null, + "tirePressureRearRightUnit": "PSI", + "lastUpdatedTime": "2020-07-24T03:06:00+0000", + "windowFrontLeftStatus": "VENTED", + "windowFrontRightStatus": "VENTED", + "windowRearLeftStatus": "UNKNOWN", + "windowRearRightStatus": "UNKNOWN", + "windowSunroofStatus": "UNKNOWN", + "remainingFuelPercent": null, + "evDistanceToEmpty": 17, + "evDistanceToEmptyUnit": "MILES", + "evChargerStateType": "CHARGING_STOPPED", + "evIsPluggedIn": "UNLOCKED_CONNECTED", + "evStateOfChargeMode": "EV_MODE", + "evTimeToFullyCharged": "65535", + "evStateOfChargePercent": "100", + "vehicleStateType": "IGNITION_OFF", + "doorBootPosition": "CLOSED", + "doorEngineHoodPosition": "CLOSED", + "doorFrontLeftPosition": "CLOSED", + "doorFrontRightPosition": "CLOSED", + "doorRearLeftPosition": "CLOSED", + "doorRearRightPosition": "CLOSED" + }, + "updateTime": null, + "vin": "JF2ABCDE6L0000001", + "errorDescription": null + } + }, + "locate": { + "success": true, + "errorCode": null, + "dataName": "remoteServiceStatus", + "data": { + "serviceRequestId": null, + "success": true, + "cancelled": false, + "remoteServiceType": "locate", + "remoteServiceState": "finished", + "subState": null, + "errorCode": null, + "result": { + "latitude": 40.0, + "longitude": -100.0, + "speed": null, + "heading": null, + "locationTimestamp": 1595560000000 + }, + "updateTime": null, + "vin": "JF2ABCDE6L0000001", + "errorDescription": null + } + }, + "climatePresetSettings": { + "success": true, + "errorCode": null, + "dataName": null, + "data": [ + "{\"name\": \"Auto\", \"runTimeMinutes\": \"10\", \"climateZoneFrontTemp\": \"74\", \"climateZoneFrontAirMode\": \"AUTO\", \"climateZoneFrontAirVolume\": \"AUTO\", \"outerAirCirculation\": \"auto\", \"heatedRearWindowActive\": \"false\", \"airConditionOn\": \"false\", \"heatedSeatFrontLeft\": \"off\", \"heatedSeatFrontRight\": \"off\", \"startConfiguration\": \"START_ENGINE_ALLOW_KEY_IN_IGNITION\", \"canEdit\": \"true\", \"disabled\": \"false\", \"vehicleType\": \"gas\", \"presetType\": \"subaruPreset\" }", + "{\"name\":\"Full Cool\",\"runTimeMinutes\":\"10\",\"climateZoneFrontTemp\":\"60\",\"climateZoneFrontAirMode\":\"feet_face_balanced\",\"climateZoneFrontAirVolume\":\"7\",\"airConditionOn\":\"true\",\"heatedSeatFrontLeft\":\"high_cool\",\"heatedSeatFrontRight\":\"high_cool\",\"heatedRearWindowActive\":\"false\",\"outerAirCirculation\":\"outsideAir\",\"startConfiguration\":\"START_ENGINE_ALLOW_KEY_IN_IGNITION\",\"canEdit\":\"true\",\"disabled\":\"true\",\"vehicleType\":\"gas\",\"presetType\":\"subaruPreset\"}", + "{\"name\": \"Full Heat\", \"runTimeMinutes\": \"10\", \"climateZoneFrontTemp\": \"85\", \"climateZoneFrontAirMode\": \"feet_window\", \"climateZoneFrontAirVolume\": \"7\", \"airConditionOn\": \"false\", \"heatedSeatFrontLeft\": \"high_heat\", \"heatedSeatFrontRight\": \"high_heat\", \"heatedRearWindowActive\": \"true\", \"outerAirCirculation\": \"outsideAir\", \"startConfiguration\": \"START_ENGINE_ALLOW_KEY_IN_IGNITION\", \"canEdit\": \"true\", \"disabled\": \"true\", \"vehicleType\": \"gas\", \"presetType\": \"subaruPreset\" }", + "{\"name\": \"Full Cool\", \"runTimeMinutes\": \"10\", \"climateZoneFrontTemp\": \"60\", \"climateZoneFrontAirMode\": \"feet_face_balanced\", \"climateZoneFrontAirVolume\": \"7\", \"airConditionOn\": \"true\", \"heatedSeatFrontLeft\": \"OFF\", \"heatedSeatFrontRight\": \"OFF\", \"heatedRearWindowActive\": \"false\", \"outerAirCirculation\": \"outsideAir\", \"startConfiguration\": \"START_CLIMATE_CONTROL_ONLY_ALLOW_KEY_IN_IGNITION\", \"canEdit\": \"true\", \"disabled\": \"true\", \"vehicleType\": \"phev\", \"presetType\": \"subaruPreset\" }", + "{\"name\": \"Full Heat\", \"runTimeMinutes\": \"10\", \"climateZoneFrontTemp\": \"85\", \"climateZoneFrontAirMode\": \"feet_window\", \"climateZoneFrontAirVolume\": \"7\", \"airConditionOn\": \"false\", \"heatedSeatFrontLeft\": \"high_heat\", \"heatedSeatFrontRight\": \"high_heat\", \"heatedRearWindowActive\": \"true\", \"outerAirCirculation\": \"outsideAir\", \"startConfiguration\": \"START_CLIMATE_CONTROL_ONLY_ALLOW_KEY_IN_IGNITION\", \"canEdit\": \"true\", \"disabled\": \"true\", \"vehicleType\": \"phev\", \"presetType\": \"subaruPreset\" }" + ] + }, + "remoteEngineStartSettings": { + "success": true, + "errorCode": null, + "dataName": null, + "data": "{\"name\": \"Full Heat\", \"runTimeMinutes\": \"10\", \"climateZoneFrontTemp\": \"85\", \"climateZoneFrontAirMode\": \"feet_window\", \"climateZoneFrontAirVolume\": \"7\", \"airConditionOn\": \"false\", \"heatedSeatFrontLeft\": \"high_heat\", \"heatedSeatFrontRight\": \"high_heat\", \"heatedRearWindowActive\": \"true\", \"outerAirCirculation\": \"outsideAir\", \"startConfiguration\": \"START_CLIMATE_CONTROL_ONLY_ALLOW_KEY_IN_IGNITION\", \"canEdit\": \"true\", \"disabled\": \"true\", \"vehicleType\": \"phev\", \"presetType\": \"subaruPreset\" }" + } +} diff --git a/tests/components/subaru/snapshots/test_diagnostics.ambr b/tests/components/subaru/snapshots/test_diagnostics.ambr new file mode 100644 index 0000000000000..848e48776dfd4 --- /dev/null +++ b/tests/components/subaru/snapshots/test_diagnostics.ambr @@ -0,0 +1,390 @@ +# serializer version: 1 +# name: test_config_entry_diagnostics + dict({ + 'config_entry': dict({ + 'country': 'USA', + 'device_id': '**REDACTED**', + 'password': '**REDACTED**', + 'pin': '**REDACTED**', + 'username': '**REDACTED**', + }), + 'data': list([ + dict({ + 'vehicle_status': dict({ + 'AVG_FUEL_CONSUMPTION': 2.3, + 'DISTANCE_TO_EMPTY_FUEL': 707, + 'DOOR_BOOT_LOCK_STATUS': 'UNKNOWN', + 'DOOR_BOOT_POSITION': 'CLOSED', + 'DOOR_ENGINE_HOOD_LOCK_STATUS': 'UNKNOWN', + 'DOOR_ENGINE_HOOD_POSITION': 'CLOSED', + 'DOOR_FRONT_LEFT_LOCK_STATUS': 'UNKNOWN', + 'DOOR_FRONT_LEFT_POSITION': 'CLOSED', + 'DOOR_FRONT_RIGHT_LOCK_STATUS': 'UNKNOWN', + 'DOOR_FRONT_RIGHT_POSITION': 'CLOSED', + 'DOOR_REAR_LEFT_LOCK_STATUS': 'UNKNOWN', + 'DOOR_REAR_LEFT_POSITION': 'CLOSED', + 'DOOR_REAR_RIGHT_LOCK_STATUS': 'UNKNOWN', + 'DOOR_REAR_RIGHT_POSITION': 'CLOSED', + 'EV_CHARGER_STATE_TYPE': 'CHARGING', + 'EV_CHARGE_SETTING_AMPERE_TYPE': 'MAXIMUM', + 'EV_CHARGE_VOLT_TYPE': 'CHARGE_LEVEL_1', + 'EV_DISTANCE_TO_EMPTY': 1, + 'EV_IS_PLUGGED_IN': 'UNLOCKED_CONNECTED', + 'EV_STATE_OF_CHARGE_MODE': 'EV_MODE', + 'EV_STATE_OF_CHARGE_PERCENT': 20, + 'EV_TIME_TO_FULLY_CHARGED_UTC': '2020-07-24T03:06:40+00:00', + 'HEADING': 170, + 'LATITUDE': '**REDACTED**', + 'LONGITUDE': '**REDACTED**', + 'ODOMETER': '**REDACTED**', + 'POSITION_HEADING_DEGREE': 150, + 'POSITION_SPEED_KMPH': '0', + 'POSITION_TIMESTAMP': 1595560000.0, + 'SEAT_BELT_STATUS_FRONT_LEFT': 'BELTED', + 'SEAT_BELT_STATUS_FRONT_MIDDLE': 'NOT_EQUIPPED', + 'SEAT_BELT_STATUS_FRONT_RIGHT': 'BELTED', + 'SEAT_BELT_STATUS_SECOND_LEFT': 'UNKNOWN', + 'SEAT_BELT_STATUS_SECOND_MIDDLE': 'UNKNOWN', + 'SEAT_BELT_STATUS_SECOND_RIGHT': 'UNKNOWN', + 'SEAT_BELT_STATUS_THIRD_LEFT': 'UNKNOWN', + 'SEAT_BELT_STATUS_THIRD_MIDDLE': 'UNKNOWN', + 'SEAT_BELT_STATUS_THIRD_RIGHT': 'UNKNOWN', + 'SEAT_OCCUPATION_STATUS_FRONT_LEFT': 'UNKNOWN', + 'SEAT_OCCUPATION_STATUS_FRONT_MIDDLE': 'NOT_EQUIPPED', + 'SEAT_OCCUPATION_STATUS_FRONT_RIGHT': 'UNKNOWN', + 'SEAT_OCCUPATION_STATUS_SECOND_LEFT': 'UNKNOWN', + 'SEAT_OCCUPATION_STATUS_SECOND_MIDDLE': 'UNKNOWN', + 'SEAT_OCCUPATION_STATUS_SECOND_RIGHT': 'UNKNOWN', + 'SEAT_OCCUPATION_STATUS_THIRD_LEFT': 'UNKNOWN', + 'SEAT_OCCUPATION_STATUS_THIRD_MIDDLE': 'UNKNOWN', + 'SEAT_OCCUPATION_STATUS_THIRD_RIGHT': 'UNKNOWN', + 'TIMESTAMP': 1595560000.0, + 'TRANSMISSION_MODE': 'UNKNOWN', + 'TYRE_PRESSURE_FRONT_LEFT': 0, + 'TYRE_PRESSURE_FRONT_RIGHT': 2550, + 'TYRE_PRESSURE_REAR_LEFT': 2450, + 'TYRE_PRESSURE_REAR_RIGHT': None, + 'TYRE_STATUS_FRONT_LEFT': 'UNKNOWN', + 'TYRE_STATUS_FRONT_RIGHT': 'UNKNOWN', + 'TYRE_STATUS_REAR_LEFT': 'UNKNOWN', + 'TYRE_STATUS_REAR_RIGHT': 'UNKNOWN', + 'VEHICLE_STATE_TYPE': 'IGNITION_OFF', + 'WINDOW_BACK_STATUS': 'UNKNOWN', + 'WINDOW_FRONT_LEFT_STATUS': 'VENTED', + 'WINDOW_FRONT_RIGHT_STATUS': 'VENTED', + 'WINDOW_REAR_LEFT_STATUS': 'UNKNOWN', + 'WINDOW_REAR_RIGHT_STATUS': 'UNKNOWN', + 'WINDOW_SUNROOF_STATUS': 'UNKNOWN', + }), + }), + ]), + 'options': dict({ + 'update_enabled': True, + }), + }) +# --- +# name: test_device_diagnostics + dict({ + 'config_entry': dict({ + 'country': 'USA', + 'device_id': '**REDACTED**', + 'password': '**REDACTED**', + 'pin': '**REDACTED**', + 'username': '**REDACTED**', + }), + 'data': dict({ + 'vehicle_status': dict({ + 'AVG_FUEL_CONSUMPTION': 2.3, + 'DISTANCE_TO_EMPTY_FUEL': 707, + 'DOOR_BOOT_LOCK_STATUS': 'UNKNOWN', + 'DOOR_BOOT_POSITION': 'CLOSED', + 'DOOR_ENGINE_HOOD_LOCK_STATUS': 'UNKNOWN', + 'DOOR_ENGINE_HOOD_POSITION': 'CLOSED', + 'DOOR_FRONT_LEFT_LOCK_STATUS': 'UNKNOWN', + 'DOOR_FRONT_LEFT_POSITION': 'CLOSED', + 'DOOR_FRONT_RIGHT_LOCK_STATUS': 'UNKNOWN', + 'DOOR_FRONT_RIGHT_POSITION': 'CLOSED', + 'DOOR_REAR_LEFT_LOCK_STATUS': 'UNKNOWN', + 'DOOR_REAR_LEFT_POSITION': 'CLOSED', + 'DOOR_REAR_RIGHT_LOCK_STATUS': 'UNKNOWN', + 'DOOR_REAR_RIGHT_POSITION': 'CLOSED', + 'EV_CHARGER_STATE_TYPE': 'CHARGING', + 'EV_CHARGE_SETTING_AMPERE_TYPE': 'MAXIMUM', + 'EV_CHARGE_VOLT_TYPE': 'CHARGE_LEVEL_1', + 'EV_DISTANCE_TO_EMPTY': 1, + 'EV_IS_PLUGGED_IN': 'UNLOCKED_CONNECTED', + 'EV_STATE_OF_CHARGE_MODE': 'EV_MODE', + 'EV_STATE_OF_CHARGE_PERCENT': 20, + 'EV_TIME_TO_FULLY_CHARGED_UTC': '2020-07-24T03:06:40+00:00', + 'HEADING': 170, + 'LATITUDE': '**REDACTED**', + 'LONGITUDE': '**REDACTED**', + 'ODOMETER': '**REDACTED**', + 'POSITION_HEADING_DEGREE': 150, + 'POSITION_SPEED_KMPH': '0', + 'POSITION_TIMESTAMP': 1595560000.0, + 'SEAT_BELT_STATUS_FRONT_LEFT': 'BELTED', + 'SEAT_BELT_STATUS_FRONT_MIDDLE': 'NOT_EQUIPPED', + 'SEAT_BELT_STATUS_FRONT_RIGHT': 'BELTED', + 'SEAT_BELT_STATUS_SECOND_LEFT': 'UNKNOWN', + 'SEAT_BELT_STATUS_SECOND_MIDDLE': 'UNKNOWN', + 'SEAT_BELT_STATUS_SECOND_RIGHT': 'UNKNOWN', + 'SEAT_BELT_STATUS_THIRD_LEFT': 'UNKNOWN', + 'SEAT_BELT_STATUS_THIRD_MIDDLE': 'UNKNOWN', + 'SEAT_BELT_STATUS_THIRD_RIGHT': 'UNKNOWN', + 'SEAT_OCCUPATION_STATUS_FRONT_LEFT': 'UNKNOWN', + 'SEAT_OCCUPATION_STATUS_FRONT_MIDDLE': 'NOT_EQUIPPED', + 'SEAT_OCCUPATION_STATUS_FRONT_RIGHT': 'UNKNOWN', + 'SEAT_OCCUPATION_STATUS_SECOND_LEFT': 'UNKNOWN', + 'SEAT_OCCUPATION_STATUS_SECOND_MIDDLE': 'UNKNOWN', + 'SEAT_OCCUPATION_STATUS_SECOND_RIGHT': 'UNKNOWN', + 'SEAT_OCCUPATION_STATUS_THIRD_LEFT': 'UNKNOWN', + 'SEAT_OCCUPATION_STATUS_THIRD_MIDDLE': 'UNKNOWN', + 'SEAT_OCCUPATION_STATUS_THIRD_RIGHT': 'UNKNOWN', + 'TIMESTAMP': 1595560000.0, + 'TRANSMISSION_MODE': 'UNKNOWN', + 'TYRE_PRESSURE_FRONT_LEFT': 0, + 'TYRE_PRESSURE_FRONT_RIGHT': 2550, + 'TYRE_PRESSURE_REAR_LEFT': 2450, + 'TYRE_PRESSURE_REAR_RIGHT': None, + 'TYRE_STATUS_FRONT_LEFT': 'UNKNOWN', + 'TYRE_STATUS_FRONT_RIGHT': 'UNKNOWN', + 'TYRE_STATUS_REAR_LEFT': 'UNKNOWN', + 'TYRE_STATUS_REAR_RIGHT': 'UNKNOWN', + 'VEHICLE_STATE_TYPE': 'IGNITION_OFF', + 'WINDOW_BACK_STATUS': 'UNKNOWN', + 'WINDOW_FRONT_LEFT_STATUS': 'VENTED', + 'WINDOW_FRONT_RIGHT_STATUS': 'VENTED', + 'WINDOW_REAR_LEFT_STATUS': 'UNKNOWN', + 'WINDOW_REAR_RIGHT_STATUS': 'UNKNOWN', + 'WINDOW_SUNROOF_STATUS': 'UNKNOWN', + }), + }), + 'options': dict({ + 'update_enabled': True, + }), + 'raw_data': dict({ + 'climatePresetSettings': dict({ + 'data': list([ + '{"name": "Auto", "runTimeMinutes": "10", "climateZoneFrontTemp": "74", "climateZoneFrontAirMode": "AUTO", "climateZoneFrontAirVolume": "AUTO", "outerAirCirculation": "auto", "heatedRearWindowActive": "false", "airConditionOn": "false", "heatedSeatFrontLeft": "off", "heatedSeatFrontRight": "off", "startConfiguration": "START_ENGINE_ALLOW_KEY_IN_IGNITION", "canEdit": "true", "disabled": "false", "vehicleType": "gas", "presetType": "subaruPreset" }', + '{"name":"Full Cool","runTimeMinutes":"10","climateZoneFrontTemp":"60","climateZoneFrontAirMode":"feet_face_balanced","climateZoneFrontAirVolume":"7","airConditionOn":"true","heatedSeatFrontLeft":"high_cool","heatedSeatFrontRight":"high_cool","heatedRearWindowActive":"false","outerAirCirculation":"outsideAir","startConfiguration":"START_ENGINE_ALLOW_KEY_IN_IGNITION","canEdit":"true","disabled":"true","vehicleType":"gas","presetType":"subaruPreset"}', + '{"name": "Full Heat", "runTimeMinutes": "10", "climateZoneFrontTemp": "85", "climateZoneFrontAirMode": "feet_window", "climateZoneFrontAirVolume": "7", "airConditionOn": "false", "heatedSeatFrontLeft": "high_heat", "heatedSeatFrontRight": "high_heat", "heatedRearWindowActive": "true", "outerAirCirculation": "outsideAir", "startConfiguration": "START_ENGINE_ALLOW_KEY_IN_IGNITION", "canEdit": "true", "disabled": "true", "vehicleType": "gas", "presetType": "subaruPreset" }', + '{"name": "Full Cool", "runTimeMinutes": "10", "climateZoneFrontTemp": "60", "climateZoneFrontAirMode": "feet_face_balanced", "climateZoneFrontAirVolume": "7", "airConditionOn": "true", "heatedSeatFrontLeft": "OFF", "heatedSeatFrontRight": "OFF", "heatedRearWindowActive": "false", "outerAirCirculation": "outsideAir", "startConfiguration": "START_CLIMATE_CONTROL_ONLY_ALLOW_KEY_IN_IGNITION", "canEdit": "true", "disabled": "true", "vehicleType": "phev", "presetType": "subaruPreset" }', + '{"name": "Full Heat", "runTimeMinutes": "10", "climateZoneFrontTemp": "85", "climateZoneFrontAirMode": "feet_window", "climateZoneFrontAirVolume": "7", "airConditionOn": "false", "heatedSeatFrontLeft": "high_heat", "heatedSeatFrontRight": "high_heat", "heatedRearWindowActive": "true", "outerAirCirculation": "outsideAir", "startConfiguration": "START_CLIMATE_CONTROL_ONLY_ALLOW_KEY_IN_IGNITION", "canEdit": "true", "disabled": "true", "vehicleType": "phev", "presetType": "subaruPreset" }', + ]), + 'dataName': None, + 'errorCode': None, + 'success': True, + }), + 'condition': dict({ + 'data': dict({ + 'cancelled': False, + 'errorCode': None, + 'errorDescription': None, + 'remoteServiceState': 'finished', + 'remoteServiceType': 'condition', + 'result': dict({ + 'avgFuelConsumption': None, + 'avgFuelConsumptionUnit': 'MPG', + 'distanceToEmptyFuel': None, + 'distanceToEmptyFuelUnit': 'MILES', + 'doorBootPosition': 'CLOSED', + 'doorEngineHoodPosition': 'CLOSED', + 'doorFrontLeftPosition': 'CLOSED', + 'doorFrontRightPosition': 'CLOSED', + 'doorRearLeftPosition': 'CLOSED', + 'doorRearRightPosition': 'CLOSED', + 'evChargerStateType': 'CHARGING_STOPPED', + 'evDistanceToEmpty': 17, + 'evDistanceToEmptyUnit': 'MILES', + 'evIsPluggedIn': 'UNLOCKED_CONNECTED', + 'evStateOfChargeMode': 'EV_MODE', + 'evStateOfChargePercent': '100', + 'evTimeToFullyCharged': '65535', + 'lastUpdatedTime': '2020-07-24T03:06:00+0000', + 'odometer': '**REDACTED**', + 'odometerUnit': 'MILES', + 'remainingFuelPercent': None, + 'tirePressureFrontLeft': None, + 'tirePressureFrontLeftUnit': 'PSI', + 'tirePressureFrontRight': None, + 'tirePressureFrontRightUnit': 'PSI', + 'tirePressureRearLeft': None, + 'tirePressureRearLeftUnit': 'PSI', + 'tirePressureRearRight': None, + 'tirePressureRearRightUnit': 'PSI', + 'vehicleStateType': 'IGNITION_OFF', + 'windowFrontLeftStatus': 'VENTED', + 'windowFrontRightStatus': 'VENTED', + 'windowRearLeftStatus': 'UNKNOWN', + 'windowRearRightStatus': 'UNKNOWN', + 'windowSunroofStatus': 'UNKNOWN', + }), + 'serviceRequestId': None, + 'subState': None, + 'success': True, + 'updateTime': None, + 'vin': '**REDACTED**', + }), + 'dataName': 'remoteServiceStatus', + 'errorCode': None, + 'success': True, + }), + 'locate': dict({ + 'data': dict({ + 'cancelled': False, + 'errorCode': None, + 'errorDescription': None, + 'remoteServiceState': 'finished', + 'remoteServiceType': 'locate', + 'result': dict({ + 'heading': None, + 'latitude': '**REDACTED**', + 'locationTimestamp': 1595560000000, + 'longitude': '**REDACTED**', + 'speed': None, + }), + 'serviceRequestId': None, + 'subState': None, + 'success': True, + 'updateTime': None, + 'vin': '**REDACTED**', + }), + 'dataName': 'remoteServiceStatus', + 'errorCode': None, + 'success': True, + }), + 'remoteEngineStartSettings': dict({ + 'data': '{"name": "Full Heat", "runTimeMinutes": "10", "climateZoneFrontTemp": "85", "climateZoneFrontAirMode": "feet_window", "climateZoneFrontAirVolume": "7", "airConditionOn": "false", "heatedSeatFrontLeft": "high_heat", "heatedSeatFrontRight": "high_heat", "heatedRearWindowActive": "true", "outerAirCirculation": "outsideAir", "startConfiguration": "START_CLIMATE_CONTROL_ONLY_ALLOW_KEY_IN_IGNITION", "canEdit": "true", "disabled": "true", "vehicleType": "phev", "presetType": "subaruPreset" }', + 'dataName': None, + 'errorCode': None, + 'success': True, + }), + 'switchVehicle': dict({ + 'accessLevel': 1, + 'active': True, + 'authorizedVehicle': True, + 'cachedStateCode': '**REDACTED**', + 'crmRightToRepair': False, + 'customer': '**REDACTED**', + 'email': '**REDACTED**', + 'engineSize': 2.0, + 'extDescrip': 'Cool-Gray Khaki', + 'features': list([ + 'ABS_MIL', + 'AHBL_MIL', + 'ATF_MIL', + 'AWD_MIL', + 'BSD', + 'BSDRCT_MIL', + 'CEL_MIL', + 'EBD_MIL', + 'EOL_MIL', + 'EPAS_MIL', + 'EPB_MIL', + 'ESS_MIL', + 'EYESIGHT', + 'HEVCM_MIL', + 'HEV_MIL', + 'NAV_TOMTOM', + 'OPL_MIL', + 'PHEV', + 'RAB_MIL', + 'RCC', + 'REARBRK', + 'RPOIA', + 'SRS_MIL', + 'TEL_MIL', + 'TIF_36', + 'TIR_35', + 'TPMS_MIL', + 'VDC_MIL', + 'WASH_MIL', + 'g2', + ]), + 'firstName': '**REDACTED**', + 'intDescrip': 'Navy', + 'lastName': '**REDACTED**', + 'licensePlate': '**REDACTED**', + 'licensePlateState': '**REDACTED**', + 'modelCode': 'KRH', + 'modelName': 'Crosstrek', + 'modelYear': '2019', + 'needEmergencyContactPrompt': False, + 'needMileagePrompt': False, + 'nickname': '**REDACTED**', + 'oemCustId': '**REDACTED**', + 'phev': None, + 'phone': '**REDACTED**', + 'preferredDealer': '**REDACTED**', + 'provisioned': True, + 'remoteServicePinExist': True, + 'show3gSunsetBanner': False, + 'stolenVehicle': False, + 'subscriptionFeatures': list([ + 'REMOTE', + 'SAFETY', + 'RetailPHEV', + ]), + 'subscriptionPlans': list([ + ]), + 'subscriptionStatus': 'ACTIVE', + 'sunsetUpgraded': True, + 'timeZone': '**REDACTED**', + 'transCode': 'CVT', + 'userOemCustId': '**REDACTED**', + 'vehicleGeoPosition': '**REDACTED**', + 'vehicleKey': '**REDACTED**', + 'vehicleMileage': '**REDACTED**', + 'vehicleName': '**REDACTED**', + 'vin': '**REDACTED**', + 'zip': '**REDACTED**', + }), + 'vehicleStatus': dict({ + 'data': dict({ + 'avgFuelConsumptionLitersPer100Kilometers': 4.5, + 'avgFuelConsumptionMpg': 52.3, + 'distanceToEmptyFuelKilometers': 852, + 'distanceToEmptyFuelKilometers10s': 850, + 'distanceToEmptyFuelMiles': 529.41, + 'distanceToEmptyFuelMiles10s': 530, + 'evDistanceToEmptyByStateKilometers': None, + 'evDistanceToEmptyByStateMiles': None, + 'evDistanceToEmptyKilometers': 852, + 'evDistanceToEmptyMiles': 529.41, + 'evStateOfChargePercent': 14, + 'eventDate': 1595560000000, + 'eventDateStr': '2020-07-24T03:06+0000', + 'latitude': '**REDACTED**', + 'longitude': '**REDACTED**', + 'odometerValue': '**REDACTED**', + 'odometerValueKilometers': '**REDACTED**', + 'positionHeadingDegree': '261', + 'remainingFuelPercent': None, + 'tirePressureFrontLeft': '2600', + 'tirePressureFrontLeftPsi': '37.71', + 'tirePressureFrontRight': '2700', + 'tirePressureFrontRightPsi': '39.16', + 'tirePressureRearLeft': '2650', + 'tirePressureRearLeftPsi': '38.44', + 'tirePressureRearRight': '2650', + 'tirePressureRearRightPsi': '38.44', + 'tyreStatusFrontLeft': 'UNKNOWN', + 'tyreStatusFrontRight': 'UNKNOWN', + 'tyreStatusRearLeft': 'UNKNOWN', + 'tyreStatusRearRight': 'UNKNOWN', + 'vehicleStateType': 'IGNITION_OFF', + 'vhsId': '**REDACTED**', + 'windowFrontLeftStatus': 'VENTED', + 'windowFrontRightStatus': 'VENTED', + 'windowRearLeftStatus': 'UNKNOWN', + 'windowRearRightStatus': 'UNKNOWN', + 'windowSunroofStatus': 'UNKNOWN', + }), + 'dataName': None, + 'errorCode': None, + 'success': True, + }), + }), + }) +# --- diff --git a/tests/components/subaru/test_diagnostics.py b/tests/components/subaru/test_diagnostics.py index 9445f1ca235bf..95287b94a7a8c 100644 --- a/tests/components/subaru/test_diagnostics.py +++ b/tests/components/subaru/test_diagnostics.py @@ -4,13 +4,19 @@ from unittest.mock import patch import pytest +from syrupy.assertion import SnapshotAssertion from homeassistant.components.subaru.const import DOMAIN from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr from .api_responses import TEST_VIN_2_EV -from .conftest import MOCK_API_FETCH, MOCK_API_GET_DATA, advance_time_to_next_fetch +from .conftest import ( + MOCK_API_FETCH, + MOCK_API_GET_DATA, + MOCK_API_GET_RAW_DATA, + advance_time_to_next_fetch, +) from tests.common import load_fixture from tests.components.diagnostics import ( @@ -21,24 +27,26 @@ async def test_config_entry_diagnostics( - hass: HomeAssistant, hass_client: ClientSessionGenerator, ev_entry + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + snapshot: SnapshotAssertion, + ev_entry, ) -> None: """Test config entry diagnostics.""" config_entry = hass.config_entries.async_entries(DOMAIN)[0] - diagnostics_fixture = json.loads( - load_fixture("subaru/diagnostics_config_entry.json") - ) - assert ( await get_diagnostics_for_config_entry(hass, hass_client, config_entry) - == diagnostics_fixture + == snapshot ) async def test_device_diagnostics( - hass: HomeAssistant, hass_client: ClientSessionGenerator, ev_entry + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + snapshot: SnapshotAssertion, + ev_entry, ) -> None: """Test device diagnostics.""" @@ -50,12 +58,15 @@ async def test_device_diagnostics( ) assert reg_device is not None - diagnostics_fixture = json.loads(load_fixture("subaru/diagnostics_device.json")) - - assert ( - await get_diagnostics_for_device(hass, hass_client, config_entry, reg_device) - == diagnostics_fixture - ) + raw_data = json.loads(load_fixture("subaru/raw_api_data.json")) + with patch(MOCK_API_GET_RAW_DATA, return_value=raw_data) as mock_get_raw_data: + assert ( + await get_diagnostics_for_device( + hass, hass_client, config_entry, reg_device + ) + == snapshot + ) + mock_get_raw_data.assert_called_once() async def test_device_diagnostics_vehicle_not_found(