From 419e68352697c850056971462e7d614e9e1918cd Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 23 Feb 2022 17:14:58 +0100 Subject: [PATCH] Add Remote Engine Start status to Renault integration (#67028) Co-authored-by: epenet --- .../components/renault/renault_vehicle.py | 5 ++ homeassistant/components/renault/sensor.py | 16 +++++++ tests/components/renault/conftest.py | 14 ++++++ tests/components/renault/const.py | 47 +++++++++++++++++++ .../renault/fixtures/res_state.1.json | 10 ++++ tests/components/renault/test_diagnostics.py | 1 + 6 files changed, 93 insertions(+) create mode 100644 tests/components/renault/fixtures/res_state.1.json diff --git a/homeassistant/components/renault/renault_vehicle.py b/homeassistant/components/renault/renault_vehicle.py index c4e42a7be5b..12860bc6b9a 100644 --- a/homeassistant/components/renault/renault_vehicle.py +++ b/homeassistant/components/renault/renault_vehicle.py @@ -153,4 +153,9 @@ COORDINATORS: tuple[RenaultCoordinatorDescription, ...] = ( key="lock_status", update_method=lambda x: x.get_lock_status, ), + RenaultCoordinatorDescription( + endpoint="res-state", + key="res_state", + update_method=lambda x: x.get_res_state, + ), ) diff --git a/homeassistant/components/renault/sensor.py b/homeassistant/components/renault/sensor.py index 8e63d09b5c7..c6621b16bbc 100644 --- a/homeassistant/components/renault/sensor.py +++ b/homeassistant/components/renault/sensor.py @@ -12,6 +12,7 @@ from renault_api.kamereon.models import ( KamereonVehicleCockpitData, KamereonVehicleHvacStatusData, KamereonVehicleLocationData, + KamereonVehicleResStateData, ) from homeassistant.components.sensor import ( @@ -333,4 +334,19 @@ SENSOR_TYPES: tuple[RenaultSensorEntityDescription, ...] = ( name="Location Last Activity", value_lambda=_get_utc_value, ), + RenaultSensorEntityDescription( + key="res_state", + coordinator="res_state", + data_key="details", + entity_class=RenaultSensor[KamereonVehicleResStateData], + name="Remote Engine Start", + ), + RenaultSensorEntityDescription( + key="res_state_code", + coordinator="res_state", + data_key="code", + entity_class=RenaultSensor[KamereonVehicleResStateData], + entity_registry_enabled_default=False, + name="Remote Engine Start Code", + ), ) diff --git a/tests/components/renault/conftest.py b/tests/components/renault/conftest.py index 89c6c364860..6c62e5d22e2 100644 --- a/tests/components/renault/conftest.py +++ b/tests/components/renault/conftest.py @@ -101,6 +101,11 @@ def _get_fixtures(vehicle_type: str) -> MappingProxyType: if "lock_status" in mock_vehicle["endpoints"] else load_fixture("renault/no_data.json") ).get_attributes(schemas.KamereonVehicleLockStatusDataSchema), + "res_state": schemas.KamereonVehicleDataResponseSchema.loads( + load_fixture(f"renault/{mock_vehicle['endpoints']['res_state']}") + if "res_state" in mock_vehicle["endpoints"] + else load_fixture("renault/no_data.json") + ).get_attributes(schemas.KamereonVehicleResStateDataSchema), } @@ -127,6 +132,9 @@ def patch_fixtures_with_data(vehicle_type: str): ), patch( "renault_api.renault_vehicle.RenaultVehicle.get_lock_status", return_value=mock_fixtures["lock_status"], + ), patch( + "renault_api.renault_vehicle.RenaultVehicle.get_res_state", + return_value=mock_fixtures["res_state"], ): yield @@ -154,6 +162,9 @@ def patch_fixtures_with_no_data(): ), patch( "renault_api.renault_vehicle.RenaultVehicle.get_lock_status", return_value=mock_fixtures["lock_status"], + ), patch( + "renault_api.renault_vehicle.RenaultVehicle.get_res_state", + return_value=mock_fixtures["res_state"], ): yield @@ -179,6 +190,9 @@ def _patch_fixtures_with_side_effect(side_effect: Any): ), patch( "renault_api.renault_vehicle.RenaultVehicle.get_lock_status", side_effect=side_effect, + ), patch( + "renault_api.renault_vehicle.RenaultVehicle.get_res_state", + side_effect=side_effect, ): yield diff --git a/tests/components/renault/const.py b/tests/components/renault/const.py index 368f3b97fbd..41a72c6b7ab 100644 --- a/tests/components/renault/const.py +++ b/tests/components/renault/const.py @@ -229,6 +229,17 @@ MOCK_VEHICLES = { ATTR_STATE: "plugged", ATTR_UNIQUE_ID: "vf1aaaaa555777999_plug_state", }, + { + ATTR_ENTITY_ID: "sensor.reg_number_remote_engine_start", + ATTR_STATE: STATE_UNKNOWN, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_res_state", + }, + { + ATTR_DEFAULT_DISABLED: True, + ATTR_ENTITY_ID: "sensor.reg_number_remote_engine_start_code", + ATTR_STATE: STATE_UNKNOWN, + ATTR_UNIQUE_ID: "vf1aaaaa555777999_res_state_code", + }, ], }, "zoe_50": { @@ -246,6 +257,7 @@ MOCK_VEHICLES = { "hvac_status": "hvac_status.2.json", "location": "location.json", "lock_status": "lock_status.1.json", + "res_state": "res_state.1.json", }, Platform.BINARY_SENSOR: [ { @@ -441,6 +453,17 @@ MOCK_VEHICLES = { ATTR_STATE: "2020-02-18T16:58:38+00:00", ATTR_UNIQUE_ID: "vf1aaaaa555777999_location_last_activity", }, + { + ATTR_ENTITY_ID: "sensor.reg_number_remote_engine_start", + ATTR_STATE: "Stopped, ready for RES", + ATTR_UNIQUE_ID: "vf1aaaaa555777999_res_state", + }, + { + ATTR_DEFAULT_DISABLED: True, + ATTR_ENTITY_ID: "sensor.reg_number_remote_engine_start_code", + ATTR_STATE: "10", + ATTR_UNIQUE_ID: "vf1aaaaa555777999_res_state_code", + }, ], }, "captur_phev": { @@ -457,6 +480,7 @@ MOCK_VEHICLES = { "cockpit": "cockpit_fuel.json", "location": "location.json", "lock_status": "lock_status.1.json", + "res_state": "res_state.1.json", }, Platform.BINARY_SENSOR: [ { @@ -641,6 +665,17 @@ MOCK_VEHICLES = { ATTR_STATE: "2020-02-18T16:58:38+00:00", ATTR_UNIQUE_ID: "vf1aaaaa555777123_location_last_activity", }, + { + ATTR_ENTITY_ID: "sensor.reg_number_remote_engine_start", + ATTR_STATE: "Stopped, ready for RES", + ATTR_UNIQUE_ID: "vf1aaaaa555777123_res_state", + }, + { + ATTR_DEFAULT_DISABLED: True, + ATTR_ENTITY_ID: "sensor.reg_number_remote_engine_start_code", + ATTR_STATE: "10", + ATTR_UNIQUE_ID: "vf1aaaaa555777123_res_state_code", + }, ], }, "captur_fuel": { @@ -655,6 +690,7 @@ MOCK_VEHICLES = { "cockpit": "cockpit_fuel.json", "location": "location.json", "lock_status": "lock_status.1.json", + "res_state": "res_state.1.json", }, Platform.BINARY_SENSOR: [ { @@ -743,6 +779,17 @@ MOCK_VEHICLES = { ATTR_STATE: "2020-02-18T16:58:38+00:00", ATTR_UNIQUE_ID: "vf1aaaaa555777123_location_last_activity", }, + { + ATTR_ENTITY_ID: "sensor.reg_number_remote_engine_start", + ATTR_STATE: "Stopped, ready for RES", + ATTR_UNIQUE_ID: "vf1aaaaa555777123_res_state", + }, + { + ATTR_DEFAULT_DISABLED: True, + ATTR_ENTITY_ID: "sensor.reg_number_remote_engine_start_code", + ATTR_STATE: "10", + ATTR_UNIQUE_ID: "vf1aaaaa555777123_res_state_code", + }, ], }, } diff --git a/tests/components/renault/fixtures/res_state.1.json b/tests/components/renault/fixtures/res_state.1.json new file mode 100644 index 00000000000..e6973ed091a --- /dev/null +++ b/tests/components/renault/fixtures/res_state.1.json @@ -0,0 +1,10 @@ +{ + "data": { + "type": "ResState", + "id": "VF1AAAAA555777999", + "attributes": { + "details": "Stopped, ready for RES", + "code": "10" + } + } + } \ No newline at end of file diff --git a/tests/components/renault/test_diagnostics.py b/tests/components/renault/test_diagnostics.py index 1a61859ac93..fccf5a757b4 100644 --- a/tests/components/renault/test_diagnostics.py +++ b/tests/components/renault/test_diagnostics.py @@ -157,6 +157,7 @@ VEHICLE_DATA = { "externalTemperature": 8.0, "hvacStatus": "off", }, + "res_state": {}, }