mirror of
https://github.com/home-assistant/core.git
synced 2026-09-28 02:18:10 -04:00
Refactor Renault to use StrEnum (#172546)
This commit is contained in:
@@ -1,22 +1,17 @@
|
||||
"""Constants for the Renault integration tests."""
|
||||
|
||||
from homeassistant.components.renault.const import (
|
||||
CONF_KAMEREON_ACCOUNT_ID,
|
||||
CONF_LOCALE,
|
||||
CONF_LOGIN_TOKEN,
|
||||
)
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.components.renault.const import RenaultConfigurationKeys
|
||||
|
||||
MOCK_ACCOUNT_ID = "account_id_1"
|
||||
MOCK_LOGIN_TOKEN = "sample-login-token"
|
||||
|
||||
# Mock config data to be used across multiple tests
|
||||
MOCK_CONFIG = {
|
||||
CONF_USERNAME: "email@test.com",
|
||||
CONF_PASSWORD: "test",
|
||||
CONF_LOGIN_TOKEN: MOCK_LOGIN_TOKEN,
|
||||
CONF_KAMEREON_ACCOUNT_ID: MOCK_ACCOUNT_ID,
|
||||
CONF_LOCALE: "fr_FR",
|
||||
RenaultConfigurationKeys.USERNAME: "email@test.com",
|
||||
RenaultConfigurationKeys.PASSWORD: "test",
|
||||
RenaultConfigurationKeys.LOGIN_TOKEN: MOCK_LOGIN_TOKEN,
|
||||
RenaultConfigurationKeys.KAMEREON_ACCOUNT_ID: MOCK_ACCOUNT_ID,
|
||||
RenaultConfigurationKeys.LOCALE: "fr_FR",
|
||||
}
|
||||
|
||||
MOCK_VEHICLES = {
|
||||
|
||||
@@ -10,13 +10,7 @@ from renault_api.renault_account import RenaultAccount
|
||||
from renault_api.renault_session import RenaultSession
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.renault.const import (
|
||||
CONF_KAMEREON_ACCOUNT_ID,
|
||||
CONF_LOCALE,
|
||||
CONF_LOGIN_TOKEN,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.const import CONF_NAME, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.components.renault.const import DOMAIN, RenaultConfigurationKeys
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.helpers import aiohttp_client
|
||||
@@ -66,9 +60,9 @@ async def test_config_flow_single_account(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_LOCALE: "fr_FR",
|
||||
CONF_USERNAME: "email@test.com",
|
||||
CONF_PASSWORD: "test",
|
||||
RenaultConfigurationKeys.LOCALE: "fr_FR",
|
||||
RenaultConfigurationKeys.USERNAME: "email@test.com",
|
||||
RenaultConfigurationKeys.PASSWORD: "test",
|
||||
},
|
||||
)
|
||||
|
||||
@@ -77,9 +71,18 @@ async def test_config_flow_single_account(
|
||||
assert result["errors"] == {"base": error}
|
||||
|
||||
data_schema = result["data_schema"].schema
|
||||
assert get_schema_suggested_value(data_schema, CONF_LOCALE) == "fr_FR"
|
||||
assert get_schema_suggested_value(data_schema, CONF_USERNAME) == "email@test.com"
|
||||
assert get_schema_suggested_value(data_schema, CONF_PASSWORD) == "test"
|
||||
assert (
|
||||
get_schema_suggested_value(data_schema, RenaultConfigurationKeys.LOCALE)
|
||||
== "fr_FR"
|
||||
)
|
||||
assert (
|
||||
get_schema_suggested_value(data_schema, RenaultConfigurationKeys.USERNAME)
|
||||
== "email@test.com"
|
||||
)
|
||||
assert (
|
||||
get_schema_suggested_value(data_schema, RenaultConfigurationKeys.PASSWORD)
|
||||
== "test"
|
||||
)
|
||||
|
||||
renault_account = AsyncMock()
|
||||
type(renault_account).account_id = PropertyMock(return_value="account_id_1")
|
||||
@@ -104,19 +107,21 @@ async def test_config_flow_single_account(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_LOCALE: "fr_FR",
|
||||
CONF_USERNAME: "email@test.com",
|
||||
CONF_PASSWORD: "test",
|
||||
RenaultConfigurationKeys.LOCALE: "fr_FR",
|
||||
RenaultConfigurationKeys.USERNAME: "email@test.com",
|
||||
RenaultConfigurationKeys.PASSWORD: "test",
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "account_id_1"
|
||||
assert result["data"][CONF_USERNAME] == "email@test.com"
|
||||
assert result["data"][CONF_PASSWORD] == "test"
|
||||
assert result["data"][CONF_LOGIN_TOKEN] == MOCK_LOGIN_TOKEN
|
||||
assert result["data"][CONF_KAMEREON_ACCOUNT_ID] == "account_id_1"
|
||||
assert result["data"][CONF_LOCALE] == "fr_FR"
|
||||
assert result["data"][RenaultConfigurationKeys.USERNAME] == "email@test.com"
|
||||
assert result["data"][RenaultConfigurationKeys.PASSWORD] == "test"
|
||||
assert result["data"][RenaultConfigurationKeys.LOGIN_TOKEN] == MOCK_LOGIN_TOKEN
|
||||
assert (
|
||||
result["data"][RenaultConfigurationKeys.KAMEREON_ACCOUNT_ID] == "account_id_1"
|
||||
)
|
||||
assert result["data"][RenaultConfigurationKeys.LOCALE] == "fr_FR"
|
||||
assert result["context"]["unique_id"] == "account_id_1"
|
||||
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
@@ -147,9 +152,9 @@ async def test_config_flow_no_account(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_LOCALE: "fr_FR",
|
||||
CONF_USERNAME: "email@test.com",
|
||||
CONF_PASSWORD: "test",
|
||||
RenaultConfigurationKeys.LOCALE: "fr_FR",
|
||||
RenaultConfigurationKeys.USERNAME: "email@test.com",
|
||||
RenaultConfigurationKeys.PASSWORD: "test",
|
||||
},
|
||||
)
|
||||
|
||||
@@ -200,9 +205,9 @@ async def test_config_flow_multiple_accounts(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_LOCALE: "fr_FR",
|
||||
CONF_USERNAME: "email@test.com",
|
||||
CONF_PASSWORD: "test",
|
||||
RenaultConfigurationKeys.LOCALE: "fr_FR",
|
||||
RenaultConfigurationKeys.USERNAME: "email@test.com",
|
||||
RenaultConfigurationKeys.PASSWORD: "test",
|
||||
},
|
||||
)
|
||||
|
||||
@@ -212,15 +217,17 @@ async def test_config_flow_multiple_accounts(
|
||||
# Account selected
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_KAMEREON_ACCOUNT_ID: "account_id_2"},
|
||||
user_input={RenaultConfigurationKeys.KAMEREON_ACCOUNT_ID: "account_id_2"},
|
||||
)
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "account_id_2"
|
||||
assert result["data"][CONF_USERNAME] == "email@test.com"
|
||||
assert result["data"][CONF_PASSWORD] == "test"
|
||||
assert result["data"][CONF_LOGIN_TOKEN] == MOCK_LOGIN_TOKEN
|
||||
assert result["data"][CONF_KAMEREON_ACCOUNT_ID] == "account_id_2"
|
||||
assert result["data"][CONF_LOCALE] == "fr_FR"
|
||||
assert result["data"][RenaultConfigurationKeys.USERNAME] == "email@test.com"
|
||||
assert result["data"][RenaultConfigurationKeys.PASSWORD] == "test"
|
||||
assert result["data"][RenaultConfigurationKeys.LOGIN_TOKEN] == MOCK_LOGIN_TOKEN
|
||||
assert (
|
||||
result["data"][RenaultConfigurationKeys.KAMEREON_ACCOUNT_ID] == "account_id_2"
|
||||
)
|
||||
assert result["data"][RenaultConfigurationKeys.LOCALE] == "fr_FR"
|
||||
assert result["context"]["unique_id"] == "account_id_2"
|
||||
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
@@ -264,9 +271,9 @@ async def test_config_flow_duplicate(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_LOCALE: "fr_FR",
|
||||
CONF_USERNAME: "email@test.com",
|
||||
CONF_PASSWORD: "test",
|
||||
RenaultConfigurationKeys.LOCALE: "fr_FR",
|
||||
RenaultConfigurationKeys.USERNAME: "email@test.com",
|
||||
RenaultConfigurationKeys.PASSWORD: "test",
|
||||
},
|
||||
)
|
||||
|
||||
@@ -285,8 +292,8 @@ async def test_reauth(hass: HomeAssistant, config_entry: MockConfigEntry) -> Non
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["description_placeholders"] == {
|
||||
CONF_NAME: "Mock Title",
|
||||
CONF_USERNAME: "email@test.com",
|
||||
"name": "Mock Title",
|
||||
RenaultConfigurationKeys.USERNAME: "email@test.com",
|
||||
}
|
||||
assert result["errors"] == {}
|
||||
|
||||
@@ -297,13 +304,13 @@ async def test_reauth(hass: HomeAssistant, config_entry: MockConfigEntry) -> Non
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_PASSWORD: "any"},
|
||||
user_input={RenaultConfigurationKeys.PASSWORD: "any"},
|
||||
)
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["description_placeholders"] == {
|
||||
CONF_NAME: "Mock Title",
|
||||
CONF_USERNAME: "email@test.com",
|
||||
"name": "Mock Title",
|
||||
RenaultConfigurationKeys.USERNAME: "email@test.com",
|
||||
}
|
||||
assert result2["errors"] == {"base": "invalid_credentials"}
|
||||
|
||||
@@ -315,15 +322,15 @@ async def test_reauth(hass: HomeAssistant, config_entry: MockConfigEntry) -> Non
|
||||
):
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_PASSWORD: "any"},
|
||||
user_input={RenaultConfigurationKeys.PASSWORD: "any"},
|
||||
)
|
||||
|
||||
assert result3["type"] is FlowResultType.ABORT
|
||||
assert result3["reason"] == "reauth_successful"
|
||||
|
||||
assert config_entry.data[CONF_USERNAME] == "email@test.com"
|
||||
assert config_entry.data[CONF_PASSWORD] == "any"
|
||||
assert config_entry.data[CONF_LOGIN_TOKEN] == MOCK_LOGIN_TOKEN
|
||||
assert config_entry.data[RenaultConfigurationKeys.USERNAME] == "email@test.com"
|
||||
assert config_entry.data[RenaultConfigurationKeys.PASSWORD] == "any"
|
||||
assert config_entry.data[RenaultConfigurationKeys.LOGIN_TOKEN] == MOCK_LOGIN_TOKEN
|
||||
|
||||
|
||||
async def test_reconfigure(
|
||||
@@ -338,9 +345,18 @@ async def test_reconfigure(
|
||||
assert not result["errors"]
|
||||
|
||||
data_schema = result["data_schema"].schema
|
||||
assert get_schema_suggested_value(data_schema, CONF_LOCALE) == "fr_FR"
|
||||
assert get_schema_suggested_value(data_schema, CONF_USERNAME) == "email@test.com"
|
||||
assert get_schema_suggested_value(data_schema, CONF_PASSWORD) == "test"
|
||||
assert (
|
||||
get_schema_suggested_value(data_schema, RenaultConfigurationKeys.LOCALE)
|
||||
== "fr_FR"
|
||||
)
|
||||
assert (
|
||||
get_schema_suggested_value(data_schema, RenaultConfigurationKeys.USERNAME)
|
||||
== "email@test.com"
|
||||
)
|
||||
assert (
|
||||
get_schema_suggested_value(data_schema, RenaultConfigurationKeys.PASSWORD)
|
||||
== "test"
|
||||
)
|
||||
|
||||
renault_account = AsyncMock()
|
||||
type(renault_account).account_id = PropertyMock(return_value="account_id_1")
|
||||
@@ -365,20 +381,23 @@ async def test_reconfigure(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_LOCALE: "fr_FR",
|
||||
CONF_USERNAME: "email2@test.com",
|
||||
CONF_PASSWORD: "test2",
|
||||
RenaultConfigurationKeys.LOCALE: "fr_FR",
|
||||
RenaultConfigurationKeys.USERNAME: "email2@test.com",
|
||||
RenaultConfigurationKeys.PASSWORD: "test2",
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
|
||||
assert config_entry.data[CONF_USERNAME] == "email2@test.com"
|
||||
assert config_entry.data[CONF_PASSWORD] == "test2"
|
||||
assert config_entry.data[CONF_LOGIN_TOKEN] == MOCK_LOGIN_TOKEN
|
||||
assert config_entry.data[CONF_KAMEREON_ACCOUNT_ID] == "account_id_1"
|
||||
assert config_entry.data[CONF_LOCALE] == "fr_FR"
|
||||
assert config_entry.data[RenaultConfigurationKeys.USERNAME] == "email2@test.com"
|
||||
assert config_entry.data[RenaultConfigurationKeys.PASSWORD] == "test2"
|
||||
assert config_entry.data[RenaultConfigurationKeys.LOGIN_TOKEN] == MOCK_LOGIN_TOKEN
|
||||
assert (
|
||||
config_entry.data[RenaultConfigurationKeys.KAMEREON_ACCOUNT_ID]
|
||||
== "account_id_1"
|
||||
)
|
||||
assert config_entry.data[RenaultConfigurationKeys.LOCALE] == "fr_FR"
|
||||
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
@@ -395,9 +414,18 @@ async def test_reconfigure_mismatch(
|
||||
assert not result["errors"]
|
||||
|
||||
data_schema = result["data_schema"].schema
|
||||
assert get_schema_suggested_value(data_schema, CONF_LOCALE) == "fr_FR"
|
||||
assert get_schema_suggested_value(data_schema, CONF_USERNAME) == "email@test.com"
|
||||
assert get_schema_suggested_value(data_schema, CONF_PASSWORD) == "test"
|
||||
assert (
|
||||
get_schema_suggested_value(data_schema, RenaultConfigurationKeys.LOCALE)
|
||||
== "fr_FR"
|
||||
)
|
||||
assert (
|
||||
get_schema_suggested_value(data_schema, RenaultConfigurationKeys.USERNAME)
|
||||
== "email@test.com"
|
||||
)
|
||||
assert (
|
||||
get_schema_suggested_value(data_schema, RenaultConfigurationKeys.PASSWORD)
|
||||
== "test"
|
||||
)
|
||||
|
||||
renault_account = AsyncMock()
|
||||
type(renault_account).account_id = PropertyMock(return_value="account_id_other")
|
||||
@@ -422,9 +450,9 @@ async def test_reconfigure_mismatch(
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_LOCALE: "fr_FR",
|
||||
CONF_USERNAME: "email2@test.com",
|
||||
CONF_PASSWORD: "test2",
|
||||
RenaultConfigurationKeys.LOCALE: "fr_FR",
|
||||
RenaultConfigurationKeys.USERNAME: "email2@test.com",
|
||||
RenaultConfigurationKeys.PASSWORD: "test2",
|
||||
},
|
||||
)
|
||||
|
||||
@@ -432,10 +460,13 @@ async def test_reconfigure_mismatch(
|
||||
assert result["reason"] == "unique_id_mismatch"
|
||||
|
||||
# Unchanged values
|
||||
assert config_entry.data[CONF_USERNAME] == "email@test.com"
|
||||
assert config_entry.data[CONF_PASSWORD] == "test"
|
||||
assert config_entry.data[CONF_LOGIN_TOKEN] == MOCK_LOGIN_TOKEN
|
||||
assert config_entry.data[CONF_KAMEREON_ACCOUNT_ID] == "account_id_1"
|
||||
assert config_entry.data[CONF_LOCALE] == "fr_FR"
|
||||
assert config_entry.data[RenaultConfigurationKeys.USERNAME] == "email@test.com"
|
||||
assert config_entry.data[RenaultConfigurationKeys.PASSWORD] == "test"
|
||||
assert config_entry.data[RenaultConfigurationKeys.LOGIN_TOKEN] == MOCK_LOGIN_TOKEN
|
||||
assert (
|
||||
config_entry.data[RenaultConfigurationKeys.KAMEREON_ACCOUNT_ID]
|
||||
== "account_id_1"
|
||||
)
|
||||
assert config_entry.data[RenaultConfigurationKeys.LOCALE] == "fr_FR"
|
||||
|
||||
assert len(mock_setup_entry.mock_calls) == 0
|
||||
|
||||
@@ -10,19 +10,13 @@ from renault_api.gigya.exceptions import GigyaException, InvalidCredentialsExcep
|
||||
from renault_api.renault_session import RenaultSession
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.renault.const import (
|
||||
CONF_KAMEREON_ACCOUNT_ID,
|
||||
CONF_LOCALE,
|
||||
CONF_LOGIN_TOKEN,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.components.renault.const import DOMAIN, RenaultConfigurationKeys
|
||||
from homeassistant.config_entries import (
|
||||
SOURCE_REAUTH,
|
||||
SOURCE_USER,
|
||||
ConfigEntry,
|
||||
ConfigEntryState,
|
||||
)
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.setup import async_setup_component
|
||||
@@ -34,10 +28,10 @@ from tests.typing import WebSocketGenerator
|
||||
|
||||
# Config data of an entry created before the login token was stored.
|
||||
MOCK_CONFIG_NO_TOKEN = {
|
||||
CONF_USERNAME: "email@test.com",
|
||||
CONF_PASSWORD: "test",
|
||||
CONF_KAMEREON_ACCOUNT_ID: MOCK_ACCOUNT_ID,
|
||||
CONF_LOCALE: "fr_FR",
|
||||
RenaultConfigurationKeys.USERNAME: "email@test.com",
|
||||
RenaultConfigurationKeys.PASSWORD: "test",
|
||||
RenaultConfigurationKeys.KAMEREON_ACCOUNT_ID: MOCK_ACCOUNT_ID,
|
||||
RenaultConfigurationKeys.LOCALE: "fr_FR",
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +96,10 @@ async def test_setup_entry_password_login(
|
||||
assert mock_login.called
|
||||
assert legacy_config_entry.state is ConfigEntryState.LOADED
|
||||
# The obtained login token is persisted so future setups skip the password.
|
||||
assert legacy_config_entry.data[CONF_LOGIN_TOKEN] == MOCK_LOGIN_TOKEN
|
||||
assert (
|
||||
legacy_config_entry.data[RenaultConfigurationKeys.LOGIN_TOKEN]
|
||||
== MOCK_LOGIN_TOKEN
|
||||
)
|
||||
|
||||
|
||||
async def test_setup_entry_bad_password(
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
from collections.abc import Generator
|
||||
from datetime import datetime
|
||||
from enum import StrEnum
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@@ -11,13 +12,8 @@ from renault_api.kamereon.models import ChargeSchedule, HvacSchedule
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.renault.const import DOMAIN
|
||||
from homeassistant.components.renault.services import (
|
||||
ATTR_SCHEDULES,
|
||||
ATTR_VEHICLE,
|
||||
ATTR_WHEN,
|
||||
)
|
||||
from homeassistant.components.renault.services import RenaultServiceArgument
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TEMPERATURE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
@@ -27,6 +23,16 @@ from tests.common import async_load_fixture
|
||||
pytestmark = pytest.mark.usefixtures("patch_renault_account", "patch_get_vehicles")
|
||||
|
||||
|
||||
class RenaultService(StrEnum):
|
||||
"""Renault service names."""
|
||||
|
||||
AC_CANCEL = "ac_cancel"
|
||||
AC_SET_SCHEDULES = "ac_set_schedules"
|
||||
AC_START = "ac_start"
|
||||
CHARGE_SET_SCHEDULES = "charge_set_schedules"
|
||||
CHARGE_START = "charge_start"
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def override_platforms() -> Generator[None]:
|
||||
"""Override PLATFORMS."""
|
||||
@@ -56,7 +62,7 @@ async def test_service_set_ac_cancel(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
data = {
|
||||
ATTR_VEHICLE: get_device_id(hass),
|
||||
RenaultServiceArgument.VEHICLE: get_device_id(hass),
|
||||
}
|
||||
|
||||
with patch(
|
||||
@@ -68,7 +74,7 @@ async def test_service_set_ac_cancel(
|
||||
),
|
||||
) as mock_action:
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "ac_cancel", service_data=data, blocking=True
|
||||
DOMAIN, RenaultService.AC_CANCEL, service_data=data, blocking=True
|
||||
)
|
||||
assert len(mock_action.mock_calls) == 1
|
||||
assert mock_action.mock_calls[0][1] == ()
|
||||
@@ -83,8 +89,8 @@ async def test_service_set_ac_start_simple(
|
||||
|
||||
temperature = 13.5
|
||||
data = {
|
||||
ATTR_VEHICLE: get_device_id(hass),
|
||||
ATTR_TEMPERATURE: temperature,
|
||||
RenaultServiceArgument.VEHICLE: get_device_id(hass),
|
||||
RenaultServiceArgument.TEMPERATURE: temperature,
|
||||
}
|
||||
|
||||
with patch(
|
||||
@@ -96,7 +102,7 @@ async def test_service_set_ac_start_simple(
|
||||
),
|
||||
) as mock_action:
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "ac_start", service_data=data, blocking=True
|
||||
DOMAIN, RenaultService.AC_START, service_data=data, blocking=True
|
||||
)
|
||||
assert len(mock_action.mock_calls) == 1
|
||||
assert mock_action.mock_calls[0][1] == (temperature, None)
|
||||
@@ -112,9 +118,9 @@ async def test_service_set_ac_start_with_date(
|
||||
temperature = 13.5
|
||||
when = datetime(2025, 8, 23, 17, 12, 45)
|
||||
data = {
|
||||
ATTR_VEHICLE: get_device_id(hass),
|
||||
ATTR_TEMPERATURE: temperature,
|
||||
ATTR_WHEN: when,
|
||||
RenaultServiceArgument.VEHICLE: get_device_id(hass),
|
||||
RenaultServiceArgument.TEMPERATURE: temperature,
|
||||
RenaultServiceArgument.WHEN: when,
|
||||
}
|
||||
|
||||
with patch(
|
||||
@@ -126,7 +132,7 @@ async def test_service_set_ac_start_with_date(
|
||||
),
|
||||
) as mock_action:
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "ac_start", service_data=data, blocking=True
|
||||
DOMAIN, RenaultService.AC_START, service_data=data, blocking=True
|
||||
)
|
||||
assert len(mock_action.mock_calls) == 1
|
||||
assert mock_action.mock_calls[0][1] == (temperature, when)
|
||||
@@ -140,7 +146,7 @@ async def test_service_charge_start_simple(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
data = {
|
||||
ATTR_VEHICLE: get_device_id(hass),
|
||||
RenaultServiceArgument.VEHICLE: get_device_id(hass),
|
||||
}
|
||||
|
||||
with patch(
|
||||
@@ -152,7 +158,7 @@ async def test_service_charge_start_simple(
|
||||
),
|
||||
) as mock_action:
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "charge_start", service_data=data, blocking=True
|
||||
DOMAIN, RenaultService.CHARGE_START, service_data=data, blocking=True
|
||||
)
|
||||
assert len(mock_action.mock_calls) == 1
|
||||
assert mock_action.mock_calls[0][1] == (None,)
|
||||
@@ -167,8 +173,8 @@ async def test_service_charge_start_with_date(
|
||||
|
||||
when = datetime(2025, 8, 23, 17, 12, 45)
|
||||
data = {
|
||||
ATTR_VEHICLE: get_device_id(hass),
|
||||
ATTR_WHEN: when,
|
||||
RenaultServiceArgument.VEHICLE: get_device_id(hass),
|
||||
RenaultServiceArgument.WHEN: when,
|
||||
}
|
||||
|
||||
with patch(
|
||||
@@ -180,7 +186,7 @@ async def test_service_charge_start_with_date(
|
||||
),
|
||||
) as mock_action:
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "charge_start", service_data=data, blocking=True
|
||||
DOMAIN, RenaultService.CHARGE_START, service_data=data, blocking=True
|
||||
)
|
||||
assert len(mock_action.mock_calls) == 1
|
||||
assert mock_action.mock_calls[0][1] == (when,)
|
||||
@@ -195,8 +201,8 @@ async def test_service_set_charge_schedule(
|
||||
|
||||
schedules = {"id": 2}
|
||||
data = {
|
||||
ATTR_VEHICLE: get_device_id(hass),
|
||||
ATTR_SCHEDULES: schedules,
|
||||
RenaultServiceArgument.VEHICLE: get_device_id(hass),
|
||||
RenaultServiceArgument.SCHEDULES: schedules,
|
||||
}
|
||||
|
||||
with (
|
||||
@@ -219,7 +225,10 @@ async def test_service_set_charge_schedule(
|
||||
) as mock_action,
|
||||
):
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "charge_set_schedules", service_data=data, blocking=True
|
||||
DOMAIN,
|
||||
RenaultService.CHARGE_SET_SCHEDULES,
|
||||
service_data=data,
|
||||
blocking=True,
|
||||
)
|
||||
assert len(mock_action.mock_calls) == 1
|
||||
mock_call_data: list[ChargeSchedule] = mock_action.mock_calls[0][1][0]
|
||||
@@ -247,8 +256,8 @@ async def test_service_set_charge_schedule_multi(
|
||||
{"id": 3},
|
||||
]
|
||||
data = {
|
||||
ATTR_VEHICLE: get_device_id(hass),
|
||||
ATTR_SCHEDULES: schedules,
|
||||
RenaultServiceArgument.VEHICLE: get_device_id(hass),
|
||||
RenaultServiceArgument.SCHEDULES: schedules,
|
||||
}
|
||||
|
||||
with (
|
||||
@@ -271,7 +280,10 @@ async def test_service_set_charge_schedule_multi(
|
||||
) as mock_action,
|
||||
):
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "charge_set_schedules", service_data=data, blocking=True
|
||||
DOMAIN,
|
||||
RenaultService.CHARGE_SET_SCHEDULES,
|
||||
service_data=data,
|
||||
blocking=True,
|
||||
)
|
||||
assert len(mock_action.mock_calls) == 1
|
||||
mock_call_data: list[ChargeSchedule] = mock_action.mock_calls[0][1][0]
|
||||
@@ -296,8 +308,8 @@ async def test_service_set_ac_schedule(
|
||||
|
||||
schedules = {"id": 2}
|
||||
data = {
|
||||
ATTR_VEHICLE: get_device_id(hass),
|
||||
ATTR_SCHEDULES: schedules,
|
||||
RenaultServiceArgument.VEHICLE: get_device_id(hass),
|
||||
RenaultServiceArgument.SCHEDULES: schedules,
|
||||
}
|
||||
|
||||
with (
|
||||
@@ -319,7 +331,7 @@ async def test_service_set_ac_schedule(
|
||||
) as mock_action,
|
||||
):
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "ac_set_schedules", service_data=data, blocking=True
|
||||
DOMAIN, RenaultService.AC_SET_SCHEDULES, service_data=data, blocking=True
|
||||
)
|
||||
assert len(mock_action.mock_calls) == 1
|
||||
mock_call_data: list[ChargeSchedule] = mock_action.mock_calls[0][1][0]
|
||||
@@ -347,8 +359,8 @@ async def test_service_set_ac_schedule_multi(
|
||||
{"id": 4},
|
||||
]
|
||||
data = {
|
||||
ATTR_VEHICLE: get_device_id(hass),
|
||||
ATTR_SCHEDULES: schedules,
|
||||
RenaultServiceArgument.VEHICLE: get_device_id(hass),
|
||||
RenaultServiceArgument.SCHEDULES: schedules,
|
||||
}
|
||||
|
||||
with (
|
||||
@@ -370,7 +382,7 @@ async def test_service_set_ac_schedule_multi(
|
||||
) as mock_action,
|
||||
):
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "ac_set_schedules", service_data=data, blocking=True
|
||||
DOMAIN, RenaultService.AC_SET_SCHEDULES, service_data=data, blocking=True
|
||||
)
|
||||
assert len(mock_action.mock_calls) == 1
|
||||
mock_call_data: list[HvacSchedule] = mock_action.mock_calls[0][1][0]
|
||||
@@ -393,11 +405,11 @@ async def test_service_invalid_device_id(
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
data = {ATTR_VEHICLE: "some_random_id"}
|
||||
data = {RenaultServiceArgument.VEHICLE: "some_random_id"}
|
||||
|
||||
with pytest.raises(ServiceValidationError) as err:
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "ac_cancel", service_data=data, blocking=True
|
||||
DOMAIN, RenaultService.AC_CANCEL, service_data=data, blocking=True
|
||||
)
|
||||
assert err.value.translation_key == "invalid_device_id"
|
||||
assert err.value.translation_placeholders == {"device_id": "some_random_id"}
|
||||
@@ -421,11 +433,11 @@ async def test_service_invalid_device_id2(
|
||||
identifiers={(DOMAIN, "VF1AAAAA111222333")},
|
||||
).id
|
||||
|
||||
data = {ATTR_VEHICLE: device_id}
|
||||
data = {RenaultServiceArgument.VEHICLE: device_id}
|
||||
|
||||
with pytest.raises(ServiceValidationError) as err:
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "ac_cancel", service_data=data, blocking=True
|
||||
DOMAIN, RenaultService.AC_CANCEL, service_data=data, blocking=True
|
||||
)
|
||||
assert err.value.translation_key == "no_config_entry_for_device"
|
||||
assert err.value.translation_placeholders == {"device_id": "REG-NUMBER"}
|
||||
@@ -439,7 +451,7 @@ async def test_service_exception(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
data = {
|
||||
ATTR_VEHICLE: get_device_id(hass),
|
||||
RenaultServiceArgument.VEHICLE: get_device_id(hass),
|
||||
}
|
||||
|
||||
with (
|
||||
@@ -450,7 +462,7 @@ async def test_service_exception(
|
||||
pytest.raises(HomeAssistantError, match="Didn't work"),
|
||||
):
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "ac_cancel", service_data=data, blocking=True
|
||||
DOMAIN, RenaultService.AC_CANCEL, service_data=data, blocking=True
|
||||
)
|
||||
assert len(mock_action.mock_calls) == 1
|
||||
assert mock_action.mock_calls[0][1] == ()
|
||||
|
||||
Reference in New Issue
Block a user