diff --git a/homeassistant/components/skoda/binary_sensor.py b/homeassistant/components/skoda/binary_sensor.py index 3eece7dc2ac0..6e2ba02b8578 100644 --- a/homeassistant/components/skoda/binary_sensor.py +++ b/homeassistant/components/skoda/binary_sensor.py @@ -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, + ), ) diff --git a/tests/components/skoda/snapshots/test_binary_sensor.ambr b/tests/components/skoda/snapshots/test_binary_sensor.ambr index 65425adc5d8b..5048c9235ecc 100644 --- a/tests/components/skoda/snapshots/test_binary_sensor.ambr +++ b/tests/components/skoda/snapshots/test_binary_sensor.ambr @@ -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': , + 'config_subentry_id': None, + 'device_class': None, + 'device_id': , + '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': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Moving', + 'options': dict({ + }), + 'original_device_class': , + '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({ + : 'moving', + : 'Enyaq Coupé Moving', + }), + 'context': , + 'entity_id': 'binary_sensor.enyaq_coupe_moving', + 'last_changed': , + 'last_reported': , + 'last_updated': , + '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': , + 'config_subentry_id': None, + 'device_class': None, + 'device_id': , + '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': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Moving', + 'options': dict({ + }), + 'original_device_class': , + '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({ + : 'moving', + : 'Superb Moving', + }), + 'context': , + 'entity_id': 'binary_sensor.superb_moving', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'on', + }) +# --- # name: test_binary_sensors[vehicle_hybrid.json][binary_sensor.superb_trunk-entry] EntityRegistryEntrySnapshot({ 'aliases': list([ diff --git a/tests/components/skoda/test_binary_sensor.py b/tests/components/skoda/test_binary_sensor.py index d905140f83c9..d4912f586851 100644 --- a/tests/components/skoda/test_binary_sensor.py +++ b/tests/components/skoda/test_binary_sensor.py @@ -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