mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 11:33:11 -04:00
Add charging error state to Škoda charging state sensor (#195979)
This commit is contained in:
@@ -58,6 +58,7 @@ _CHARGING_STATE_MAP = {
|
||||
ChargingState.CONSERVING: "conserving",
|
||||
ChargingState.DISCHARGING: "discharging",
|
||||
ChargingState.CHARGING_INTERRUPTED: "charging_interrupted",
|
||||
ChargingState.CHARGING_ERROR: "charging_error",
|
||||
}
|
||||
|
||||
_CHARGE_TYPE_MAP = {
|
||||
@@ -338,6 +339,7 @@ SENSOR_TYPES: tuple[SkodaSensorEntityDescription, ...] = (
|
||||
"conserving",
|
||||
"discharging",
|
||||
"charging_interrupted",
|
||||
"charging_error",
|
||||
],
|
||||
icon="mdi:battery-charging",
|
||||
required_capabilities=frozenset({VehicleCapability.CHARGING}),
|
||||
|
||||
@@ -108,6 +108,7 @@
|
||||
"name": "Charging state",
|
||||
"state": {
|
||||
"charging": "Charging",
|
||||
"charging_error": "Charging error",
|
||||
"charging_interrupted": "Charging interrupted",
|
||||
"connect_cable": "Cable not connected",
|
||||
"conserving": "Conserving",
|
||||
|
||||
@@ -685,6 +685,7 @@
|
||||
'conserving',
|
||||
'discharging',
|
||||
'charging_interrupted',
|
||||
'charging_error',
|
||||
]),
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
@@ -730,6 +731,7 @@
|
||||
'conserving',
|
||||
'discharging',
|
||||
'charging_interrupted',
|
||||
'charging_error',
|
||||
]),
|
||||
}),
|
||||
'context': <ANY>,
|
||||
@@ -1425,6 +1427,7 @@
|
||||
'conserving',
|
||||
'discharging',
|
||||
'charging_interrupted',
|
||||
'charging_error',
|
||||
]),
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
@@ -1470,6 +1473,7 @@
|
||||
'conserving',
|
||||
'discharging',
|
||||
'charging_interrupted',
|
||||
'charging_error',
|
||||
]),
|
||||
}),
|
||||
'context': <ANY>,
|
||||
@@ -2217,6 +2221,7 @@
|
||||
'conserving',
|
||||
'discharging',
|
||||
'charging_interrupted',
|
||||
'charging_error',
|
||||
]),
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
@@ -2262,6 +2267,7 @@
|
||||
'conserving',
|
||||
'discharging',
|
||||
'charging_interrupted',
|
||||
'charging_error',
|
||||
]),
|
||||
}),
|
||||
'context': <ANY>,
|
||||
@@ -2950,6 +2956,7 @@
|
||||
'conserving',
|
||||
'discharging',
|
||||
'charging_interrupted',
|
||||
'charging_error',
|
||||
]),
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
@@ -2995,6 +3002,7 @@
|
||||
'conserving',
|
||||
'discharging',
|
||||
'charging_interrupted',
|
||||
'charging_error',
|
||||
]),
|
||||
}),
|
||||
'context': <ANY>,
|
||||
|
||||
@@ -11,6 +11,7 @@ from pytest_homeassistant.common import (
|
||||
async_load_json_object_fixture,
|
||||
snapshot_platform,
|
||||
)
|
||||
from skoda_public_api.models.enums import ChargingState
|
||||
from skoda_public_api.models.vehicle import VehicleResponse
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
@@ -79,3 +80,33 @@ async def test_sensor_unknown_when_data_becomes_unavailable(
|
||||
|
||||
assert (state := hass.states.get("sensor.superb_fuel_level"))
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("charging_state", "expected_state"),
|
||||
[
|
||||
(ChargingState.CHARGING, "charging"),
|
||||
(ChargingState.CHARGING_ERROR, "charging_error"),
|
||||
(ChargingState.UNKNOWN, STATE_UNKNOWN),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("vehicle_fixture", ["vehicle_hybrid.json"])
|
||||
async def test_charging_state_follows_vehicle(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_skoda_client: AsyncMock,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
charging_state: ChargingState,
|
||||
expected_state: str,
|
||||
) -> None:
|
||||
"""Test the charging state sensor follows the state reported by the vehicle."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
vehicle = mock_skoda_client.get_vehicle.return_value.vehicle
|
||||
vehicle.charging.status.state = charging_state
|
||||
freezer.tick(UPDATE_INTERVAL)
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (state := hass.states.get("sensor.superb_charging_state"))
|
||||
assert state.state == expected_state
|
||||
|
||||
@@ -195,6 +195,7 @@ async def test_switch_action_error(
|
||||
("charging_state", "expected_state"),
|
||||
[
|
||||
(ChargingState.CHARGING, STATE_ON),
|
||||
(ChargingState.CHARGING_ERROR, STATE_OFF),
|
||||
(ChargingState.UNKNOWN, STATE_UNKNOWN),
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user