diff --git a/src/renault_api/cli/renault_vehicle.py b/src/renault_api/cli/renault_vehicle.py index de118134..098c1267 100644 --- a/src/renault_api/cli/renault_vehicle.py +++ b/src/renault_api/cli/renault_vehicle.py @@ -157,6 +157,7 @@ async def display_status( await update_charge_mode(vehicle, status_table) await update_cockpit(vehicle, status_table) await update_location(vehicle, status_table) + await update_lock_status(vehicle, status_table) await update_hvac_status(vehicle, status_table) click.echo(tabulate(status_table.items())) @@ -292,6 +293,28 @@ async def update_location( update_status_table(status_table, key, value, unit) +async def update_lock_status( + vehicle: RenaultVehicle, status_table: Dict[str, Any] +) -> None: + """Update status table from get_vehicle_lock_status.""" + try: + if not await vehicle.supports_endpoint("lock-status"): + return + response = await vehicle.get_lock_status() + except QuotaLimitException as exc: # pragma: no cover + raise click.ClickException(repr(exc)) from exc + except KamereonResponseException as exc: # pragma: no cover + click.echo(f"lock status: {exc.error_details}", err=True) + else: + items = [ + ("Lock status", response.lockStatus, None), + ("Lock last updated", response.lastUpdateTime, "tzdatetime"), + ] + + for key, value, unit in items: + update_status_table(status_table, key, value, unit) + + async def update_hvac_status( vehicle: RenaultVehicle, status_table: Dict[str, str] ) -> None: diff --git a/src/renault_api/kamereon/models.py b/src/renault_api/kamereon/models.py index a3759bcc..fcab86cd 100644 --- a/src/renault_api/kamereon/models.py +++ b/src/renault_api/kamereon/models.py @@ -49,6 +49,7 @@ "X101VE": { # ZOE phase 1 "reports-in-watts": True, "support-endpoint-location": False, + "support-endpoint-lock-status": False, }, "X102VE": { # ZOE phase 2 "warns-on-method-set_ac_stop": "Action `cancel` on endpoint `hvac-start` may not be supported on this model.", # noqa @@ -65,6 +66,7 @@ "GDC": { # ZOE phase 1 "reports-in-watts": True, "support-endpoint-location": False, + "support-endpoint-lock-status": False, }, } diff --git a/tests/cli/test_vehicle.py b/tests/cli/test_vehicle.py index 59d25d3b..d22389e0 100644 --- a/tests/cli/test_vehicle.py +++ b/tests/cli/test_vehicle.py @@ -32,45 +32,51 @@ EXPECTED_STATUS = { "captur_ii.1.json": ( - "---------------- -------------------\n" - "Total mileage 5566.78 km\n" - "Fuel autonomy 35.0 km\n" - "Fuel quantity 3.0 L\n" - "GPS Latitude 48.1234567\n" - "GPS Longitude 11.1234567\n" - "GPS last updated 2020-02-18 17:58:38\n" - "---------------- -------------------\n" + "----------------- -------------------\n" + "Total mileage 5566.78 km\n" + "Fuel autonomy 35.0 km\n" + "Fuel quantity 3.0 L\n" + "GPS Latitude 48.1234567\n" + "GPS Longitude 11.1234567\n" + "GPS last updated 2020-02-18 17:58:38\n" + "Lock status locked\n" + "Lock last updated 2022-02-02 14:51:13\n" + "----------------- -------------------\n" ), "captur_ii.2.json": ( - "---------------- -------------------------\n" - "Battery level 50 %\n" - "Last updated 2020-11-17 09:06:48\n" - "Range estimate 128 km\n" - "Plug state PlugState.UNPLUGGED\n" - "Charging state ChargeState.NOT_IN_CHARGE\n" - "Charge mode always\n" - "Total mileage 5566.78 km\n" - "Fuel autonomy 35.0 km\n" - "Fuel quantity 3.0 L\n" - "GPS Latitude 48.1234567\n" - "GPS Longitude 11.1234567\n" - "GPS last updated 2020-02-18 17:58:38\n" - "---------------- -------------------------\n" + "----------------- -------------------------\n" + "Battery level 50 %\n" + "Last updated 2020-11-17 09:06:48\n" + "Range estimate 128 km\n" + "Plug state PlugState.UNPLUGGED\n" + "Charging state ChargeState.NOT_IN_CHARGE\n" + "Charge mode always\n" + "Total mileage 5566.78 km\n" + "Fuel autonomy 35.0 km\n" + "Fuel quantity 3.0 L\n" + "GPS Latitude 48.1234567\n" + "GPS Longitude 11.1234567\n" + "GPS last updated 2020-02-18 17:58:38\n" + "Lock status locked\n" + "Lock last updated 2022-02-02 14:51:13\n" + "----------------- -------------------------\n" ), "twingo_ze.1.json": ( - "---------------- -------------------------\n" - "Battery level 50 %\n" - "Last updated 2020-11-17 09:06:48\n" - "Range estimate 128 km\n" - "Plug state PlugState.UNPLUGGED\n" - "Charging state ChargeState.NOT_IN_CHARGE\n" - "Charge mode always\n" - "Total mileage 49114.27 km\n" - "GPS Latitude 48.1234567\n" - "GPS Longitude 11.1234567\n" - "GPS last updated 2020-02-18 17:58:38\n" - "HVAC status on\n" - "---------------- -------------------------\n" + "----------------- -------------------------\n" + "Battery level 50 %\n" + "Last updated 2020-11-17 09:06:48\n" + "Range estimate 128 km\n" + "Plug state PlugState.UNPLUGGED\n" + "Charging state ChargeState.NOT_IN_CHARGE\n" + "Charge mode always\n" + "Total mileage 49114.27 km\n" + "GPS Latitude 48.1234567\n" + "GPS Longitude 11.1234567\n" + "GPS last updated 2020-02-18 17:58:38\n" + "Lock status locked\n" + "Lock last updated 2022-02-02 14:51:13\n" + "HVAC status on\n" + "----------------- -------------------------\n" ), "zoe_40.1.json": ( "-------------------- -------------------------\n" @@ -99,21 +105,23 @@ "-------------------- -------------------------\n" ), "zoe_50.1.json": ( - "---------------- -------------------------\n" - "Battery level 50 %\n" - "Last updated 2020-11-17 09:06:48\n" - "Range estimate 128 km\n" - "Plug state PlugState.UNPLUGGED\n" - "Charging state ChargeState.NOT_IN_CHARGE\n" - "Charge mode always\n" - "Total mileage 5785.75 km\n" - "Fuel autonomy 0.0 km\n" - "Fuel quantity 0.0 L\n" - "GPS Latitude 48.1234567\n" - "GPS Longitude 11.1234567\n" - "GPS last updated 2020-02-18 17:58:38\n" - "HVAC status on\n" - "---------------- -------------------------\n" + "----------------- -------------------------\n" + "Battery level 50 %\n" + "Last updated 2020-11-17 09:06:48\n" + "Range estimate 128 km\n" + "Plug state PlugState.UNPLUGGED\n" + "Charging state ChargeState.NOT_IN_CHARGE\n" + "Charge mode always\n" + "Total mileage 5785.75 km\n" + "Fuel autonomy 0.0 km\n" + "Fuel quantity 0.0 L\n" + "GPS Latitude 48.1234567\n" + "GPS Longitude 11.1234567\n" + "GPS last updated 2020-02-18 17:58:38\n" + "Lock status locked\n" + "Lock last updated 2022-02-02 14:51:13\n" + "HVAC status on\n" + "----------------- -------------------------\n" ), } diff --git a/tests/fixtures.py b/tests/fixtures.py index 9344bd43..3c54e9f5 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -456,6 +456,7 @@ def inject_vehicle_status(mocked_responses: aioresponses, vehicle: str) -> None: """Inject Kamereon vehicle status data.""" inject_get_battery_status(mocked_responses) inject_get_location(mocked_responses) + inject_get_lock_status(mocked_responses) inject_get_hvac_status(mocked_responses, vehicle) inject_get_charge_mode(mocked_responses) inject_get_cockpit(mocked_responses, vehicle)