Add Remote Engine Start status to Renault integration (#67028)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2022-02-23 17:14:58 +01:00 committed by GitHub
parent eb80abf89e
commit 419e683526
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 93 additions and 0 deletions

View File

@ -153,4 +153,9 @@ COORDINATORS: tuple[RenaultCoordinatorDescription, ...] = (
key="lock_status", key="lock_status",
update_method=lambda x: x.get_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,
),
) )

View File

@ -12,6 +12,7 @@ from renault_api.kamereon.models import (
KamereonVehicleCockpitData, KamereonVehicleCockpitData,
KamereonVehicleHvacStatusData, KamereonVehicleHvacStatusData,
KamereonVehicleLocationData, KamereonVehicleLocationData,
KamereonVehicleResStateData,
) )
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
@ -333,4 +334,19 @@ SENSOR_TYPES: tuple[RenaultSensorEntityDescription, ...] = (
name="Location Last Activity", name="Location Last Activity",
value_lambda=_get_utc_value, 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",
),
) )

View File

@ -101,6 +101,11 @@ def _get_fixtures(vehicle_type: str) -> MappingProxyType:
if "lock_status" in mock_vehicle["endpoints"] if "lock_status" in mock_vehicle["endpoints"]
else load_fixture("renault/no_data.json") else load_fixture("renault/no_data.json")
).get_attributes(schemas.KamereonVehicleLockStatusDataSchema), ).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( ), patch(
"renault_api.renault_vehicle.RenaultVehicle.get_lock_status", "renault_api.renault_vehicle.RenaultVehicle.get_lock_status",
return_value=mock_fixtures["lock_status"], return_value=mock_fixtures["lock_status"],
), patch(
"renault_api.renault_vehicle.RenaultVehicle.get_res_state",
return_value=mock_fixtures["res_state"],
): ):
yield yield
@ -154,6 +162,9 @@ def patch_fixtures_with_no_data():
), patch( ), patch(
"renault_api.renault_vehicle.RenaultVehicle.get_lock_status", "renault_api.renault_vehicle.RenaultVehicle.get_lock_status",
return_value=mock_fixtures["lock_status"], return_value=mock_fixtures["lock_status"],
), patch(
"renault_api.renault_vehicle.RenaultVehicle.get_res_state",
return_value=mock_fixtures["res_state"],
): ):
yield yield
@ -179,6 +190,9 @@ def _patch_fixtures_with_side_effect(side_effect: Any):
), patch( ), patch(
"renault_api.renault_vehicle.RenaultVehicle.get_lock_status", "renault_api.renault_vehicle.RenaultVehicle.get_lock_status",
side_effect=side_effect, side_effect=side_effect,
), patch(
"renault_api.renault_vehicle.RenaultVehicle.get_res_state",
side_effect=side_effect,
): ):
yield yield

View File

@ -229,6 +229,17 @@ MOCK_VEHICLES = {
ATTR_STATE: "plugged", ATTR_STATE: "plugged",
ATTR_UNIQUE_ID: "vf1aaaaa555777999_plug_state", 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": { "zoe_50": {
@ -246,6 +257,7 @@ MOCK_VEHICLES = {
"hvac_status": "hvac_status.2.json", "hvac_status": "hvac_status.2.json",
"location": "location.json", "location": "location.json",
"lock_status": "lock_status.1.json", "lock_status": "lock_status.1.json",
"res_state": "res_state.1.json",
}, },
Platform.BINARY_SENSOR: [ Platform.BINARY_SENSOR: [
{ {
@ -441,6 +453,17 @@ MOCK_VEHICLES = {
ATTR_STATE: "2020-02-18T16:58:38+00:00", ATTR_STATE: "2020-02-18T16:58:38+00:00",
ATTR_UNIQUE_ID: "vf1aaaaa555777999_location_last_activity", 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": { "captur_phev": {
@ -457,6 +480,7 @@ MOCK_VEHICLES = {
"cockpit": "cockpit_fuel.json", "cockpit": "cockpit_fuel.json",
"location": "location.json", "location": "location.json",
"lock_status": "lock_status.1.json", "lock_status": "lock_status.1.json",
"res_state": "res_state.1.json",
}, },
Platform.BINARY_SENSOR: [ Platform.BINARY_SENSOR: [
{ {
@ -641,6 +665,17 @@ MOCK_VEHICLES = {
ATTR_STATE: "2020-02-18T16:58:38+00:00", ATTR_STATE: "2020-02-18T16:58:38+00:00",
ATTR_UNIQUE_ID: "vf1aaaaa555777123_location_last_activity", 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": { "captur_fuel": {
@ -655,6 +690,7 @@ MOCK_VEHICLES = {
"cockpit": "cockpit_fuel.json", "cockpit": "cockpit_fuel.json",
"location": "location.json", "location": "location.json",
"lock_status": "lock_status.1.json", "lock_status": "lock_status.1.json",
"res_state": "res_state.1.json",
}, },
Platform.BINARY_SENSOR: [ Platform.BINARY_SENSOR: [
{ {
@ -743,6 +779,17 @@ MOCK_VEHICLES = {
ATTR_STATE: "2020-02-18T16:58:38+00:00", ATTR_STATE: "2020-02-18T16:58:38+00:00",
ATTR_UNIQUE_ID: "vf1aaaaa555777123_location_last_activity", 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",
},
], ],
}, },
} }

View File

@ -0,0 +1,10 @@
{
"data": {
"type": "ResState",
"id": "VF1AAAAA555777999",
"attributes": {
"details": "Stopped, ready for RES",
"code": "10"
}
}
}

View File

@ -157,6 +157,7 @@ VEHICLE_DATA = {
"externalTemperature": 8.0, "externalTemperature": 8.0,
"hvacStatus": "off", "hvacStatus": "off",
}, },
"res_state": {},
} }