Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed remarks + implemented temperature rounding to 0,5 step
Browse files Browse the repository at this point in the history
Tomas Prvak committed Nov 8, 2024
1 parent fd69d07 commit 144a50a
Showing 8 changed files with 61 additions and 37 deletions.
4 changes: 2 additions & 2 deletions myskoda/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
wakeup,
lock,
unlock,
honk_flash
honk_flash,
)
from myskoda.cli.requests import (
air_conditioning,
@@ -45,7 +45,7 @@
status,
trip_statistics,
user,
verify_spin
verify_spin,
)
from myskoda.cli.utils import Format, print_json, print_yaml

1 change: 0 additions & 1 deletion myskoda/cli/operations.py
Original file line number Diff line number Diff line change
@@ -47,7 +47,6 @@ async def stop_air_conditioning(ctx: Context, timeout: float, vin: str) -> None:
@click.option("timeout", "--timeout", type=float, default=300)
@click.argument("vin")
@click.pass_context
#@mqtt_required NOTE: 08/11/2024 - no response is published in MQTT (maybe bug in MySkoda api?) so we don't need MQTT
async def start_auxiliary_heating(
ctx: Context,
temperature: float,
2 changes: 1 addition & 1 deletion myskoda/cli/requests.py
Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@ async def garage(ctx: Context, anonymize: bool) -> None:
@click.option("anonymize", "--anonymize", help="Strip all personal data.", is_flag=True)
@click.pass_context
async def verify_spin(ctx: Context, spin: str, anonymize: bool) -> None:
"""Verify S-PIN"""
"""Verify S-PIN."""
await handle_request(ctx, ctx.obj["myskoda"].verify_spin, spin, anonymize)


17 changes: 10 additions & 7 deletions myskoda/models/spin.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
"""Models for responses of api/v2/garage/vehicles/{vin}."""
"""Models for responses of api/v1/spin/verify."""

import logging
from dataclasses import dataclass, field
from enum import StrEnum

from mashumaro import field_options
from mashumaro.mixins.orjson import DataClassORJSONMixin

_LOGGER = logging.getLogger(__name__)

class VerificationStatus(StrEnum):
"""List of known statuses for SPIN."""

CORRECT_SPIN = "CORRECT_SPIN"
INCORRECT_SPIN = "INCORRECT_SPIN"

@dataclass
class SpinStatus(DataClassORJSONMixin):
state: str
remainingTries: int
lockedWaitingTimeInSeconds: int
remaining_tries: int = field(metadata=field_options(alias="remainingTries"))
locked_waiting_time_in_seconds: int = field(
metadata=field_options(alias="lockedWaitingTimeInSeconds"))

@dataclass
class Spin(DataClassORJSONMixin):
verificationStatus: VerificationStatus
spinStatus: SpinStatus | None = field(default=None)
verification_status: VerificationStatus = field(
metadata=field_options(alias="verificationStatus"))
spin_status: SpinStatus | None = field(default=None,
metadata=field_options(alias="spinStatus"))
6 changes: 3 additions & 3 deletions myskoda/myskoda.py
Original file line number Diff line number Diff line change
@@ -218,16 +218,16 @@ async def stop_air_conditioning(self, vin: str) -> None:
await self.rest_api.stop_air_conditioning(vin)
await future

async def start_auxiliary_heating(self, vin: str, temperature: float, spin: str = "") -> None:
async def start_auxiliary_heating(self, vin: str, temperature: float, spin: str) -> None:
"""Start the auxiliary heating with the provided target temperature in °C."""
# NOTE: 08/11/2024 - no response is published in MQTT (maybe bug in MySkoda api?) so we don't wait
# NOTE: 08/11/2024 - no response is published in MQTT (maybe bug in api?) so we don't wait
# future = self._wait_for_operation(OperationName.START_AUXILIARY_HEATING)
await self.rest_api.start_auxiliary_heating(vin, temperature, spin)
# await future

async def stop_auxiliary_heating(self, vin: str) -> None:
"""Stop the auxiliary heating."""
# NOTE: 08/11/2024 - no response is published in MQTT (maybe bug in MySkoda api?) so we don't wait
# NOTE: 08/11/2024 - no response is published in MQTT (maybe bug in api?) so we don't wait
# future = self._wait_for_operation(OperationName.STOP_AUXILIARY_HEATING)
await self.rest_api.stop_auxiliary_heating(vin)
# await future
19 changes: 11 additions & 8 deletions myskoda/rest_api.py
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ async def _make_put_request(self, url: str, json: dict | None = None) -> str:

async def verify_spin(self, spin: str, anonymize: bool = False) -> GetEndpointResult[Spin]:
"""Verify SPIN."""
url = f"/v1/spin/verify"
url = "/v1/spin/verify"
json_data = {"currentSpin": spin}
raw = self.process_json(
data=await self._make_post_request(url, json_data),
@@ -264,15 +264,16 @@ async def stop_air_conditioning(self, vin: str) -> None:

async def start_air_conditioning(self, vin: str, temperature: float) -> None:
"""Start the air conditioning."""
round_temp = f"{round(temperature * 2) / 2:.1f}"
_LOGGER.debug(
"Starting air conditioning for vehicle %s with temperature %s",
vin,
str(temperature),
round_temp,
)
json_data = {
"heaterSource": "ELECTRIC",
"targetTemperature": {
"temperatureValue": str(temperature),
"temperatureValue": round_temp,
"unitInCar": "CELSIUS",
},
}
@@ -286,19 +287,20 @@ async def stop_auxiliary_heating(self, vin: str) -> None:
_LOGGER.debug("Stopping auxiliary heating for vehicle %s", vin)
await self._make_post_request(url=f"/v2/air-conditioning/{vin}/auxiliary-heating/stop")

async def start_auxiliary_heating(self, vin: str, temperature: float, spin: str = "") -> None:
async def start_auxiliary_heating(self, vin: str, temperature: float, spin: str) -> None:
"""Start the auxiliary heating."""
round_temp = f"{round(temperature * 2) / 2:.1f}"
_LOGGER.debug(
"Starting auxiliary heating for vehicle %s with temperature %s",
vin,
str(temperature),
round_temp,
)
json_data = {
"heaterSource": "AUTOMATIC",
"airConditioningWithoutExternalPower": True,
"spin": spin,
"targetTemperature": {
"temperatureValue": str(temperature),
"temperatureValue": round_temp,
"unitInCar": "CELSIUS",
},
}
@@ -309,8 +311,9 @@ async def start_auxiliary_heating(self, vin: str, temperature: float, spin: str

async def set_target_temperature(self, vin: str, temperature: float) -> None:
"""Set the air conditioning's target temperature in °C."""
_LOGGER.debug("Setting target temperature for vehicle %s to %s", vin, str(temperature))
json_data = {"temperatureValue": str(temperature), "unitInCar": "CELSIUS"}
round_temp = f"{round(temperature * 2) / 2:.1f}"
_LOGGER.debug("Setting target temperature for vehicle %s to %s", vin, round_temp)
json_data = {"temperatureValue": round_temp, "unitInCar": "CELSIUS"}
await self._make_post_request(
url=f"/v2/air-conditioning/{vin}/settings/target-temperature",
json=json_data,
34 changes: 25 additions & 9 deletions tests/test_operations.py
Original file line number Diff line number Diff line change
@@ -33,9 +33,14 @@ async def test_stop_air_conditioning(


@pytest.mark.asyncio
@pytest.mark.parametrize("temperature", [21.5, 23.5, 10])
@pytest.mark.parametrize(("temperature", "expected"),
[(21.5, "21.5"), (23.2, "23.0"), (10.01, "10.0")])
async def test_start_air_conditioning(
responses: aioresponses, mqtt_client: MQTTClient, myskoda: MySkoda, temperature: float
responses: aioresponses,
mqtt_client: MQTTClient,
myskoda: MySkoda,
temperature: float,
expected: str
) -> None:
url = f"{BASE_URL_SKODA}/api/v2/air-conditioning/{VIN}/start"
responses.post(url=url)
@@ -52,15 +57,20 @@ async def test_start_air_conditioning(
headers={"authorization": f"Bearer {ACCESS_TOKEN}"},
json={
"heaterSource": "ELECTRIC",
"targetTemperature": {"temperatureValue": f"{temperature}", "unitInCar": "CELSIUS"},
"targetTemperature": {"temperatureValue": f"{expected}", "unitInCar": "CELSIUS"},
},
)


@pytest.mark.asyncio
@pytest.mark.parametrize("temperature", [21.5, 23.5, 10])
@pytest.mark.parametrize(("temperature", "expected"),
[(21.5, "21.5"), (23.2, "23.0"), (10.01, "10.0")])
async def test_set_target_temperature(
responses: aioresponses, mqtt_client: MQTTClient, myskoda: MySkoda, temperature: float
responses: aioresponses,
mqtt_client: MQTTClient,
myskoda: MySkoda,
temperature: float,
expected: str
) -> None:
url = f"{BASE_URL_SKODA}/api/v2/air-conditioning/{VIN}/settings/target-temperature"
responses.post(url=url)
@@ -77,7 +87,7 @@ async def test_set_target_temperature(
url=url,
method="POST",
headers={"authorization": f"Bearer {ACCESS_TOKEN}"},
json={"temperatureValue": f"{temperature}", "unitInCar": "CELSIUS"},
json={"temperatureValue": f"{expected}", "unitInCar": "CELSIUS"},
)


@@ -374,9 +384,15 @@ async def test_stop_auxiliary_heater(


@pytest.mark.asyncio
@pytest.mark.parametrize(("temperature", "spin"), [(21.5,"1234"), (23.5,"1234"), (10,"1234")])
@pytest.mark.parametrize(("temperature", "expected", "spin"),
[(21.5, "21.5", "1234"), (23.2, "23.0", "1234"), (10.01, "10.0", "1234")])
async def test_start_auxiliary_heater(
responses: aioresponses, mqtt_client: MQTTClient, myskoda: MySkoda, temperature: float, spin: str
responses: aioresponses,
mqtt_client: MQTTClient,
myskoda: MySkoda,
temperature: float,
expected: str,
spin: str
) -> None:
url = f"{BASE_URL_SKODA}/api/v2/air-conditioning/{VIN}/auxiliary-heating/start"
responses.post(url=url)
@@ -395,6 +411,6 @@ async def test_start_auxiliary_heater(
"heaterSource": "AUTOMATIC",
"airConditioningWithoutExternalPower": True,
"spin": spin,
"targetTemperature": {"temperatureValue": f"{temperature}", "unitInCar": "CELSIUS"},
"targetTemperature": {"temperatureValue": f"{expected}", "unitInCar": "CELSIUS"},
},
)
15 changes: 9 additions & 6 deletions tests/test_rest_api.py
Original file line number Diff line number Diff line change
@@ -236,13 +236,16 @@ async def test_get_spin_status(
spin_status_json = json.loads(spin_status)

responses.post(
url=f"https://mysmob.api.connect.skoda-auto.cz/api/v1/spin/verify",
url="https://mysmob.api.connect.skoda-auto.cz/api/v1/spin/verify",
body=spin_status,
)
get_spin_status_result = await myskoda.verify_spin(spin)

assert get_spin_status_result.verificationStatus == spin_status_json["verificationStatus"]
if get_spin_status_result.spinStatus is not None:
assert get_spin_status_result.spinStatus.remainingTries == spin_status_json["spinStatus"]["remainingTries"]
assert get_spin_status_result.spinStatus.lockedWaitingTimeInSeconds == spin_status_json["spinStatus"]["lockedWaitingTimeInSeconds"]
assert get_spin_status_result.spinStatus.state == spin_status_json["spinStatus"]["state"]
assert get_spin_status_result.verification_status == spin_status_json["verificationStatus"]
if get_spin_status_result.spin_status is not None:
assert (get_spin_status_result.spin_status.remaining_tries
== spin_status_json["spinStatus"]["remainingTries"])
assert (get_spin_status_result.spin_status.locked_waiting_time_in_seconds
== spin_status_json["spinStatus"]["lockedWaitingTimeInSeconds"])
assert (get_spin_status_result.spin_status.state
== spin_status_json["spinStatus"]["state"])

0 comments on commit 144a50a

Please sign in to comment.