Skip to content

Commit

Permalink
Add lock status to CLI (#508)
Browse files Browse the repository at this point in the history
* Added update_lock_status to CLI

* Updates to supported endpoints for vehicles

NEW DUSTER does not support hvac start, instead supports engineStart.
ZOE 40 (phase 1) does not support lock-status

* Update test response for CLI

* Removed deprecated check for supported contract

* Revert extra change

* GATEWAY_SPECIFICATIONS update for Zoe phase 1

* Added mising inject_get_lock_status

* Formatting fix for tabs/spaces

* Fix typo in CLI output

* Update tests/cli/test_vehicle.py

Co-authored-by: epenet <[email protected]>

* Update tests/cli/test_vehicle.py

Co-authored-by: epenet <[email protected]>

* Update tests/cli/test_vehicle.py

Co-authored-by: epenet <[email protected]>

* Update tests/cli/test_vehicle.py

Co-authored-by: epenet <[email protected]>

* Added Lock timestamp to CLI

* Fix spaces in Status fixtures

* Fix timestamp in fixtures

Co-authored-by: epenet <[email protected]>
  • Loading branch information
FRSTR and epenet authored Feb 4, 2022
1 parent 7893fb0 commit 93d2073
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 50 deletions.
23 changes: 23 additions & 0 deletions src/renault_api/cli/renault_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions src/renault_api/kamereon/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -65,6 +66,7 @@
"GDC": { # ZOE phase 1
"reports-in-watts": True,
"support-endpoint-location": False,
"support-endpoint-lock-status": False,
},
}

Expand Down
108 changes: 58 additions & 50 deletions tests/cli/test_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
),
}

Expand Down
1 change: 1 addition & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 93d2073

Please sign in to comment.