mirror of
https://github.com/home-assistant/core
synced 2024-10-04 07:58:43 +02:00
Add door and lock status to Renault integration (#66698)
* Add coordinator for lock status * Add fixture for lock status * Add lock status binary sensor * Add to test constants * Adjust conftest * Fix inverted state * Add door status Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
9ed4bcf965
commit
d49029e9fc
@ -79,7 +79,8 @@ class RenaultBinarySensor(
|
||||
return None
|
||||
|
||||
|
||||
BINARY_SENSOR_TYPES: tuple[RenaultBinarySensorEntityDescription, ...] = (
|
||||
BINARY_SENSOR_TYPES: tuple[RenaultBinarySensorEntityDescription, ...] = tuple(
|
||||
[
|
||||
RenaultBinarySensorEntityDescription(
|
||||
key="plugged_in",
|
||||
coordinator="battery",
|
||||
@ -104,4 +105,35 @@ BINARY_SENSOR_TYPES: tuple[RenaultBinarySensorEntityDescription, ...] = (
|
||||
on_key="hvacStatus",
|
||||
on_value="on",
|
||||
),
|
||||
RenaultBinarySensorEntityDescription(
|
||||
key="lock_status",
|
||||
coordinator="lock_status",
|
||||
# lock: on means open (unlocked), off means closed (locked)
|
||||
device_class=BinarySensorDeviceClass.LOCK,
|
||||
name="Lock",
|
||||
on_key="lockStatus",
|
||||
on_value="unlocked",
|
||||
),
|
||||
RenaultBinarySensorEntityDescription(
|
||||
key="hatch_status",
|
||||
coordinator="lock_status",
|
||||
# On means open, Off means closed
|
||||
device_class=BinarySensorDeviceClass.DOOR,
|
||||
name="Hatch",
|
||||
on_key="hatchStatus",
|
||||
on_value="open",
|
||||
),
|
||||
]
|
||||
+ [
|
||||
RenaultBinarySensorEntityDescription(
|
||||
key=f"{door.replace(' ','_').lower()}_door_status",
|
||||
coordinator="lock_status",
|
||||
# On means open, Off means closed
|
||||
device_class=BinarySensorDeviceClass.DOOR,
|
||||
name=f"{door} Door",
|
||||
on_key=f"doorStatus{door.replace(' ','')}",
|
||||
on_value="open",
|
||||
)
|
||||
for door in ("Rear Left", "Rear Right", "Driver", "Passenger")
|
||||
],
|
||||
)
|
||||
|
@ -148,4 +148,9 @@ COORDINATORS: tuple[RenaultCoordinatorDescription, ...] = (
|
||||
requires_electricity=True,
|
||||
update_method=lambda x: x.get_charge_mode,
|
||||
),
|
||||
RenaultCoordinatorDescription(
|
||||
endpoint="lock-status",
|
||||
key="lock_status",
|
||||
update_method=lambda x: x.get_lock_status,
|
||||
),
|
||||
)
|
||||
|
@ -102,6 +102,11 @@ def _get_fixtures(vehicle_type: str) -> MappingProxyType:
|
||||
if "location" in mock_vehicle["endpoints"]
|
||||
else load_fixture("renault/no_data.json")
|
||||
).get_attributes(schemas.KamereonVehicleLocationDataSchema),
|
||||
"lock_status": schemas.KamereonVehicleDataResponseSchema.loads(
|
||||
load_fixture(f"renault/{mock_vehicle['endpoints']['lock_status']}")
|
||||
if "lock_status" in mock_vehicle["endpoints"]
|
||||
else load_fixture("renault/no_data.json")
|
||||
).get_attributes(schemas.KamereonVehicleLockStatusDataSchema),
|
||||
}
|
||||
|
||||
|
||||
@ -125,6 +130,9 @@ def patch_fixtures_with_data(vehicle_type: str):
|
||||
), patch(
|
||||
"renault_api.renault_vehicle.RenaultVehicle.get_location",
|
||||
return_value=mock_fixtures["location"],
|
||||
), patch(
|
||||
"renault_api.renault_vehicle.RenaultVehicle.get_lock_status",
|
||||
return_value=mock_fixtures["lock_status"],
|
||||
):
|
||||
yield
|
||||
|
||||
@ -149,6 +157,9 @@ def patch_fixtures_with_no_data():
|
||||
), patch(
|
||||
"renault_api.renault_vehicle.RenaultVehicle.get_location",
|
||||
return_value=mock_fixtures["location"],
|
||||
), patch(
|
||||
"renault_api.renault_vehicle.RenaultVehicle.get_lock_status",
|
||||
return_value=mock_fixtures["lock_status"],
|
||||
):
|
||||
yield
|
||||
|
||||
@ -171,6 +182,9 @@ def _patch_fixtures_with_side_effect(side_effect: Any):
|
||||
), patch(
|
||||
"renault_api.renault_vehicle.RenaultVehicle.get_location",
|
||||
side_effect=side_effect,
|
||||
), patch(
|
||||
"renault_api.renault_vehicle.RenaultVehicle.get_lock_status",
|
||||
side_effect=side_effect,
|
||||
):
|
||||
yield
|
||||
|
||||
|
@ -252,6 +252,7 @@ MOCK_VEHICLES = {
|
||||
True, # location
|
||||
True, # battery-status
|
||||
True, # charge-mode
|
||||
True, # lock-status
|
||||
],
|
||||
"endpoints": {
|
||||
"battery_status": "battery_status_not_charging.json",
|
||||
@ -259,6 +260,7 @@ MOCK_VEHICLES = {
|
||||
"cockpit": "cockpit_ev.json",
|
||||
"hvac_status": "hvac_status.2.json",
|
||||
"location": "location.json",
|
||||
"lock_status": "lock_status.1.json",
|
||||
},
|
||||
Platform.BINARY_SENSOR: [
|
||||
{
|
||||
@ -279,6 +281,42 @@ MOCK_VEHICLES = {
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777999_hvac_status",
|
||||
},
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.LOCK,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_lock",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777999_lock_status",
|
||||
},
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_rear_left_door",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777999_rear_left_door_status",
|
||||
},
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_rear_right_door",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777999_rear_right_door_status",
|
||||
},
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_driver_door",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777999_driver_door_status",
|
||||
},
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_passenger_door",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777999_passenger_door_status",
|
||||
},
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_hatch",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777999_hatch_status",
|
||||
},
|
||||
],
|
||||
Platform.BUTTON: [
|
||||
{
|
||||
@ -434,12 +472,14 @@ MOCK_VEHICLES = {
|
||||
True, # location
|
||||
True, # battery-status
|
||||
True, # charge-mode
|
||||
True, # lock-status
|
||||
],
|
||||
"endpoints": {
|
||||
"battery_status": "battery_status_charging.json",
|
||||
"charge_mode": "charge_mode_always.json",
|
||||
"cockpit": "cockpit_fuel.json",
|
||||
"location": "location.json",
|
||||
"lock_status": "lock_status.1.json",
|
||||
},
|
||||
Platform.BINARY_SENSOR: [
|
||||
{
|
||||
@ -454,6 +494,42 @@ MOCK_VEHICLES = {
|
||||
ATTR_STATE: STATE_ON,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777123_charging",
|
||||
},
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.LOCK,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_lock",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777123_lock_status",
|
||||
},
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_rear_left_door",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777123_rear_left_door_status",
|
||||
},
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_rear_right_door",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777123_rear_right_door_status",
|
||||
},
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_driver_door",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777123_driver_door_status",
|
||||
},
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_passenger_door",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777123_passenger_door_status",
|
||||
},
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_hatch",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777123_hatch_status",
|
||||
},
|
||||
],
|
||||
Platform.BUTTON: [
|
||||
{
|
||||
@ -604,12 +680,51 @@ MOCK_VEHICLES = {
|
||||
True, # location
|
||||
# Ignore, # battery-status
|
||||
# Ignore, # charge-mode
|
||||
True, # lock-status
|
||||
],
|
||||
"endpoints": {
|
||||
"cockpit": "cockpit_fuel.json",
|
||||
"location": "location.json",
|
||||
"lock_status": "lock_status.1.json",
|
||||
},
|
||||
Platform.BINARY_SENSOR: [],
|
||||
Platform.BINARY_SENSOR: [
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.LOCK,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_lock",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777123_lock_status",
|
||||
},
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_rear_left_door",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777123_rear_left_door_status",
|
||||
},
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_rear_right_door",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777123_rear_right_door_status",
|
||||
},
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_driver_door",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777123_driver_door_status",
|
||||
},
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_passenger_door",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777123_passenger_door_status",
|
||||
},
|
||||
{
|
||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
|
||||
ATTR_ENTITY_ID: "binary_sensor.reg_number_hatch",
|
||||
ATTR_STATE: STATE_OFF,
|
||||
ATTR_UNIQUE_ID: "vf1aaaaa555777123_hatch_status",
|
||||
},
|
||||
],
|
||||
Platform.BUTTON: [
|
||||
{
|
||||
ATTR_ENTITY_ID: "button.reg_number_start_air_conditioner",
|
||||
|
15
tests/components/renault/fixtures/lock_status.1.json
Normal file
15
tests/components/renault/fixtures/lock_status.1.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"data": {
|
||||
"type": "Car",
|
||||
"id": "VF1AAAAA555777999",
|
||||
"attributes": {
|
||||
"lockStatus": "locked",
|
||||
"doorStatusRearLeft": "closed",
|
||||
"doorStatusRearRight": "closed",
|
||||
"doorStatusDriver": "closed",
|
||||
"doorStatusPassenger": "closed",
|
||||
"hatchStatus": "closed",
|
||||
"lastUpdateTime": "2022-02-02T13:51:13Z"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user