mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Add moving binary sensor to Škoda (#195648)
This commit is contained in:
@@ -8,6 +8,7 @@ from skoda_public_api.models.enums import (
|
||||
AirConditioningState,
|
||||
AuxiliaryHeatingState,
|
||||
LockState,
|
||||
MovementState,
|
||||
OnOffState,
|
||||
OpenCloseState,
|
||||
PlugConnectionState,
|
||||
@@ -110,6 +111,14 @@ def _auxiliary_heating_value(vehicle: VehicleObject) -> bool | None:
|
||||
return _AUXILIARY_HEATING_RUNNING_MAP.get(vehicle.auxiliary_heating.state)
|
||||
|
||||
|
||||
def _moving_value(vehicle: VehicleObject) -> bool | None:
|
||||
if (parking_position := vehicle.parking_position) is None:
|
||||
return None
|
||||
if parking_position.state is MovementState.UNKNOWN:
|
||||
return None
|
||||
return parking_position.state is MovementState.IN_MOTION
|
||||
|
||||
|
||||
BINARY_SENSOR_TYPES: tuple[SkodaBinarySensorEntityDescription, ...] = (
|
||||
SkodaBinarySensorEntityDescription(
|
||||
key="lock",
|
||||
@@ -186,6 +195,12 @@ BINARY_SENSOR_TYPES: tuple[SkodaBinarySensorEntityDescription, ...] = (
|
||||
required_capabilities=frozenset({VehicleCapability.AUXILIARY_HEATING}),
|
||||
is_on_fn=_auxiliary_heating_value,
|
||||
),
|
||||
SkodaBinarySensorEntityDescription(
|
||||
key="moving",
|
||||
device_class=BinarySensorDeviceClass.MOVING,
|
||||
required_capabilities=frozenset({VehicleCapability.PARKING_POSITION}),
|
||||
is_on_fn=_moving_value,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -356,6 +356,57 @@
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[vehicle_electric.json][binary_sensor.enyaq_coupe_moving-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
None,
|
||||
]),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': None,
|
||||
'device_class': None,
|
||||
'device_id': <DeviceEntry identifiers=[('skoda', 'TMBJM7NP2M1TMP511')]>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.enyaq_coupe_moving',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Moving',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.MOVING: 'moving'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Moving',
|
||||
'platform': 'skoda',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'TMBJM7NP2M1TMP511_moving',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[vehicle_electric.json][binary_sensor.enyaq_coupe_moving-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'moving',
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Enyaq Coupé Moving',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.enyaq_coupe_moving',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[vehicle_electric.json][binary_sensor.enyaq_coupe_sunroof-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
@@ -866,6 +917,57 @@
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[vehicle_hybrid.json][binary_sensor.superb_moving-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
None,
|
||||
]),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': None,
|
||||
'device_class': None,
|
||||
'device_id': <DeviceEntry identifiers=[('skoda', 'TMBJM7NP2M1TMP511')]>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.superb_moving',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Moving',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.MOVING: 'moving'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Moving',
|
||||
'platform': 'skoda',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'TMBJM7NP2M1TMP511_moving',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[vehicle_hybrid.json][binary_sensor.superb_moving-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'moving',
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Superb Moving',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.superb_moving',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[vehicle_hybrid.json][binary_sensor.superb_trunk-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
|
||||
@@ -14,6 +14,7 @@ from pytest_homeassistant.common import (
|
||||
from skoda_public_api.models.enums import (
|
||||
AirConditioningState,
|
||||
AuxiliaryHeatingState,
|
||||
MovementState,
|
||||
PlugConnectionState,
|
||||
)
|
||||
from skoda_public_api.models.vehicle import VehicleResponse
|
||||
@@ -107,6 +108,7 @@ async def test_lock_prefers_reliable_lock_status(
|
||||
("binary_sensor.enyaq_coupe_charging_cable", STATE_ON),
|
||||
("binary_sensor.enyaq_coupe_air_conditioning", STATE_OFF),
|
||||
("binary_sensor.enyaq_coupe_auxiliary_heating", STATE_OFF),
|
||||
("binary_sensor.enyaq_coupe_moving", STATE_OFF),
|
||||
],
|
||||
)
|
||||
async def test_binary_sensor_unknown_when_data_missing(
|
||||
@@ -210,3 +212,28 @@ async def test_auxiliary_heating_state(
|
||||
|
||||
assert (state := hass.states.get("binary_sensor.enyaq_coupe_auxiliary_heating"))
|
||||
assert state.state == expected_state
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("movement_state", "expected_state"),
|
||||
[
|
||||
pytest.param(MovementState.IN_MOTION, STATE_ON, id="in_motion"),
|
||||
pytest.param(MovementState.PARKED, STATE_OFF, id="parked"),
|
||||
pytest.param(MovementState.UNKNOWN, STATE_UNKNOWN, id="unknown"),
|
||||
],
|
||||
)
|
||||
async def test_moving_state(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_skoda_client: AsyncMock,
|
||||
movement_state: MovementState,
|
||||
expected_state: str,
|
||||
) -> None:
|
||||
"""Test the moving sensor follows the parking position state."""
|
||||
vehicle = mock_skoda_client.get_vehicle.return_value.vehicle
|
||||
vehicle.parking_position.state = movement_state
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert (state := hass.states.get("binary_sensor.enyaq_coupe_moving"))
|
||||
assert state.state == expected_state
|
||||
|
||||
Reference in New Issue
Block a user