From 29c95a0b3472a21ee5feccd6a15b843633fad0eb Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 25 Oct 2021 15:42:01 +0200 Subject: [PATCH] Use constants in renault tests (#58406) Co-authored-by: epenet --- tests/components/renault/__init__.py | 25 +- tests/components/renault/const.py | 368 ++++++++++++------------ tests/components/renault/test_sensor.py | 8 +- 3 files changed, 209 insertions(+), 192 deletions(-) diff --git a/tests/components/renault/__init__.py b/tests/components/renault/__init__.py index 7b3bb9e3d0a..f13adae1982 100644 --- a/tests/components/renault/__init__.py +++ b/tests/components/renault/__init__.py @@ -4,11 +4,13 @@ from __future__ import annotations from types import MappingProxyType from homeassistant.const import ( + ATTR_ENTITY_ID, ATTR_ICON, ATTR_IDENTIFIERS, ATTR_MANUFACTURER, ATTR_MODEL, ATTR_NAME, + ATTR_STATE, ATTR_SW_VERSION, STATE_UNAVAILABLE, ) @@ -16,12 +18,17 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import DeviceRegistry from homeassistant.helpers.entity_registry import EntityRegistry -from .const import DYNAMIC_ATTRIBUTES, FIXED_ATTRIBUTES, ICON_FOR_EMPTY_VALUES +from .const import ( + ATTR_UNIQUE_ID, + DYNAMIC_ATTRIBUTES, + FIXED_ATTRIBUTES, + ICON_FOR_EMPTY_VALUES, +) def get_no_data_icon(expected_entity: MappingProxyType): """Check icon attribute for inactive sensors.""" - entity_id = expected_entity["entity_id"] + entity_id = expected_entity[ATTR_ENTITY_ID] return ICON_FOR_EMPTY_VALUES.get(entity_id, expected_entity.get(ATTR_ICON)) @@ -46,12 +53,12 @@ def check_entities( ) -> None: """Ensure that the expected_entities are correct.""" for expected_entity in expected_entities: - entity_id = expected_entity["entity_id"] + entity_id = expected_entity[ATTR_ENTITY_ID] registry_entry = entity_registry.entities.get(entity_id) assert registry_entry is not None - assert registry_entry.unique_id == expected_entity["unique_id"] + assert registry_entry.unique_id == expected_entity[ATTR_UNIQUE_ID] state = hass.states.get(entity_id) - assert state.state == expected_entity["result"] + assert state.state == expected_entity[ATTR_STATE] for attr in FIXED_ATTRIBUTES + DYNAMIC_ATTRIBUTES: assert state.attributes.get(attr) == expected_entity.get(attr) @@ -64,10 +71,10 @@ def check_entities_no_data( ) -> None: """Ensure that the expected_entities are correct.""" for expected_entity in expected_entities: - entity_id = expected_entity["entity_id"] + entity_id = expected_entity[ATTR_ENTITY_ID] registry_entry = entity_registry.entities.get(entity_id) assert registry_entry is not None - assert registry_entry.unique_id == expected_entity["unique_id"] + assert registry_entry.unique_id == expected_entity[ATTR_UNIQUE_ID] state = hass.states.get(entity_id) assert state.state == expected_state for attr in FIXED_ATTRIBUTES: @@ -83,10 +90,10 @@ def check_entities_unavailable( ) -> None: """Ensure that the expected_entities are correct.""" for expected_entity in expected_entities: - entity_id = expected_entity["entity_id"] + entity_id = expected_entity[ATTR_ENTITY_ID] registry_entry = entity_registry.entities.get(entity_id) assert registry_entry is not None - assert registry_entry.unique_id == expected_entity["unique_id"] + assert registry_entry.unique_id == expected_entity[ATTR_UNIQUE_ID] state = hass.states.get(entity_id) assert state.state == STATE_UNAVAILABLE for attr in FIXED_ATTRIBUTES: diff --git a/tests/components/renault/const.py b/tests/components/renault/const.py index f1296ba2ce3..e3703173ad0 100644 --- a/tests/components/renault/const.py +++ b/tests/components/renault/const.py @@ -23,7 +23,14 @@ from homeassistant.components.sensor import ( ) from homeassistant.const import ( ATTR_DEVICE_CLASS, + ATTR_ENTITY_ID, ATTR_ICON, + ATTR_IDENTIFIERS, + ATTR_MANUFACTURER, + ATTR_MODEL, + ATTR_NAME, + ATTR_STATE, + ATTR_SW_VERSION, ATTR_UNIT_OF_MEASUREMENT, CONF_PASSWORD, CONF_USERNAME, @@ -47,6 +54,9 @@ from homeassistant.const import ( VOLUME_LITERS, ) +ATTR_DEFAULT_DISABLED = "default_disabled" +ATTR_UNIQUE_ID = "unique_id" + FIXED_ATTRIBUTES = ( ATTR_DEVICE_CLASS, ATTR_OPTIONS, @@ -74,11 +84,11 @@ MOCK_CONFIG = { MOCK_VEHICLES = { "zoe_40": { "expected_device": { - "identifiers": {(DOMAIN, "VF1AAAAA555777999")}, - "manufacturer": "Renault", - "model": "Zoe", - "name": "REG-NUMBER", - "sw_version": "X101VE", + ATTR_IDENTIFIERS: {(DOMAIN, "VF1AAAAA555777999")}, + ATTR_MANUFACTURER: "Renault", + ATTR_MODEL: "Zoe", + ATTR_NAME: "REG-NUMBER", + ATTR_SW_VERSION: "X101VE", }, "endpoints_available": [ True, # cockpit @@ -95,124 +105,124 @@ MOCK_VEHICLES = { }, BINARY_SENSOR_DOMAIN: [ { - "entity_id": "binary_sensor.reg_number_plugged_in", - "unique_id": "vf1aaaaa555777999_plugged_in", - "result": STATE_ON, ATTR_DEVICE_CLASS: DEVICE_CLASS_PLUG, + ATTR_ENTITY_ID: "binary_sensor.reg_number_plugged_in", + ATTR_STATE: STATE_ON, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_plugged_in", }, { - "entity_id": "binary_sensor.reg_number_charging", - "unique_id": "vf1aaaaa555777999_charging", - "result": STATE_ON, ATTR_DEVICE_CLASS: DEVICE_CLASS_BATTERY_CHARGING, + ATTR_ENTITY_ID: "binary_sensor.reg_number_charging", + ATTR_STATE: STATE_ON, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging", }, ], DEVICE_TRACKER_DOMAIN: [], SELECT_DOMAIN: [ { - "entity_id": "select.reg_number_charge_mode", - "unique_id": "vf1aaaaa555777999_charge_mode", - "result": "always", ATTR_DEVICE_CLASS: DEVICE_CLASS_CHARGE_MODE, + ATTR_ENTITY_ID: "select.reg_number_charge_mode", ATTR_ICON: "mdi:calendar-remove", ATTR_OPTIONS: ["always", "always_charging", "schedule_mode"], + ATTR_STATE: "always", + ATTR_UNIQUE_ID: "vf1aaaaa555777999_charge_mode", }, ], SENSOR_DOMAIN: [ { - "entity_id": "sensor.reg_number_battery_autonomy", - "unique_id": "vf1aaaaa555777999_battery_autonomy", - "result": "141", + ATTR_ENTITY_ID: "sensor.reg_number_battery_autonomy", ATTR_ICON: "mdi:ev-station", + ATTR_STATE: "141", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_autonomy", ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, }, { - "entity_id": "sensor.reg_number_battery_available_energy", - "unique_id": "vf1aaaaa555777999_battery_available_energy", - "result": "31", ATTR_DEVICE_CLASS: DEVICE_CLASS_ENERGY, + ATTR_ENTITY_ID: "sensor.reg_number_battery_available_energy", + ATTR_STATE: "31", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_available_energy", ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR, }, { - "entity_id": "sensor.reg_number_battery_level", - "unique_id": "vf1aaaaa555777999_battery_level", - "result": "60", ATTR_DEVICE_CLASS: DEVICE_CLASS_BATTERY, + ATTR_ENTITY_ID: "sensor.reg_number_battery_level", + ATTR_STATE: "60", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_level", ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE, }, { - "entity_id": "sensor.reg_number_battery_last_activity", - "unique_id": "vf1aaaaa555777999_battery_last_activity", - "result": "2020-01-12T21:40:16+00:00", - "default_disabled": True, + ATTR_DEFAULT_DISABLED: True, ATTR_DEVICE_CLASS: DEVICE_CLASS_TIMESTAMP, + ATTR_ENTITY_ID: "sensor.reg_number_battery_last_activity", + ATTR_STATE: "2020-01-12T21:40:16+00:00", + ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_last_activity", }, { - "entity_id": "sensor.reg_number_battery_temperature", - "unique_id": "vf1aaaaa555777999_battery_temperature", - "result": "20", ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, + ATTR_ENTITY_ID: "sensor.reg_number_battery_temperature", + ATTR_STATE: "20", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_temperature", ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS, }, { - "entity_id": "sensor.reg_number_charge_state", - "unique_id": "vf1aaaaa555777999_charge_state", - "result": "charge_in_progress", ATTR_DEVICE_CLASS: DEVICE_CLASS_CHARGE_STATE, + ATTR_ENTITY_ID: "sensor.reg_number_charge_state", ATTR_ICON: "mdi:flash", + ATTR_STATE: "charge_in_progress", + ATTR_UNIQUE_ID: "vf1aaaaa555777999_charge_state", }, { - "entity_id": "sensor.reg_number_charging_power", - "unique_id": "vf1aaaaa555777999_charging_power", - "result": "0.027", ATTR_DEVICE_CLASS: DEVICE_CLASS_POWER, + ATTR_ENTITY_ID: "sensor.reg_number_charging_power", + ATTR_STATE: "0.027", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging_power", ATTR_UNIT_OF_MEASUREMENT: POWER_KILO_WATT, }, { - "entity_id": "sensor.reg_number_charging_remaining_time", - "unique_id": "vf1aaaaa555777999_charging_remaining_time", - "result": "145", + ATTR_ENTITY_ID: "sensor.reg_number_charging_remaining_time", ATTR_ICON: "mdi:timer", + ATTR_STATE: "145", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging_remaining_time", ATTR_UNIT_OF_MEASUREMENT: TIME_MINUTES, }, { - "entity_id": "sensor.reg_number_mileage", - "unique_id": "vf1aaaaa555777999_mileage", - "result": "49114", + ATTR_ENTITY_ID: "sensor.reg_number_mileage", ATTR_ICON: "mdi:sign-direction", + ATTR_STATE: "49114", ATTR_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_mileage", ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, }, { - "entity_id": "sensor.reg_number_outside_temperature", - "unique_id": "vf1aaaaa555777999_outside_temperature", - "result": "8.0", ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, + ATTR_ENTITY_ID: "sensor.reg_number_outside_temperature", + ATTR_STATE: "8.0", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_outside_temperature", ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS, }, { - "entity_id": "sensor.reg_number_plug_state", - "unique_id": "vf1aaaaa555777999_plug_state", - "result": "plugged", ATTR_DEVICE_CLASS: DEVICE_CLASS_PLUG_STATE, + ATTR_ENTITY_ID: "sensor.reg_number_plug_state", ATTR_ICON: "mdi:power-plug", + ATTR_STATE: "plugged", + ATTR_UNIQUE_ID: "vf1aaaaa555777999_plug_state", }, ], }, "zoe_50": { "expected_device": { - "identifiers": {(DOMAIN, "VF1AAAAA555777999")}, - "manufacturer": "Renault", - "model": "Zoe", - "name": "REG-NUMBER", - "sw_version": "X102VE", + ATTR_IDENTIFIERS: {(DOMAIN, "VF1AAAAA555777999")}, + ATTR_MANUFACTURER: "Renault", + ATTR_MODEL: "Zoe", + ATTR_NAME: "REG-NUMBER", + ATTR_SW_VERSION: "X102VE", }, "endpoints_available": [ True, # cockpit @@ -229,130 +239,130 @@ MOCK_VEHICLES = { }, BINARY_SENSOR_DOMAIN: [ { - "entity_id": "binary_sensor.reg_number_plugged_in", - "unique_id": "vf1aaaaa555777999_plugged_in", - "result": STATE_OFF, ATTR_DEVICE_CLASS: DEVICE_CLASS_PLUG, + ATTR_ENTITY_ID: "binary_sensor.reg_number_plugged_in", + ATTR_STATE: STATE_OFF, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_plugged_in", }, { - "entity_id": "binary_sensor.reg_number_charging", - "unique_id": "vf1aaaaa555777999_charging", - "result": STATE_OFF, ATTR_DEVICE_CLASS: DEVICE_CLASS_BATTERY_CHARGING, + ATTR_ENTITY_ID: "binary_sensor.reg_number_charging", + ATTR_STATE: STATE_OFF, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging", }, ], DEVICE_TRACKER_DOMAIN: [ { - "entity_id": "device_tracker.reg_number_location", - "unique_id": "vf1aaaaa555777999_location", - "result": STATE_NOT_HOME, + ATTR_ENTITY_ID: "device_tracker.reg_number_location", ATTR_ICON: "mdi:car", + ATTR_STATE: STATE_NOT_HOME, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_location", } ], SELECT_DOMAIN: [ { - "entity_id": "select.reg_number_charge_mode", - "unique_id": "vf1aaaaa555777999_charge_mode", - "result": "schedule_mode", ATTR_DEVICE_CLASS: DEVICE_CLASS_CHARGE_MODE, + ATTR_ENTITY_ID: "select.reg_number_charge_mode", ATTR_ICON: "mdi:calendar-clock", ATTR_OPTIONS: ["always", "always_charging", "schedule_mode"], + ATTR_STATE: "schedule_mode", + ATTR_UNIQUE_ID: "vf1aaaaa555777999_charge_mode", }, ], SENSOR_DOMAIN: [ { - "entity_id": "sensor.reg_number_battery_autonomy", - "unique_id": "vf1aaaaa555777999_battery_autonomy", - "result": "128", + ATTR_ENTITY_ID: "sensor.reg_number_battery_autonomy", ATTR_ICON: "mdi:ev-station", + ATTR_STATE: "128", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_autonomy", ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, }, { - "entity_id": "sensor.reg_number_battery_available_energy", - "unique_id": "vf1aaaaa555777999_battery_available_energy", - "result": "0", ATTR_DEVICE_CLASS: DEVICE_CLASS_ENERGY, + ATTR_ENTITY_ID: "sensor.reg_number_battery_available_energy", + ATTR_STATE: "0", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_available_energy", ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR, }, { - "entity_id": "sensor.reg_number_battery_level", - "unique_id": "vf1aaaaa555777999_battery_level", - "result": "50", ATTR_DEVICE_CLASS: DEVICE_CLASS_BATTERY, + ATTR_ENTITY_ID: "sensor.reg_number_battery_level", + ATTR_STATE: "50", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_level", ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE, }, { - "entity_id": "sensor.reg_number_battery_last_activity", - "unique_id": "vf1aaaaa555777999_battery_last_activity", - "result": "2020-11-17T08:06:48+00:00", - "default_disabled": True, + ATTR_DEFAULT_DISABLED: True, ATTR_DEVICE_CLASS: DEVICE_CLASS_TIMESTAMP, + ATTR_ENTITY_ID: "sensor.reg_number_battery_last_activity", + ATTR_STATE: "2020-11-17T08:06:48+00:00", + ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_last_activity", }, { - "entity_id": "sensor.reg_number_battery_temperature", - "unique_id": "vf1aaaaa555777999_battery_temperature", - "result": STATE_UNKNOWN, ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, + ATTR_ENTITY_ID: "sensor.reg_number_battery_temperature", + ATTR_STATE: STATE_UNKNOWN, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_temperature", ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS, }, { - "entity_id": "sensor.reg_number_charge_state", - "unique_id": "vf1aaaaa555777999_charge_state", - "result": "charge_error", ATTR_DEVICE_CLASS: DEVICE_CLASS_CHARGE_STATE, + ATTR_ENTITY_ID: "sensor.reg_number_charge_state", ATTR_ICON: "mdi:flash-off", + ATTR_STATE: "charge_error", + ATTR_UNIQUE_ID: "vf1aaaaa555777999_charge_state", }, { - "entity_id": "sensor.reg_number_charging_power", - "unique_id": "vf1aaaaa555777999_charging_power", - "result": STATE_UNKNOWN, ATTR_DEVICE_CLASS: DEVICE_CLASS_CURRENT, + ATTR_ENTITY_ID: "sensor.reg_number_charging_power", + ATTR_STATE: STATE_UNKNOWN, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging_power", ATTR_UNIT_OF_MEASUREMENT: ELECTRIC_CURRENT_AMPERE, }, { - "entity_id": "sensor.reg_number_charging_remaining_time", - "unique_id": "vf1aaaaa555777999_charging_remaining_time", - "result": STATE_UNKNOWN, + ATTR_ENTITY_ID: "sensor.reg_number_charging_remaining_time", ATTR_ICON: "mdi:timer", + ATTR_STATE: STATE_UNKNOWN, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging_remaining_time", ATTR_UNIT_OF_MEASUREMENT: TIME_MINUTES, }, { - "entity_id": "sensor.reg_number_mileage", - "unique_id": "vf1aaaaa555777999_mileage", - "result": "49114", + ATTR_ENTITY_ID: "sensor.reg_number_mileage", ATTR_ICON: "mdi:sign-direction", + ATTR_STATE: "49114", ATTR_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_mileage", ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, }, { - "entity_id": "sensor.reg_number_plug_state", - "unique_id": "vf1aaaaa555777999_plug_state", - "result": "unplugged", ATTR_DEVICE_CLASS: DEVICE_CLASS_PLUG_STATE, + ATTR_ENTITY_ID: "sensor.reg_number_plug_state", ATTR_ICON: "mdi:power-plug-off", + ATTR_STATE: "unplugged", + ATTR_UNIQUE_ID: "vf1aaaaa555777999_plug_state", }, { - "entity_id": "sensor.reg_number_location_last_activity", - "unique_id": "vf1aaaaa555777999_location_last_activity", - "result": "2020-02-18T16:58:38+00:00", - "default_disabled": True, + ATTR_DEFAULT_DISABLED: True, ATTR_DEVICE_CLASS: DEVICE_CLASS_TIMESTAMP, + ATTR_ENTITY_ID: "sensor.reg_number_location_last_activity", + ATTR_STATE: "2020-02-18T16:58:38+00:00", + ATTR_UNIQUE_ID: "vf1aaaaa555777999_location_last_activity", }, ], }, "captur_phev": { "expected_device": { - "identifiers": {(DOMAIN, "VF1AAAAA555777123")}, - "manufacturer": "Renault", - "model": "Captur ii", - "name": "REG-NUMBER", - "sw_version": "XJB1SU", + ATTR_IDENTIFIERS: {(DOMAIN, "VF1AAAAA555777123")}, + ATTR_MANUFACTURER: "Renault", + ATTR_MODEL: "Captur ii", + ATTR_NAME: "REG-NUMBER", + ATTR_SW_VERSION: "XJB1SU", }, "endpoints_available": [ True, # cockpit @@ -369,146 +379,146 @@ MOCK_VEHICLES = { }, BINARY_SENSOR_DOMAIN: [ { - "entity_id": "binary_sensor.reg_number_plugged_in", - "unique_id": "vf1aaaaa555777123_plugged_in", - "result": STATE_ON, ATTR_DEVICE_CLASS: DEVICE_CLASS_PLUG, + ATTR_ENTITY_ID: "binary_sensor.reg_number_plugged_in", + ATTR_STATE: STATE_ON, + ATTR_UNIQUE_ID: "vf1aaaaa555777123_plugged_in", }, { - "entity_id": "binary_sensor.reg_number_charging", - "unique_id": "vf1aaaaa555777123_charging", - "result": STATE_ON, ATTR_DEVICE_CLASS: DEVICE_CLASS_BATTERY_CHARGING, + ATTR_ENTITY_ID: "binary_sensor.reg_number_charging", + ATTR_STATE: STATE_ON, + ATTR_UNIQUE_ID: "vf1aaaaa555777123_charging", }, ], DEVICE_TRACKER_DOMAIN: [ { - "entity_id": "device_tracker.reg_number_location", - "unique_id": "vf1aaaaa555777123_location", - "result": STATE_NOT_HOME, + ATTR_ENTITY_ID: "device_tracker.reg_number_location", ATTR_ICON: "mdi:car", + ATTR_STATE: STATE_NOT_HOME, + ATTR_UNIQUE_ID: "vf1aaaaa555777123_location", } ], SELECT_DOMAIN: [ { - "entity_id": "select.reg_number_charge_mode", - "unique_id": "vf1aaaaa555777123_charge_mode", - "result": "always", ATTR_DEVICE_CLASS: DEVICE_CLASS_CHARGE_MODE, + ATTR_ENTITY_ID: "select.reg_number_charge_mode", ATTR_ICON: "mdi:calendar-remove", ATTR_OPTIONS: ["always", "always_charging", "schedule_mode"], + ATTR_STATE: "always", + ATTR_UNIQUE_ID: "vf1aaaaa555777123_charge_mode", }, ], SENSOR_DOMAIN: [ { - "entity_id": "sensor.reg_number_battery_autonomy", - "unique_id": "vf1aaaaa555777123_battery_autonomy", - "result": "141", + ATTR_ENTITY_ID: "sensor.reg_number_battery_autonomy", ATTR_ICON: "mdi:ev-station", + ATTR_STATE: "141", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777123_battery_autonomy", ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, }, { - "entity_id": "sensor.reg_number_battery_available_energy", - "unique_id": "vf1aaaaa555777123_battery_available_energy", - "result": "31", ATTR_DEVICE_CLASS: DEVICE_CLASS_ENERGY, + ATTR_ENTITY_ID: "sensor.reg_number_battery_available_energy", + ATTR_STATE: "31", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777123_battery_available_energy", ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR, }, { - "entity_id": "sensor.reg_number_battery_level", - "unique_id": "vf1aaaaa555777123_battery_level", - "result": "60", ATTR_DEVICE_CLASS: DEVICE_CLASS_BATTERY, + ATTR_ENTITY_ID: "sensor.reg_number_battery_level", + ATTR_STATE: "60", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777123_battery_level", ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE, }, { - "entity_id": "sensor.reg_number_battery_last_activity", - "unique_id": "vf1aaaaa555777123_battery_last_activity", - "result": "2020-01-12T21:40:16+00:00", - "default_disabled": True, + ATTR_DEFAULT_DISABLED: True, ATTR_DEVICE_CLASS: DEVICE_CLASS_TIMESTAMP, + ATTR_ENTITY_ID: "sensor.reg_number_battery_last_activity", + ATTR_STATE: "2020-01-12T21:40:16+00:00", + ATTR_UNIQUE_ID: "vf1aaaaa555777123_battery_last_activity", }, { - "entity_id": "sensor.reg_number_battery_temperature", - "unique_id": "vf1aaaaa555777123_battery_temperature", - "result": "20", ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, + ATTR_ENTITY_ID: "sensor.reg_number_battery_temperature", + ATTR_STATE: "20", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777123_battery_temperature", ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS, }, { - "entity_id": "sensor.reg_number_charge_state", - "unique_id": "vf1aaaaa555777123_charge_state", - "result": "charge_in_progress", ATTR_DEVICE_CLASS: DEVICE_CLASS_CHARGE_STATE, + ATTR_ENTITY_ID: "sensor.reg_number_charge_state", ATTR_ICON: "mdi:flash", + ATTR_STATE: "charge_in_progress", + ATTR_UNIQUE_ID: "vf1aaaaa555777123_charge_state", }, { - "entity_id": "sensor.reg_number_charging_power", - "unique_id": "vf1aaaaa555777123_charging_power", - "result": "27.0", ATTR_DEVICE_CLASS: DEVICE_CLASS_CURRENT, + ATTR_ENTITY_ID: "sensor.reg_number_charging_power", + ATTR_STATE: "27.0", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777123_charging_power", ATTR_UNIT_OF_MEASUREMENT: ELECTRIC_CURRENT_AMPERE, }, { - "entity_id": "sensor.reg_number_charging_remaining_time", - "unique_id": "vf1aaaaa555777123_charging_remaining_time", - "result": "145", + ATTR_ENTITY_ID: "sensor.reg_number_charging_remaining_time", ATTR_ICON: "mdi:timer", + ATTR_STATE: "145", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777123_charging_remaining_time", ATTR_UNIT_OF_MEASUREMENT: TIME_MINUTES, }, { - "entity_id": "sensor.reg_number_fuel_autonomy", - "unique_id": "vf1aaaaa555777123_fuel_autonomy", - "result": "35", + ATTR_ENTITY_ID: "sensor.reg_number_fuel_autonomy", ATTR_ICON: "mdi:gas-station", + ATTR_STATE: "35", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777123_fuel_autonomy", ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, }, { - "entity_id": "sensor.reg_number_fuel_quantity", - "unique_id": "vf1aaaaa555777123_fuel_quantity", - "result": "3", + ATTR_ENTITY_ID: "sensor.reg_number_fuel_quantity", ATTR_ICON: "mdi:fuel", + ATTR_STATE: "3", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777123_fuel_quantity", ATTR_UNIT_OF_MEASUREMENT: VOLUME_LITERS, }, { - "entity_id": "sensor.reg_number_mileage", - "unique_id": "vf1aaaaa555777123_mileage", - "result": "5567", + ATTR_ENTITY_ID: "sensor.reg_number_mileage", ATTR_ICON: "mdi:sign-direction", + ATTR_STATE: "5567", ATTR_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING, + ATTR_UNIQUE_ID: "vf1aaaaa555777123_mileage", ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, }, { - "entity_id": "sensor.reg_number_plug_state", - "unique_id": "vf1aaaaa555777123_plug_state", - "result": "plugged", ATTR_DEVICE_CLASS: DEVICE_CLASS_PLUG_STATE, + ATTR_ENTITY_ID: "sensor.reg_number_plug_state", ATTR_ICON: "mdi:power-plug", + ATTR_STATE: "plugged", + ATTR_UNIQUE_ID: "vf1aaaaa555777123_plug_state", }, { - "entity_id": "sensor.reg_number_location_last_activity", - "unique_id": "vf1aaaaa555777123_location_last_activity", - "result": "2020-02-18T16:58:38+00:00", - "default_disabled": True, + ATTR_DEFAULT_DISABLED: True, ATTR_DEVICE_CLASS: DEVICE_CLASS_TIMESTAMP, + ATTR_ENTITY_ID: "sensor.reg_number_location_last_activity", + ATTR_STATE: "2020-02-18T16:58:38+00:00", + ATTR_UNIQUE_ID: "vf1aaaaa555777123_location_last_activity", }, ], }, "captur_fuel": { "expected_device": { - "identifiers": {(DOMAIN, "VF1AAAAA555777123")}, - "manufacturer": "Renault", - "model": "Captur ii", - "name": "REG-NUMBER", - "sw_version": "XJB1SU", + ATTR_IDENTIFIERS: {(DOMAIN, "VF1AAAAA555777123")}, + ATTR_MANUFACTURER: "Renault", + ATTR_MODEL: "Captur ii", + ATTR_NAME: "REG-NUMBER", + ATTR_SW_VERSION: "XJB1SU", }, "endpoints_available": [ True, # cockpit @@ -524,44 +534,44 @@ MOCK_VEHICLES = { BINARY_SENSOR_DOMAIN: [], DEVICE_TRACKER_DOMAIN: [ { - "entity_id": "device_tracker.reg_number_location", - "unique_id": "vf1aaaaa555777123_location", - "result": STATE_NOT_HOME, + ATTR_ENTITY_ID: "device_tracker.reg_number_location", ATTR_ICON: "mdi:car", + ATTR_STATE: STATE_NOT_HOME, + ATTR_UNIQUE_ID: "vf1aaaaa555777123_location", } ], SELECT_DOMAIN: [], SENSOR_DOMAIN: [ { - "entity_id": "sensor.reg_number_fuel_autonomy", - "unique_id": "vf1aaaaa555777123_fuel_autonomy", - "result": "35", + ATTR_ENTITY_ID: "sensor.reg_number_fuel_autonomy", ATTR_ICON: "mdi:gas-station", + ATTR_STATE: "35", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777123_fuel_autonomy", ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, }, { - "entity_id": "sensor.reg_number_fuel_quantity", - "unique_id": "vf1aaaaa555777123_fuel_quantity", - "result": "3", + ATTR_ENTITY_ID: "sensor.reg_number_fuel_quantity", ATTR_ICON: "mdi:fuel", + ATTR_STATE: "3", ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, + ATTR_UNIQUE_ID: "vf1aaaaa555777123_fuel_quantity", ATTR_UNIT_OF_MEASUREMENT: VOLUME_LITERS, }, { - "entity_id": "sensor.reg_number_mileage", - "unique_id": "vf1aaaaa555777123_mileage", - "result": "5567", + ATTR_ENTITY_ID: "sensor.reg_number_mileage", ATTR_ICON: "mdi:sign-direction", + ATTR_STATE: "5567", ATTR_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING, + ATTR_UNIQUE_ID: "vf1aaaaa555777123_mileage", ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, }, { - "entity_id": "sensor.reg_number_location_last_activity", - "unique_id": "vf1aaaaa555777123_location_last_activity", - "result": "2020-02-18T16:58:38+00:00", - "default_disabled": True, + ATTR_DEFAULT_DISABLED: True, ATTR_DEVICE_CLASS: DEVICE_CLASS_TIMESTAMP, + ATTR_ENTITY_ID: "sensor.reg_number_location_last_activity", + ATTR_STATE: "2020-02-18T16:58:38+00:00", + ATTR_UNIQUE_ID: "vf1aaaaa555777123_location_last_activity", }, ], }, diff --git a/tests/components/renault/test_sensor.py b/tests/components/renault/test_sensor.py index 9e83a131aa8..c9a70c8e026 100644 --- a/tests/components/renault/test_sensor.py +++ b/tests/components/renault/test_sensor.py @@ -6,7 +6,7 @@ import pytest from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.config_entries import ConfigEntry -from homeassistant.const import STATE_UNKNOWN +from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_registry import EntityRegistry @@ -16,7 +16,7 @@ from . import ( check_entities_no_data, check_entities_unavailable, ) -from .const import MOCK_VEHICLES +from .const import ATTR_DEFAULT_DISABLED, MOCK_VEHICLES from tests.common import mock_device_registry, mock_registry @@ -35,8 +35,8 @@ def _check_and_enable_disabled_entities( ) -> None: """Ensure that the expected_entities are correctly disabled.""" for expected_entity in expected_entities: - if expected_entity.get("default_disabled"): - entity_id = expected_entity["entity_id"] + if expected_entity.get(ATTR_DEFAULT_DISABLED): + entity_id = expected_entity[ATTR_ENTITY_ID] registry_entry = entity_registry.entities.get(entity_id) assert registry_entry.disabled assert registry_entry.disabled_by == "integration"