Use constants in renault tests (#58406)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-10-25 15:42:01 +02:00 committed by GitHub
parent 71230f1f1c
commit 29c95a0b34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 209 additions and 192 deletions

View File

@ -4,11 +4,13 @@ from __future__ import annotations
from types import MappingProxyType from types import MappingProxyType
from homeassistant.const import ( from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_ICON, ATTR_ICON,
ATTR_IDENTIFIERS, ATTR_IDENTIFIERS,
ATTR_MANUFACTURER, ATTR_MANUFACTURER,
ATTR_MODEL, ATTR_MODEL,
ATTR_NAME, ATTR_NAME,
ATTR_STATE,
ATTR_SW_VERSION, ATTR_SW_VERSION,
STATE_UNAVAILABLE, STATE_UNAVAILABLE,
) )
@ -16,12 +18,17 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceRegistry from homeassistant.helpers.device_registry import DeviceRegistry
from homeassistant.helpers.entity_registry import EntityRegistry 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): def get_no_data_icon(expected_entity: MappingProxyType):
"""Check icon attribute for inactive sensors.""" """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)) return ICON_FOR_EMPTY_VALUES.get(entity_id, expected_entity.get(ATTR_ICON))
@ -46,12 +53,12 @@ def check_entities(
) -> None: ) -> None:
"""Ensure that the expected_entities are correct.""" """Ensure that the expected_entities are correct."""
for expected_entity in expected_entities: 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) registry_entry = entity_registry.entities.get(entity_id)
assert registry_entry is not None 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) 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: for attr in FIXED_ATTRIBUTES + DYNAMIC_ATTRIBUTES:
assert state.attributes.get(attr) == expected_entity.get(attr) assert state.attributes.get(attr) == expected_entity.get(attr)
@ -64,10 +71,10 @@ def check_entities_no_data(
) -> None: ) -> None:
"""Ensure that the expected_entities are correct.""" """Ensure that the expected_entities are correct."""
for expected_entity in expected_entities: 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) registry_entry = entity_registry.entities.get(entity_id)
assert registry_entry is not None 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) state = hass.states.get(entity_id)
assert state.state == expected_state assert state.state == expected_state
for attr in FIXED_ATTRIBUTES: for attr in FIXED_ATTRIBUTES:
@ -83,10 +90,10 @@ def check_entities_unavailable(
) -> None: ) -> None:
"""Ensure that the expected_entities are correct.""" """Ensure that the expected_entities are correct."""
for expected_entity in expected_entities: 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) registry_entry = entity_registry.entities.get(entity_id)
assert registry_entry is not None 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) state = hass.states.get(entity_id)
assert state.state == STATE_UNAVAILABLE assert state.state == STATE_UNAVAILABLE
for attr in FIXED_ATTRIBUTES: for attr in FIXED_ATTRIBUTES:

View File

@ -23,7 +23,14 @@ from homeassistant.components.sensor import (
) )
from homeassistant.const import ( from homeassistant.const import (
ATTR_DEVICE_CLASS, ATTR_DEVICE_CLASS,
ATTR_ENTITY_ID,
ATTR_ICON, ATTR_ICON,
ATTR_IDENTIFIERS,
ATTR_MANUFACTURER,
ATTR_MODEL,
ATTR_NAME,
ATTR_STATE,
ATTR_SW_VERSION,
ATTR_UNIT_OF_MEASUREMENT, ATTR_UNIT_OF_MEASUREMENT,
CONF_PASSWORD, CONF_PASSWORD,
CONF_USERNAME, CONF_USERNAME,
@ -47,6 +54,9 @@ from homeassistant.const import (
VOLUME_LITERS, VOLUME_LITERS,
) )
ATTR_DEFAULT_DISABLED = "default_disabled"
ATTR_UNIQUE_ID = "unique_id"
FIXED_ATTRIBUTES = ( FIXED_ATTRIBUTES = (
ATTR_DEVICE_CLASS, ATTR_DEVICE_CLASS,
ATTR_OPTIONS, ATTR_OPTIONS,
@ -74,11 +84,11 @@ MOCK_CONFIG = {
MOCK_VEHICLES = { MOCK_VEHICLES = {
"zoe_40": { "zoe_40": {
"expected_device": { "expected_device": {
"identifiers": {(DOMAIN, "VF1AAAAA555777999")}, ATTR_IDENTIFIERS: {(DOMAIN, "VF1AAAAA555777999")},
"manufacturer": "Renault", ATTR_MANUFACTURER: "Renault",
"model": "Zoe", ATTR_MODEL: "Zoe",
"name": "REG-NUMBER", ATTR_NAME: "REG-NUMBER",
"sw_version": "X101VE", ATTR_SW_VERSION: "X101VE",
}, },
"endpoints_available": [ "endpoints_available": [
True, # cockpit True, # cockpit
@ -95,124 +105,124 @@ MOCK_VEHICLES = {
}, },
BINARY_SENSOR_DOMAIN: [ 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_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_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: [], DEVICE_TRACKER_DOMAIN: [],
SELECT_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_DEVICE_CLASS: DEVICE_CLASS_CHARGE_MODE,
ATTR_ENTITY_ID: "select.reg_number_charge_mode",
ATTR_ICON: "mdi:calendar-remove", ATTR_ICON: "mdi:calendar-remove",
ATTR_OPTIONS: ["always", "always_charging", "schedule_mode"], ATTR_OPTIONS: ["always", "always_charging", "schedule_mode"],
ATTR_STATE: "always",
ATTR_UNIQUE_ID: "vf1aaaaa555777999_charge_mode",
}, },
], ],
SENSOR_DOMAIN: [ SENSOR_DOMAIN: [
{ {
"entity_id": "sensor.reg_number_battery_autonomy", ATTR_ENTITY_ID: "sensor.reg_number_battery_autonomy",
"unique_id": "vf1aaaaa555777999_battery_autonomy",
"result": "141",
ATTR_ICON: "mdi:ev-station", ATTR_ICON: "mdi:ev-station",
ATTR_STATE: "141",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_autonomy",
ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, 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_DEVICE_CLASS: DEVICE_CLASS_ENERGY,
ATTR_ENTITY_ID: "sensor.reg_number_battery_available_energy",
ATTR_STATE: "31",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_available_energy",
ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR, 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_DEVICE_CLASS: DEVICE_CLASS_BATTERY,
ATTR_ENTITY_ID: "sensor.reg_number_battery_level",
ATTR_STATE: "60",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_level",
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE, ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
}, },
{ {
"entity_id": "sensor.reg_number_battery_last_activity", ATTR_DEFAULT_DISABLED: True,
"unique_id": "vf1aaaaa555777999_battery_last_activity",
"result": "2020-01-12T21:40:16+00:00",
"default_disabled": True,
ATTR_DEVICE_CLASS: DEVICE_CLASS_TIMESTAMP, 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_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
ATTR_ENTITY_ID: "sensor.reg_number_battery_temperature",
ATTR_STATE: "20",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_temperature",
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS, 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_DEVICE_CLASS: DEVICE_CLASS_CHARGE_STATE,
ATTR_ENTITY_ID: "sensor.reg_number_charge_state",
ATTR_ICON: "mdi:flash", 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_DEVICE_CLASS: DEVICE_CLASS_POWER,
ATTR_ENTITY_ID: "sensor.reg_number_charging_power",
ATTR_STATE: "0.027",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging_power",
ATTR_UNIT_OF_MEASUREMENT: POWER_KILO_WATT, ATTR_UNIT_OF_MEASUREMENT: POWER_KILO_WATT,
}, },
{ {
"entity_id": "sensor.reg_number_charging_remaining_time", ATTR_ENTITY_ID: "sensor.reg_number_charging_remaining_time",
"unique_id": "vf1aaaaa555777999_charging_remaining_time",
"result": "145",
ATTR_ICON: "mdi:timer", ATTR_ICON: "mdi:timer",
ATTR_STATE: "145",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging_remaining_time",
ATTR_UNIT_OF_MEASUREMENT: TIME_MINUTES, ATTR_UNIT_OF_MEASUREMENT: TIME_MINUTES,
}, },
{ {
"entity_id": "sensor.reg_number_mileage", ATTR_ENTITY_ID: "sensor.reg_number_mileage",
"unique_id": "vf1aaaaa555777999_mileage",
"result": "49114",
ATTR_ICON: "mdi:sign-direction", ATTR_ICON: "mdi:sign-direction",
ATTR_STATE: "49114",
ATTR_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING, ATTR_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_mileage",
ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, 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_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
ATTR_ENTITY_ID: "sensor.reg_number_outside_temperature",
ATTR_STATE: "8.0",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_outside_temperature",
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS, 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_DEVICE_CLASS: DEVICE_CLASS_PLUG_STATE,
ATTR_ENTITY_ID: "sensor.reg_number_plug_state",
ATTR_ICON: "mdi:power-plug", ATTR_ICON: "mdi:power-plug",
ATTR_STATE: "plugged",
ATTR_UNIQUE_ID: "vf1aaaaa555777999_plug_state",
}, },
], ],
}, },
"zoe_50": { "zoe_50": {
"expected_device": { "expected_device": {
"identifiers": {(DOMAIN, "VF1AAAAA555777999")}, ATTR_IDENTIFIERS: {(DOMAIN, "VF1AAAAA555777999")},
"manufacturer": "Renault", ATTR_MANUFACTURER: "Renault",
"model": "Zoe", ATTR_MODEL: "Zoe",
"name": "REG-NUMBER", ATTR_NAME: "REG-NUMBER",
"sw_version": "X102VE", ATTR_SW_VERSION: "X102VE",
}, },
"endpoints_available": [ "endpoints_available": [
True, # cockpit True, # cockpit
@ -229,130 +239,130 @@ MOCK_VEHICLES = {
}, },
BINARY_SENSOR_DOMAIN: [ 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_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_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: [ DEVICE_TRACKER_DOMAIN: [
{ {
"entity_id": "device_tracker.reg_number_location", ATTR_ENTITY_ID: "device_tracker.reg_number_location",
"unique_id": "vf1aaaaa555777999_location",
"result": STATE_NOT_HOME,
ATTR_ICON: "mdi:car", ATTR_ICON: "mdi:car",
ATTR_STATE: STATE_NOT_HOME,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_location",
} }
], ],
SELECT_DOMAIN: [ 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_DEVICE_CLASS: DEVICE_CLASS_CHARGE_MODE,
ATTR_ENTITY_ID: "select.reg_number_charge_mode",
ATTR_ICON: "mdi:calendar-clock", ATTR_ICON: "mdi:calendar-clock",
ATTR_OPTIONS: ["always", "always_charging", "schedule_mode"], ATTR_OPTIONS: ["always", "always_charging", "schedule_mode"],
ATTR_STATE: "schedule_mode",
ATTR_UNIQUE_ID: "vf1aaaaa555777999_charge_mode",
}, },
], ],
SENSOR_DOMAIN: [ SENSOR_DOMAIN: [
{ {
"entity_id": "sensor.reg_number_battery_autonomy", ATTR_ENTITY_ID: "sensor.reg_number_battery_autonomy",
"unique_id": "vf1aaaaa555777999_battery_autonomy",
"result": "128",
ATTR_ICON: "mdi:ev-station", ATTR_ICON: "mdi:ev-station",
ATTR_STATE: "128",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_autonomy",
ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, 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_DEVICE_CLASS: DEVICE_CLASS_ENERGY,
ATTR_ENTITY_ID: "sensor.reg_number_battery_available_energy",
ATTR_STATE: "0",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_available_energy",
ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR, 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_DEVICE_CLASS: DEVICE_CLASS_BATTERY,
ATTR_ENTITY_ID: "sensor.reg_number_battery_level",
ATTR_STATE: "50",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_level",
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE, ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
}, },
{ {
"entity_id": "sensor.reg_number_battery_last_activity", ATTR_DEFAULT_DISABLED: True,
"unique_id": "vf1aaaaa555777999_battery_last_activity",
"result": "2020-11-17T08:06:48+00:00",
"default_disabled": True,
ATTR_DEVICE_CLASS: DEVICE_CLASS_TIMESTAMP, 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_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
ATTR_ENTITY_ID: "sensor.reg_number_battery_temperature",
ATTR_STATE: STATE_UNKNOWN,
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_temperature",
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS, 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_DEVICE_CLASS: DEVICE_CLASS_CHARGE_STATE,
ATTR_ENTITY_ID: "sensor.reg_number_charge_state",
ATTR_ICON: "mdi:flash-off", 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_DEVICE_CLASS: DEVICE_CLASS_CURRENT,
ATTR_ENTITY_ID: "sensor.reg_number_charging_power",
ATTR_STATE: STATE_UNKNOWN,
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging_power",
ATTR_UNIT_OF_MEASUREMENT: ELECTRIC_CURRENT_AMPERE, ATTR_UNIT_OF_MEASUREMENT: ELECTRIC_CURRENT_AMPERE,
}, },
{ {
"entity_id": "sensor.reg_number_charging_remaining_time", ATTR_ENTITY_ID: "sensor.reg_number_charging_remaining_time",
"unique_id": "vf1aaaaa555777999_charging_remaining_time",
"result": STATE_UNKNOWN,
ATTR_ICON: "mdi:timer", ATTR_ICON: "mdi:timer",
ATTR_STATE: STATE_UNKNOWN,
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging_remaining_time",
ATTR_UNIT_OF_MEASUREMENT: TIME_MINUTES, ATTR_UNIT_OF_MEASUREMENT: TIME_MINUTES,
}, },
{ {
"entity_id": "sensor.reg_number_mileage", ATTR_ENTITY_ID: "sensor.reg_number_mileage",
"unique_id": "vf1aaaaa555777999_mileage",
"result": "49114",
ATTR_ICON: "mdi:sign-direction", ATTR_ICON: "mdi:sign-direction",
ATTR_STATE: "49114",
ATTR_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING, ATTR_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_mileage",
ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, 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_DEVICE_CLASS: DEVICE_CLASS_PLUG_STATE,
ATTR_ENTITY_ID: "sensor.reg_number_plug_state",
ATTR_ICON: "mdi:power-plug-off", ATTR_ICON: "mdi:power-plug-off",
ATTR_STATE: "unplugged",
ATTR_UNIQUE_ID: "vf1aaaaa555777999_plug_state",
}, },
{ {
"entity_id": "sensor.reg_number_location_last_activity", ATTR_DEFAULT_DISABLED: True,
"unique_id": "vf1aaaaa555777999_location_last_activity",
"result": "2020-02-18T16:58:38+00:00",
"default_disabled": True,
ATTR_DEVICE_CLASS: DEVICE_CLASS_TIMESTAMP, 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": { "captur_phev": {
"expected_device": { "expected_device": {
"identifiers": {(DOMAIN, "VF1AAAAA555777123")}, ATTR_IDENTIFIERS: {(DOMAIN, "VF1AAAAA555777123")},
"manufacturer": "Renault", ATTR_MANUFACTURER: "Renault",
"model": "Captur ii", ATTR_MODEL: "Captur ii",
"name": "REG-NUMBER", ATTR_NAME: "REG-NUMBER",
"sw_version": "XJB1SU", ATTR_SW_VERSION: "XJB1SU",
}, },
"endpoints_available": [ "endpoints_available": [
True, # cockpit True, # cockpit
@ -369,146 +379,146 @@ MOCK_VEHICLES = {
}, },
BINARY_SENSOR_DOMAIN: [ 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_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_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: [ DEVICE_TRACKER_DOMAIN: [
{ {
"entity_id": "device_tracker.reg_number_location", ATTR_ENTITY_ID: "device_tracker.reg_number_location",
"unique_id": "vf1aaaaa555777123_location",
"result": STATE_NOT_HOME,
ATTR_ICON: "mdi:car", ATTR_ICON: "mdi:car",
ATTR_STATE: STATE_NOT_HOME,
ATTR_UNIQUE_ID: "vf1aaaaa555777123_location",
} }
], ],
SELECT_DOMAIN: [ SELECT_DOMAIN: [
{ {
"entity_id": "select.reg_number_charge_mode",
"unique_id": "vf1aaaaa555777123_charge_mode",
"result": "always",
ATTR_DEVICE_CLASS: DEVICE_CLASS_CHARGE_MODE, ATTR_DEVICE_CLASS: DEVICE_CLASS_CHARGE_MODE,
ATTR_ENTITY_ID: "select.reg_number_charge_mode",
ATTR_ICON: "mdi:calendar-remove", ATTR_ICON: "mdi:calendar-remove",
ATTR_OPTIONS: ["always", "always_charging", "schedule_mode"], ATTR_OPTIONS: ["always", "always_charging", "schedule_mode"],
ATTR_STATE: "always",
ATTR_UNIQUE_ID: "vf1aaaaa555777123_charge_mode",
}, },
], ],
SENSOR_DOMAIN: [ SENSOR_DOMAIN: [
{ {
"entity_id": "sensor.reg_number_battery_autonomy", ATTR_ENTITY_ID: "sensor.reg_number_battery_autonomy",
"unique_id": "vf1aaaaa555777123_battery_autonomy",
"result": "141",
ATTR_ICON: "mdi:ev-station", ATTR_ICON: "mdi:ev-station",
ATTR_STATE: "141",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777123_battery_autonomy",
ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, 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_DEVICE_CLASS: DEVICE_CLASS_ENERGY,
ATTR_ENTITY_ID: "sensor.reg_number_battery_available_energy",
ATTR_STATE: "31",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777123_battery_available_energy",
ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR, 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_DEVICE_CLASS: DEVICE_CLASS_BATTERY,
ATTR_ENTITY_ID: "sensor.reg_number_battery_level",
ATTR_STATE: "60",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777123_battery_level",
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE, ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
}, },
{ {
"entity_id": "sensor.reg_number_battery_last_activity", ATTR_DEFAULT_DISABLED: True,
"unique_id": "vf1aaaaa555777123_battery_last_activity",
"result": "2020-01-12T21:40:16+00:00",
"default_disabled": True,
ATTR_DEVICE_CLASS: DEVICE_CLASS_TIMESTAMP, 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_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
ATTR_ENTITY_ID: "sensor.reg_number_battery_temperature",
ATTR_STATE: "20",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777123_battery_temperature",
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS, 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_DEVICE_CLASS: DEVICE_CLASS_CHARGE_STATE,
ATTR_ENTITY_ID: "sensor.reg_number_charge_state",
ATTR_ICON: "mdi:flash", 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_DEVICE_CLASS: DEVICE_CLASS_CURRENT,
ATTR_ENTITY_ID: "sensor.reg_number_charging_power",
ATTR_STATE: "27.0",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777123_charging_power",
ATTR_UNIT_OF_MEASUREMENT: ELECTRIC_CURRENT_AMPERE, ATTR_UNIT_OF_MEASUREMENT: ELECTRIC_CURRENT_AMPERE,
}, },
{ {
"entity_id": "sensor.reg_number_charging_remaining_time", ATTR_ENTITY_ID: "sensor.reg_number_charging_remaining_time",
"unique_id": "vf1aaaaa555777123_charging_remaining_time",
"result": "145",
ATTR_ICON: "mdi:timer", ATTR_ICON: "mdi:timer",
ATTR_STATE: "145",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777123_charging_remaining_time",
ATTR_UNIT_OF_MEASUREMENT: TIME_MINUTES, ATTR_UNIT_OF_MEASUREMENT: TIME_MINUTES,
}, },
{ {
"entity_id": "sensor.reg_number_fuel_autonomy", ATTR_ENTITY_ID: "sensor.reg_number_fuel_autonomy",
"unique_id": "vf1aaaaa555777123_fuel_autonomy",
"result": "35",
ATTR_ICON: "mdi:gas-station", ATTR_ICON: "mdi:gas-station",
ATTR_STATE: "35",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777123_fuel_autonomy",
ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS,
}, },
{ {
"entity_id": "sensor.reg_number_fuel_quantity", ATTR_ENTITY_ID: "sensor.reg_number_fuel_quantity",
"unique_id": "vf1aaaaa555777123_fuel_quantity",
"result": "3",
ATTR_ICON: "mdi:fuel", ATTR_ICON: "mdi:fuel",
ATTR_STATE: "3",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777123_fuel_quantity",
ATTR_UNIT_OF_MEASUREMENT: VOLUME_LITERS, ATTR_UNIT_OF_MEASUREMENT: VOLUME_LITERS,
}, },
{ {
"entity_id": "sensor.reg_number_mileage", ATTR_ENTITY_ID: "sensor.reg_number_mileage",
"unique_id": "vf1aaaaa555777123_mileage",
"result": "5567",
ATTR_ICON: "mdi:sign-direction", ATTR_ICON: "mdi:sign-direction",
ATTR_STATE: "5567",
ATTR_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING, ATTR_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING,
ATTR_UNIQUE_ID: "vf1aaaaa555777123_mileage",
ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, 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_DEVICE_CLASS: DEVICE_CLASS_PLUG_STATE,
ATTR_ENTITY_ID: "sensor.reg_number_plug_state",
ATTR_ICON: "mdi:power-plug", ATTR_ICON: "mdi:power-plug",
ATTR_STATE: "plugged",
ATTR_UNIQUE_ID: "vf1aaaaa555777123_plug_state",
}, },
{ {
"entity_id": "sensor.reg_number_location_last_activity", ATTR_DEFAULT_DISABLED: True,
"unique_id": "vf1aaaaa555777123_location_last_activity",
"result": "2020-02-18T16:58:38+00:00",
"default_disabled": True,
ATTR_DEVICE_CLASS: DEVICE_CLASS_TIMESTAMP, 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": { "captur_fuel": {
"expected_device": { "expected_device": {
"identifiers": {(DOMAIN, "VF1AAAAA555777123")}, ATTR_IDENTIFIERS: {(DOMAIN, "VF1AAAAA555777123")},
"manufacturer": "Renault", ATTR_MANUFACTURER: "Renault",
"model": "Captur ii", ATTR_MODEL: "Captur ii",
"name": "REG-NUMBER", ATTR_NAME: "REG-NUMBER",
"sw_version": "XJB1SU", ATTR_SW_VERSION: "XJB1SU",
}, },
"endpoints_available": [ "endpoints_available": [
True, # cockpit True, # cockpit
@ -524,44 +534,44 @@ MOCK_VEHICLES = {
BINARY_SENSOR_DOMAIN: [], BINARY_SENSOR_DOMAIN: [],
DEVICE_TRACKER_DOMAIN: [ DEVICE_TRACKER_DOMAIN: [
{ {
"entity_id": "device_tracker.reg_number_location", ATTR_ENTITY_ID: "device_tracker.reg_number_location",
"unique_id": "vf1aaaaa555777123_location",
"result": STATE_NOT_HOME,
ATTR_ICON: "mdi:car", ATTR_ICON: "mdi:car",
ATTR_STATE: STATE_NOT_HOME,
ATTR_UNIQUE_ID: "vf1aaaaa555777123_location",
} }
], ],
SELECT_DOMAIN: [], SELECT_DOMAIN: [],
SENSOR_DOMAIN: [ SENSOR_DOMAIN: [
{ {
"entity_id": "sensor.reg_number_fuel_autonomy", ATTR_ENTITY_ID: "sensor.reg_number_fuel_autonomy",
"unique_id": "vf1aaaaa555777123_fuel_autonomy",
"result": "35",
ATTR_ICON: "mdi:gas-station", ATTR_ICON: "mdi:gas-station",
ATTR_STATE: "35",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777123_fuel_autonomy",
ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS,
}, },
{ {
"entity_id": "sensor.reg_number_fuel_quantity", ATTR_ENTITY_ID: "sensor.reg_number_fuel_quantity",
"unique_id": "vf1aaaaa555777123_fuel_quantity",
"result": "3",
ATTR_ICON: "mdi:fuel", ATTR_ICON: "mdi:fuel",
ATTR_STATE: "3",
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT, ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777123_fuel_quantity",
ATTR_UNIT_OF_MEASUREMENT: VOLUME_LITERS, ATTR_UNIT_OF_MEASUREMENT: VOLUME_LITERS,
}, },
{ {
"entity_id": "sensor.reg_number_mileage", ATTR_ENTITY_ID: "sensor.reg_number_mileage",
"unique_id": "vf1aaaaa555777123_mileage",
"result": "5567",
ATTR_ICON: "mdi:sign-direction", ATTR_ICON: "mdi:sign-direction",
ATTR_STATE: "5567",
ATTR_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING, ATTR_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING,
ATTR_UNIQUE_ID: "vf1aaaaa555777123_mileage",
ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS, ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS,
}, },
{ {
"entity_id": "sensor.reg_number_location_last_activity", ATTR_DEFAULT_DISABLED: True,
"unique_id": "vf1aaaaa555777123_location_last_activity",
"result": "2020-02-18T16:58:38+00:00",
"default_disabled": True,
ATTR_DEVICE_CLASS: DEVICE_CLASS_TIMESTAMP, 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",
}, },
], ],
}, },

View File

@ -6,7 +6,7 @@ import pytest
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.config_entries import ConfigEntry 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.core import HomeAssistant
from homeassistant.helpers.entity_registry import EntityRegistry from homeassistant.helpers.entity_registry import EntityRegistry
@ -16,7 +16,7 @@ from . import (
check_entities_no_data, check_entities_no_data,
check_entities_unavailable, 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 from tests.common import mock_device_registry, mock_registry
@ -35,8 +35,8 @@ def _check_and_enable_disabled_entities(
) -> None: ) -> None:
"""Ensure that the expected_entities are correctly disabled.""" """Ensure that the expected_entities are correctly disabled."""
for expected_entity in expected_entities: for expected_entity in expected_entities:
if expected_entity.get("default_disabled"): if expected_entity.get(ATTR_DEFAULT_DISABLED):
entity_id = expected_entity["entity_id"] entity_id = expected_entity[ATTR_ENTITY_ID]
registry_entry = entity_registry.entities.get(entity_id) registry_entry = entity_registry.entities.get(entity_id)
assert registry_entry.disabled assert registry_entry.disabled
assert registry_entry.disabled_by == "integration" assert registry_entry.disabled_by == "integration"