pySmartHashtag 0.14.4__tar.gz → 0.15.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pysmarthashtag-0.14.4/pySmartHashtag.egg-info → pysmarthashtag-0.15.0}/PKG-INFO +1 -1
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0/pySmartHashtag.egg-info}/PKG-INFO +1 -1
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pySmartHashtag.egg-info/SOURCES.txt +3 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pySmartHashtag.egg-info/scm_file_list.json +3 -0
- pysmarthashtag-0.15.0/pySmartHashtag.egg-info/scm_version.json +8 -0
- pysmarthashtag-0.15.0/pysmarthashtag/control/charging_lid.py +80 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/control/climate.py +83 -47
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/control/telematics.py +4 -0
- pysmarthashtag-0.15.0/pysmarthashtag/tests/test_charging_lid.py +55 -0
- pysmarthashtag-0.15.0/pysmarthashtag/tests/test_charging_lid_control.py +54 -0
- pysmarthashtag-0.15.0/pysmarthashtag/tests/test_climate_zaf.py +193 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/vehicle/battery.py +9 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/vehicle/vehicle.py +11 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/requirements-test.txt +1 -1
- pysmarthashtag-0.14.4/pySmartHashtag.egg-info/scm_version.json +0 -8
- pysmarthashtag-0.14.4/pysmarthashtag/tests/test_climate_zaf.py +0 -141
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/.devcontainer.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/.github/copilot-instructions.md +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/.github/dependabot.yml +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/.github/workflows/python-package.yml +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/.github/workflows/python-publish.yml +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/.gitignore +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/.pre-commit-config.yaml +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/.vscode/launch.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/.vscode/settings.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/AUTHORS +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/CODE_OF_CONDUCT.md +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/CONTRIBUTING.md +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/ChangeLog +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/LICENSE +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/README.md +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pySmartHashtag.egg-info/dependency_links.txt +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pySmartHashtag.egg-info/requires.txt +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pySmartHashtag.egg-info/top_level.txt +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pyproject.toml +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/__init__.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/account.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/api/__init__.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/api/authentication.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/api/client.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/api/log_sanitizer.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/api/ssl_context.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/api/utils.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/cli.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/const.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/control/charging.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/control/horn_light.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/control/journal.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/control/lock.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/control/windows.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/models.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/__init__.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/common.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/conftest.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/Human_and_vehicle_relationship_does_not_exist.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/api_access.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/auth_context.url +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/auth_intermediate.url +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/auth_result.url +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/charging_success.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/climate_success.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/dc_charge_info.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/journal_response.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/journal_toggle_success.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/login_result.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/ota_response.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/soc_80.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/soc_90.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/token_expired.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/trackpoints_response.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/vehicle_info.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/vehicle_info2.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/vehicle_info_dc_charging.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/vehicle_response.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/replys/vehicle_result.json +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_account.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_actions.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_authentication_backoff.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_charging.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_charging_limit.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_charging_states.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_cli.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_climate_status.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_dc_charge_info.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_dc_charging.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_endpoint_urls.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_horn_light_control.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_journal.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_journal_control.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_journal_pagination.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_lock_control.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_log_sanitizer.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_missing_fields.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_ota_info.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_send_destination.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_ssl_context.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_token_lifecycle.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_tracked_vins.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_trackpoints.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_vehicle_state.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_vin_headers.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/tests/test_window_control.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/vehicle/__init__.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/vehicle/climate.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/vehicle/journal.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/vehicle/maintenance.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/vehicle/position.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/vehicle/running.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/vehicle/safety.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/vehicle/tires.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/vehicle/trackpoints.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/pysmarthashtag/vehicle/vehicle_state.py +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/requirements-cli.txt +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/requirements.txt +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/run.sh +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/setup.cfg +0 -0
- {pysmarthashtag-0.14.4 → pysmarthashtag-0.15.0}/setup.py +0 -0
|
@@ -39,6 +39,7 @@ pysmarthashtag/api/log_sanitizer.py
|
|
|
39
39
|
pysmarthashtag/api/ssl_context.py
|
|
40
40
|
pysmarthashtag/api/utils.py
|
|
41
41
|
pysmarthashtag/control/charging.py
|
|
42
|
+
pysmarthashtag/control/charging_lid.py
|
|
42
43
|
pysmarthashtag/control/climate.py
|
|
43
44
|
pysmarthashtag/control/horn_light.py
|
|
44
45
|
pysmarthashtag/control/journal.py
|
|
@@ -52,6 +53,8 @@ pysmarthashtag/tests/test_account.py
|
|
|
52
53
|
pysmarthashtag/tests/test_actions.py
|
|
53
54
|
pysmarthashtag/tests/test_authentication_backoff.py
|
|
54
55
|
pysmarthashtag/tests/test_charging.py
|
|
56
|
+
pysmarthashtag/tests/test_charging_lid.py
|
|
57
|
+
pysmarthashtag/tests/test_charging_lid_control.py
|
|
55
58
|
pysmarthashtag/tests/test_charging_limit.py
|
|
56
59
|
pysmarthashtag/tests/test_charging_states.py
|
|
57
60
|
pysmarthashtag/tests/test_cli.py
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"pysmarthashtag/cli.py",
|
|
28
28
|
"pysmarthashtag/const.py",
|
|
29
29
|
"pysmarthashtag/control/charging.py",
|
|
30
|
+
"pysmarthashtag/control/charging_lid.py",
|
|
30
31
|
"pysmarthashtag/control/climate.py",
|
|
31
32
|
"pysmarthashtag/control/horn_light.py",
|
|
32
33
|
"pysmarthashtag/control/journal.py",
|
|
@@ -62,6 +63,8 @@
|
|
|
62
63
|
"pysmarthashtag/tests/test_actions.py",
|
|
63
64
|
"pysmarthashtag/tests/test_authentication_backoff.py",
|
|
64
65
|
"pysmarthashtag/tests/test_charging.py",
|
|
66
|
+
"pysmarthashtag/tests/test_charging_lid.py",
|
|
67
|
+
"pysmarthashtag/tests/test_charging_lid_control.py",
|
|
65
68
|
"pysmarthashtag/tests/test_charging_limit.py",
|
|
66
69
|
"pysmarthashtag/tests/test_charging_states.py",
|
|
67
70
|
"pysmarthashtag/tests/test_cli.py",
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""Provides an accessible control of the vehicle's charging lid."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
from pysmarthashtag.account import SmartAccount
|
|
6
|
+
from pysmarthashtag.control.telematics import (
|
|
7
|
+
TELEMATICS_OPERATION_SCHEDULING,
|
|
8
|
+
build_telematics_payload,
|
|
9
|
+
send_telematics_command,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
_LOGGER = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ChargingLidControl:
|
|
16
|
+
"""Provides the opening and closing of the motorised charging lid.
|
|
17
|
+
|
|
18
|
+
Only the Smart #5 has one. Uses the remote charging lid open (RDO) and
|
|
19
|
+
close (RDC) telematics services.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
OPEN_SERVICE_ID = "RDO"
|
|
23
|
+
CLOSE_SERVICE_ID = "RDC"
|
|
24
|
+
LID_PARAMETER = {"key": "target", "value": "front-charge-lid"}
|
|
25
|
+
OPERATION_SCHEDULING = {**TELEMATICS_OPERATION_SCHEDULING, "duration": 0}
|
|
26
|
+
|
|
27
|
+
def __init__(self, account: SmartAccount, vin: str):
|
|
28
|
+
"""Initialize the charging lid control.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
----
|
|
32
|
+
account: The Smart account instance
|
|
33
|
+
vin: Vehicle identification number
|
|
34
|
+
|
|
35
|
+
"""
|
|
36
|
+
self.account = account
|
|
37
|
+
self.config = account.config
|
|
38
|
+
self.vin = vin
|
|
39
|
+
|
|
40
|
+
def _get_payload(self, service_id: str) -> str:
|
|
41
|
+
"""Create the payload for a charging lid command.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
----
|
|
45
|
+
service_id: The telematics service to call (RDO or RDC)
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
-------
|
|
49
|
+
JSON string payload for the API request
|
|
50
|
+
|
|
51
|
+
"""
|
|
52
|
+
return build_telematics_payload(
|
|
53
|
+
service_id,
|
|
54
|
+
[self.LID_PARAMETER],
|
|
55
|
+
operation_scheduling=self.OPERATION_SCHEDULING,
|
|
56
|
+
timestamp_key="timeStamp",
|
|
57
|
+
user_id=str(self.config.authentication.api_user_id),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
async def open(self) -> bool:
|
|
61
|
+
"""Open the charging lid.
|
|
62
|
+
|
|
63
|
+
Returns
|
|
64
|
+
-------
|
|
65
|
+
True if the command was accepted, False otherwise
|
|
66
|
+
|
|
67
|
+
"""
|
|
68
|
+
_LOGGER.debug("Opening the charging lid")
|
|
69
|
+
return await send_telematics_command(self.account, self.vin, self._get_payload(self.OPEN_SERVICE_ID))
|
|
70
|
+
|
|
71
|
+
async def close(self) -> bool:
|
|
72
|
+
"""Close the charging lid.
|
|
73
|
+
|
|
74
|
+
Returns
|
|
75
|
+
-------
|
|
76
|
+
True if the command was accepted, False otherwise
|
|
77
|
+
|
|
78
|
+
"""
|
|
79
|
+
_LOGGER.debug("Closing the charging lid")
|
|
80
|
+
return await send_telematics_command(self.account, self.vin, self._get_payload(self.CLOSE_SERVICE_ID))
|
|
@@ -47,7 +47,7 @@ class RearHeatingLocation(str, Enum):
|
|
|
47
47
|
# ZAF service parameter keys of the Smart #5 comfort functions
|
|
48
48
|
ZAF_HEATING_KEYS = {
|
|
49
49
|
HeatingLocation.DRIVER_SEAT: "SH.11",
|
|
50
|
-
HeatingLocation.PASSENGER_SEAT: "SH.
|
|
50
|
+
HeatingLocation.PASSENGER_SEAT: "SH.19",
|
|
51
51
|
HeatingLocation.STEERING_WHEEL: "SW",
|
|
52
52
|
}
|
|
53
53
|
ZAF_VENTILATION_KEYS = {
|
|
@@ -56,10 +56,10 @@ ZAF_VENTILATION_KEYS = {
|
|
|
56
56
|
}
|
|
57
57
|
ZAF_REAR_HEATING_KEYS = {
|
|
58
58
|
RearHeatingLocation.REAR_LEFT: "SH.21",
|
|
59
|
-
RearHeatingLocation.REAR_RIGHT: "SH.
|
|
59
|
+
RearHeatingLocation.REAR_RIGHT: "SH.29",
|
|
60
60
|
}
|
|
61
61
|
ZAF_SEAT_HEATING_DURATION = "15"
|
|
62
|
-
ZAF_ALL_COMFORT_KEYS = ("
|
|
62
|
+
ZAF_ALL_COMFORT_KEYS = ("SH.11", "SH.19", "SH.21", "SH.29", "SW", "DF", "SV.11", "SV.19")
|
|
63
63
|
|
|
64
64
|
|
|
65
65
|
class ClimateControll:
|
|
@@ -102,28 +102,37 @@ class ClimateControll:
|
|
|
102
102
|
RearHeatingLocation.REAR_RIGHT: 0,
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
def
|
|
106
|
-
"""Build the Smart #5 ZAF
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
105
|
+
def _get_zaf_payloads(self, active: bool) -> list[str]:
|
|
106
|
+
"""Build the Smart #5 ZAF requests, one per comfort function.
|
|
107
|
+
|
|
108
|
+
The cloud does not take several seats in one request, so every seat,
|
|
109
|
+
the steering wheel and the ventilation get their own request. The
|
|
110
|
+
air conditioning is not part of it. Start and stop both use
|
|
111
|
+
``command: start``.
|
|
112
|
+
"""
|
|
113
|
+
if not active:
|
|
114
|
+
return [self._build_zaf_payload({"operation": "4", key: "false"}) for key in ZAF_ALL_COMFORT_KEYS]
|
|
115
|
+
comfort = [
|
|
116
|
+
*(
|
|
117
|
+
(ZAF_HEATING_KEYS[loc], lvl, loc != HeatingLocation.STEERING_WHEEL)
|
|
118
|
+
for loc, lvl in self.heating_levels.items()
|
|
119
|
+
),
|
|
120
|
+
*((ZAF_VENTILATION_KEYS[loc], lvl, False) for loc, lvl in self.ventilation_levels.items()),
|
|
121
|
+
*((ZAF_REAR_HEATING_KEYS[loc], lvl, True) for loc, lvl in self.rear_heating_levels.items()),
|
|
122
|
+
]
|
|
123
|
+
return [
|
|
124
|
+
self._build_zaf_payload(self._zaf_level_params(key, level, with_duration))
|
|
125
|
+
for key, level, with_duration in comfort
|
|
126
|
+
if level > 0
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
@staticmethod
|
|
130
|
+
def _zaf_level_params(key: str, level: int, with_duration: bool) -> dict[str, str]:
|
|
131
|
+
"""Service parameters that switch a single comfort function on."""
|
|
132
|
+
params = {"operation": "4", key: "true", f"{key}.level": str(level)}
|
|
133
|
+
if with_duration:
|
|
134
|
+
params[f"{key}.duration"] = ZAF_SEAT_HEATING_DURATION
|
|
135
|
+
return params
|
|
127
136
|
|
|
128
137
|
def _build_zaf_payload(self, params: dict[str, str]) -> str:
|
|
129
138
|
"""Wrap ZAF service parameters in the request body. Start and stop both use ``command: start``."""
|
|
@@ -145,12 +154,22 @@ class ClimateControll:
|
|
|
145
154
|
}
|
|
146
155
|
return json.dumps(payload).replace(" ", "")
|
|
147
156
|
|
|
148
|
-
async def
|
|
149
|
-
"""Send
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
157
|
+
async def _send_zaf_commands(self, payloads: list[str]) -> bool:
|
|
158
|
+
"""Send the ZAF requests one after the other and log what was sent and answered.
|
|
159
|
+
|
|
160
|
+
Every request is sent even if an earlier one failed, so a stop always
|
|
161
|
+
tries to switch everything off. Returns True only if all were accepted.
|
|
162
|
+
"""
|
|
163
|
+
if not payloads:
|
|
164
|
+
_LOGGER.debug("No ZAF command to send")
|
|
165
|
+
return False
|
|
166
|
+
results = []
|
|
167
|
+
for params in payloads:
|
|
168
|
+
_LOGGER.debug("Sending ZAF command: %s", params)
|
|
169
|
+
result = await send_telematics_command(self.account, self.vin, params)
|
|
170
|
+
_LOGGER.debug("ZAF command result: %s", result)
|
|
171
|
+
results.append(result is True)
|
|
172
|
+
return all(results)
|
|
154
173
|
|
|
155
174
|
def set_ventilation_level(self, location: VentilationLocation, level: int):
|
|
156
175
|
"""Set the (Smart #5) seat ventilation level; selecting one clears the seat's heating."""
|
|
@@ -226,7 +245,7 @@ class ClimateControll:
|
|
|
226
245
|
|
|
227
246
|
_LOGGER.debug("Setting climate conditioning: active=%s, temp=%s", active, temp)
|
|
228
247
|
if self.use_zaf:
|
|
229
|
-
return await self.
|
|
248
|
+
return await self._send_zaf_commands(self._get_zaf_payloads(active))
|
|
230
249
|
return await self._send_rce_command(self._get_payload(active))
|
|
231
250
|
|
|
232
251
|
def _get_heating_payload(self, active: bool, levels: dict[HeatingLocation, int]) -> str:
|
|
@@ -257,6 +276,16 @@ class ClimateControll:
|
|
|
257
276
|
levels: Heating level (1-3) per location; only the keys are used to stop
|
|
258
277
|
|
|
259
278
|
"""
|
|
279
|
+
self._check_heating_request(active, levels)
|
|
280
|
+
|
|
281
|
+
_LOGGER.debug("Setting heating: active=%s, levels=%s", active, levels)
|
|
282
|
+
if self.use_zaf:
|
|
283
|
+
return await self._send_zaf_commands(self._get_zaf_heating_payloads(active, levels))
|
|
284
|
+
return await self._send_rce_command(self._get_heating_payload(active, levels))
|
|
285
|
+
|
|
286
|
+
@staticmethod
|
|
287
|
+
def _check_heating_request(active: bool, levels: dict) -> None:
|
|
288
|
+
"""Validate the arguments of set_heating / set_rear_heating."""
|
|
260
289
|
if not isinstance(active, bool):
|
|
261
290
|
raise TypeError("Heating state must be a boolean")
|
|
262
291
|
if not levels:
|
|
@@ -267,24 +296,31 @@ class ClimateControll:
|
|
|
267
296
|
if active and (level > 3 or level < 1):
|
|
268
297
|
raise ValueError("Heating level must be between 1 and 3 to start heating.")
|
|
269
298
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
return await self._send_zaf_command(self._get_zaf_heating_payload(active, levels))
|
|
273
|
-
return await self._send_rce_command(self._get_heating_payload(active, levels))
|
|
299
|
+
async def set_rear_heating(self, active: bool, levels: dict[RearHeatingLocation, int]) -> bool:
|
|
300
|
+
"""Start or stop the rear seat heating on its own (Smart #5 only).
|
|
274
301
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
302
|
+
Every seat in ``levels`` is sent as its own request, without climate conditioning.
|
|
303
|
+
The levels given here are used as-is and do not change rear_heating_levels.
|
|
304
|
+
"""
|
|
305
|
+
if not self.use_zaf:
|
|
306
|
+
raise NotImplementedError("Rear seat heating is only supported on the Smart #5")
|
|
307
|
+
self._check_heating_request(active, levels)
|
|
308
|
+
_LOGGER.debug("Setting rear heating: active=%s, levels=%s", active, levels)
|
|
309
|
+
return await self._send_zaf_commands(self._get_zaf_heating_payloads(active, levels))
|
|
310
|
+
|
|
311
|
+
def _get_zaf_heating_payloads(
|
|
312
|
+
self, active: bool, levels: dict[HeatingLocation, int] | dict[RearHeatingLocation, int]
|
|
313
|
+
) -> list[str]:
|
|
314
|
+
"""Build one Smart #5 ZAF request per seat / steering wheel in ``levels``."""
|
|
315
|
+
payloads = []
|
|
278
316
|
for loc, level in levels.items():
|
|
279
|
-
key = ZAF_HEATING_KEYS[loc]
|
|
317
|
+
key = {**ZAF_HEATING_KEYS, **ZAF_REAR_HEATING_KEYS}[loc]
|
|
280
318
|
if active:
|
|
281
|
-
params
|
|
282
|
-
params[f"{key}.level"] = str(level)
|
|
283
|
-
if loc != HeatingLocation.STEERING_WHEEL:
|
|
284
|
-
params[f"{key}.duration"] = ZAF_SEAT_HEATING_DURATION
|
|
319
|
+
params = self._zaf_level_params(key, level, loc != HeatingLocation.STEERING_WHEEL)
|
|
285
320
|
else:
|
|
286
|
-
params
|
|
287
|
-
|
|
321
|
+
params = {"operation": "4", key: "false"}
|
|
322
|
+
payloads.append(self._build_zaf_payload(params))
|
|
323
|
+
return payloads
|
|
288
324
|
|
|
289
325
|
def _get_defrost_payload(self, active: bool) -> str:
|
|
290
326
|
_payload = self.BASE_PAYLOAD_TEMPLATE.copy()
|
|
@@ -307,7 +343,7 @@ class ClimateControll:
|
|
|
307
343
|
_LOGGER.debug("Setting front windscreen defrost: active=%s", active)
|
|
308
344
|
if self.use_zaf:
|
|
309
345
|
params = {"operation": "4", "DF": "true" if active else "false"}
|
|
310
|
-
return await self.
|
|
346
|
+
return await self._send_zaf_commands([self._build_zaf_payload(params)])
|
|
311
347
|
return await self._send_rce_command(self._get_defrost_payload(active))
|
|
312
348
|
|
|
313
349
|
async def _send_rce_command(self, params: str) -> bool:
|
|
@@ -30,6 +30,7 @@ def build_telematics_payload(
|
|
|
30
30
|
command: str = "start",
|
|
31
31
|
operation_scheduling: dict[str, Any] | None = None,
|
|
32
32
|
timestamp_key: str = "timestamp",
|
|
33
|
+
user_id: str | None = None,
|
|
33
34
|
) -> str:
|
|
34
35
|
"""Create the compact JSON body of a remote telematics command.
|
|
35
36
|
|
|
@@ -40,6 +41,7 @@ def build_telematics_payload(
|
|
|
40
41
|
command: "start" or "stop"
|
|
41
42
|
operation_scheduling: Overrides the default operation scheduling
|
|
42
43
|
timestamp_key: Name of the timestamp field ("timestamp" or "timeStamp")
|
|
44
|
+
user_id: Adds a "userId" field, for the services that require it
|
|
43
45
|
|
|
44
46
|
Returns:
|
|
45
47
|
-------
|
|
@@ -54,6 +56,8 @@ def build_telematics_payload(
|
|
|
54
56
|
timestamp_key: utils.create_correct_timestamp(),
|
|
55
57
|
"serviceParameters": parameters,
|
|
56
58
|
}
|
|
59
|
+
if user_id is not None:
|
|
60
|
+
payload["userId"] = user_id
|
|
57
61
|
return json.dumps(payload).replace(" ", "")
|
|
58
62
|
|
|
59
63
|
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Tests for the charging lid status."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from pysmarthashtag.tests import RESPONSE_DIR, load_response
|
|
6
|
+
from pysmarthashtag.vehicle.battery import Battery
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def create_vehicle_data(ev_status: dict) -> dict:
|
|
10
|
+
"""Create minimal vehicle data carrying the given electric vehicle status."""
|
|
11
|
+
return {
|
|
12
|
+
"vehicleStatus": {
|
|
13
|
+
"updateTime": "1716485767970",
|
|
14
|
+
"additionalVehicleStatus": {"electricVehicleStatus": {"chargeLevel": "50", **ev_status}},
|
|
15
|
+
},
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@pytest.mark.parametrize(
|
|
20
|
+
("lid_status", "expected"),
|
|
21
|
+
[
|
|
22
|
+
("1", True),
|
|
23
|
+
("2", False),
|
|
24
|
+
("0", False),
|
|
25
|
+
],
|
|
26
|
+
)
|
|
27
|
+
def test_charging_lid_status(lid_status: str, expected: bool):
|
|
28
|
+
"""Only chargeLidDcAcStatus "1" means the lid is open."""
|
|
29
|
+
battery = Battery.from_vehicle_data(create_vehicle_data({"chargeLidDcAcStatus": lid_status}))
|
|
30
|
+
|
|
31
|
+
assert battery is not None
|
|
32
|
+
assert battery.is_charging_lid_open is expected
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.mark.parametrize("ev_status", [{}, {"chargeLidDcAcStatus": None}, {"chargeLidDcAcStatus": "n/a"}])
|
|
36
|
+
def test_charging_lid_unknown(ev_status: dict):
|
|
37
|
+
"""A vehicle that does not report the lid never reads as closed."""
|
|
38
|
+
battery = Battery.from_vehicle_data(create_vehicle_data(ev_status))
|
|
39
|
+
|
|
40
|
+
assert battery is not None
|
|
41
|
+
assert battery.is_charging_lid_open is None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@pytest.mark.parametrize(
|
|
45
|
+
("response", "expected"),
|
|
46
|
+
[
|
|
47
|
+
("vehicle_info.json", False),
|
|
48
|
+
("vehicle_info_dc_charging.json", True),
|
|
49
|
+
],
|
|
50
|
+
)
|
|
51
|
+
def test_charging_lid_from_api_response(response: str, expected: bool):
|
|
52
|
+
"""The recorded API responses report a closed lid, and an open one while DC charging."""
|
|
53
|
+
vehicle_data = load_response(RESPONSE_DIR / response)["data"]
|
|
54
|
+
|
|
55
|
+
assert Battery.from_vehicle_data(vehicle_data).is_charging_lid_open is expected
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Tests for the remote charging lid control."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
import respx
|
|
7
|
+
|
|
8
|
+
from pysmarthashtag.const import API_BASE_URL_V2
|
|
9
|
+
from pysmarthashtag.tests import RESPONSE_DIR, load_response
|
|
10
|
+
from pysmarthashtag.tests.conftest import prepare_account_with_vehicles
|
|
11
|
+
|
|
12
|
+
SMART_5_VIN = "TestVIN0000000002"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _last_telematics_payload(router: respx.Router) -> dict:
|
|
16
|
+
"""Return the JSON body of the most recent telematics PUT request."""
|
|
17
|
+
calls = [c for c in router.calls if c.request.method == "PUT" and "/vehicle/telematics/" in c.request.url.path]
|
|
18
|
+
assert calls, "No telematics request was sent"
|
|
19
|
+
return json.loads(calls[-1].request.content)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.mark.asyncio
|
|
23
|
+
@pytest.mark.parametrize(("method", "service_id"), [("open", "RDO"), ("close", "RDC")])
|
|
24
|
+
async def test_charging_lid_commands(smart_fixture: respx.Router, method: str, service_id: str):
|
|
25
|
+
"""Test that each charging lid command sends the matching telematics service."""
|
|
26
|
+
smart_fixture.put(API_BASE_URL_V2 + "/remote-control/vehicle/telematics/" + SMART_5_VIN).respond(
|
|
27
|
+
200, json=load_response(RESPONSE_DIR / "climate_success.json")
|
|
28
|
+
)
|
|
29
|
+
account = await prepare_account_with_vehicles()
|
|
30
|
+
await account.get_vehicle_information(SMART_5_VIN)
|
|
31
|
+
lid_ctrl = account.vehicles[SMART_5_VIN].charging_lid_control
|
|
32
|
+
assert lid_ctrl is not None
|
|
33
|
+
|
|
34
|
+
result = await getattr(lid_ctrl, method)()
|
|
35
|
+
|
|
36
|
+
assert result
|
|
37
|
+
payload = _last_telematics_payload(smart_fixture)
|
|
38
|
+
assert payload["serviceId"] == service_id
|
|
39
|
+
assert payload["command"] == "start"
|
|
40
|
+
assert payload["serviceParameters"] == [{"key": "target", "value": "front-charge-lid"}]
|
|
41
|
+
assert payload["userId"] == str(account.config.authentication.api_user_id)
|
|
42
|
+
assert payload["operationScheduling"]["duration"] == 0
|
|
43
|
+
assert "timeStamp" in payload
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@pytest.mark.asyncio
|
|
47
|
+
async def test_charging_lid_control_smart_5_only(smart_fixture: respx.Router):
|
|
48
|
+
"""Test that only the Smart #5 gets a charging lid control."""
|
|
49
|
+
account = await prepare_account_with_vehicles()
|
|
50
|
+
await account.get_vehicle_information("TestVIN0000000001")
|
|
51
|
+
await account.get_vehicle_information(SMART_5_VIN)
|
|
52
|
+
|
|
53
|
+
assert account.vehicles["TestVIN0000000001"].charging_lid_control is None
|
|
54
|
+
assert account.vehicles[SMART_5_VIN].charging_lid_control is not None
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"""Tests for the Smart #5 ZAF climate payload with seat ventilation."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from types import SimpleNamespace
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
from pysmarthashtag.control.climate import ClimateControll, HeatingLocation, VentilationLocation
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _ctrl(use_zaf: bool = True) -> ClimateControll:
|
|
12
|
+
account = SimpleNamespace(config=SimpleNamespace(authentication=SimpleNamespace(api_user_id=42)))
|
|
13
|
+
return ClimateControll(account, "VIN", use_zaf=use_zaf)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _params(payload: str) -> dict:
|
|
17
|
+
return {p["key"]: p["value"] for p in json.loads(payload)["serviceParameters"]}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_start_sends_each_seat_by_itself_without_ac():
|
|
21
|
+
ctrl = _ctrl()
|
|
22
|
+
ctrl.set_ventilation_level(VentilationLocation.DRIVER_SEAT, 2)
|
|
23
|
+
ctrl.set_heating_level(HeatingLocation.PASSENGER_SEAT, 3)
|
|
24
|
+
payloads = ctrl._get_zaf_payloads(True)
|
|
25
|
+
assert len(payloads) == 2
|
|
26
|
+
for raw in payloads:
|
|
27
|
+
payload = json.loads(raw)
|
|
28
|
+
assert payload["serviceId"] == "ZAF"
|
|
29
|
+
assert payload["command"] == "start"
|
|
30
|
+
assert payload["userId"] == "42"
|
|
31
|
+
assert payload["latest"] is False
|
|
32
|
+
assert [_params(p) for p in payloads] == [
|
|
33
|
+
{"operation": "4", "SH.19": "true", "SH.19.level": "3", "SH.19.duration": "15"},
|
|
34
|
+
{"operation": "4", "SV.11": "true", "SV.11.level": "2"},
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_start_without_selection_sends_nothing():
|
|
39
|
+
assert _ctrl()._get_zaf_payloads(True) == []
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_heating_and_ventilation_are_exclusive():
|
|
43
|
+
ctrl = _ctrl()
|
|
44
|
+
ctrl.set_heating_level(HeatingLocation.DRIVER_SEAT, 1)
|
|
45
|
+
ctrl.set_ventilation_level(VentilationLocation.DRIVER_SEAT, 3)
|
|
46
|
+
assert ctrl.heating_levels[HeatingLocation.DRIVER_SEAT] == 0
|
|
47
|
+
ctrl.set_heating_level(HeatingLocation.DRIVER_SEAT, 2)
|
|
48
|
+
assert ctrl.ventilation_levels[VentilationLocation.DRIVER_SEAT] == 0
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_stop_switches_every_function_off_separately():
|
|
52
|
+
ctrl = _ctrl()
|
|
53
|
+
ctrl.set_ventilation_level(VentilationLocation.DRIVER_SEAT, 2)
|
|
54
|
+
payloads = ctrl._get_zaf_payloads(False)
|
|
55
|
+
assert all(json.loads(p)["command"] == "start" for p in payloads)
|
|
56
|
+
assert [_params(p) for p in payloads] == [
|
|
57
|
+
{"operation": "4", key: "false"} for key in ("SH.11", "SH.19", "SH.21", "SH.29", "SW", "DF", "SV.11", "SV.19")
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_invalid_level_and_legacy_rejected():
|
|
62
|
+
ctrl = _ctrl()
|
|
63
|
+
with pytest.raises(ValueError):
|
|
64
|
+
ctrl.set_ventilation_level(VentilationLocation.DRIVER_SEAT, 4)
|
|
65
|
+
with pytest.raises(NotImplementedError):
|
|
66
|
+
_ctrl(use_zaf=False).set_ventilation_level(VentilationLocation.DRIVER_SEAT, 1)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_rear_heating_is_its_own_request():
|
|
70
|
+
from pysmarthashtag.control.climate import RearHeatingLocation
|
|
71
|
+
|
|
72
|
+
ctrl = _ctrl()
|
|
73
|
+
ctrl.set_rear_heating_level(RearHeatingLocation.REAR_LEFT, 2)
|
|
74
|
+
assert [_params(p) for p in ctrl._get_zaf_payloads(True)] == [
|
|
75
|
+
{"operation": "4", "SH.21": "true", "SH.21.level": "2", "SH.21.duration": "15"}
|
|
76
|
+
]
|
|
77
|
+
with pytest.raises(ValueError):
|
|
78
|
+
ctrl.set_rear_heating_level(RearHeatingLocation.REAR_LEFT, 4)
|
|
79
|
+
with pytest.raises(NotImplementedError):
|
|
80
|
+
_ctrl(use_zaf=False).set_rear_heating_level(RearHeatingLocation.REAR_LEFT, 1)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@pytest.mark.asyncio
|
|
84
|
+
async def test_stop_works_with_corrupt_temperature(monkeypatch):
|
|
85
|
+
sent = []
|
|
86
|
+
|
|
87
|
+
async def fake_send(account, vin, payload):
|
|
88
|
+
sent.append(payload)
|
|
89
|
+
return True
|
|
90
|
+
|
|
91
|
+
monkeypatch.setattr("pysmarthashtag.control.climate.send_telematics_command", fake_send)
|
|
92
|
+
ctrl = _ctrl()
|
|
93
|
+
assert await ctrl.set_climate_conditioning("garbage", False) is True
|
|
94
|
+
assert len(sent) == 8
|
|
95
|
+
assert all(v == "false" for raw in sent for k, v in _params(raw).items() if k != "operation")
|
|
96
|
+
with pytest.raises(TypeError):
|
|
97
|
+
await ctrl.set_climate_conditioning("garbage", True)
|
|
98
|
+
assert len(sent) == 8
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@pytest.mark.asyncio
|
|
102
|
+
async def test_start_sends_one_request_per_seat_and_reports_failure(monkeypatch):
|
|
103
|
+
from pysmarthashtag.control.climate import RearHeatingLocation
|
|
104
|
+
|
|
105
|
+
sent = []
|
|
106
|
+
|
|
107
|
+
async def fake_send(account, vin, payload):
|
|
108
|
+
sent.append(payload)
|
|
109
|
+
return len(sent) != 1
|
|
110
|
+
|
|
111
|
+
monkeypatch.setattr("pysmarthashtag.control.climate.send_telematics_command", fake_send)
|
|
112
|
+
ctrl = _ctrl()
|
|
113
|
+
ctrl.set_heating_level(HeatingLocation.DRIVER_SEAT, 1)
|
|
114
|
+
ctrl.set_rear_heating_level(RearHeatingLocation.REAR_LEFT, 2)
|
|
115
|
+
# the first request fails, the second is still sent
|
|
116
|
+
assert await ctrl.set_climate_conditioning(21.0, True) is False
|
|
117
|
+
assert [_params(raw) for raw in sent] == [
|
|
118
|
+
{"operation": "4", "SH.11": "true", "SH.11.level": "1", "SH.11.duration": "15"},
|
|
119
|
+
{"operation": "4", "SH.21": "true", "SH.21.level": "2", "SH.21.duration": "15"},
|
|
120
|
+
]
|
|
121
|
+
|
|
122
|
+
sent.clear()
|
|
123
|
+
assert await _ctrl().set_climate_conditioning(21.0, True) is False
|
|
124
|
+
assert sent == []
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@pytest.mark.asyncio
|
|
128
|
+
async def test_set_heating_on_smart5_uses_zaf_without_ac(monkeypatch):
|
|
129
|
+
sent = []
|
|
130
|
+
|
|
131
|
+
async def fake_send(account, vin, payload):
|
|
132
|
+
sent.append(payload)
|
|
133
|
+
return True
|
|
134
|
+
|
|
135
|
+
monkeypatch.setattr("pysmarthashtag.control.climate.send_telematics_command", fake_send)
|
|
136
|
+
ctrl = _ctrl()
|
|
137
|
+
levels = {HeatingLocation.DRIVER_SEAT: 3, HeatingLocation.PASSENGER_SEAT: 2}
|
|
138
|
+
assert await ctrl.set_heating(True, levels) is True
|
|
139
|
+
assert len(sent) == 2
|
|
140
|
+
assert json.loads(sent[0])["serviceId"] == "ZAF"
|
|
141
|
+
assert _params(sent[0]) == {"operation": "4", "SH.11": "true", "SH.11.level": "3", "SH.11.duration": "15"}
|
|
142
|
+
assert _params(sent[1]) == {"operation": "4", "SH.19": "true", "SH.19.level": "2", "SH.19.duration": "15"}
|
|
143
|
+
assert ctrl.heating_levels[HeatingLocation.DRIVER_SEAT] == 0
|
|
144
|
+
|
|
145
|
+
assert await ctrl.set_heating(False, {HeatingLocation.STEERING_WHEEL: 0}) is True
|
|
146
|
+
assert _params(sent[2]) == {"operation": "4", "SW": "false"}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
@pytest.mark.asyncio
|
|
150
|
+
async def test_set_defrost_on_smart5_uses_zaf(monkeypatch):
|
|
151
|
+
sent = []
|
|
152
|
+
|
|
153
|
+
async def fake_send(account, vin, payload):
|
|
154
|
+
sent.append(payload)
|
|
155
|
+
return True
|
|
156
|
+
|
|
157
|
+
monkeypatch.setattr("pysmarthashtag.control.climate.send_telematics_command", fake_send)
|
|
158
|
+
ctrl = _ctrl()
|
|
159
|
+
assert await ctrl.set_defrost(True) is True
|
|
160
|
+
assert json.loads(sent[0])["serviceId"] == "ZAF"
|
|
161
|
+
assert _params(sent[0]) == {"operation": "4", "DF": "true"}
|
|
162
|
+
await ctrl.set_defrost(False)
|
|
163
|
+
assert _params(sent[1]) == {"operation": "4", "DF": "false"}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
@pytest.mark.asyncio
|
|
167
|
+
async def test_set_rear_heating_sends_each_seat_by_itself(monkeypatch):
|
|
168
|
+
from pysmarthashtag.control.climate import RearHeatingLocation
|
|
169
|
+
|
|
170
|
+
sent = []
|
|
171
|
+
|
|
172
|
+
async def fake_send(account, vin, payload):
|
|
173
|
+
sent.append(payload)
|
|
174
|
+
return True
|
|
175
|
+
|
|
176
|
+
monkeypatch.setattr("pysmarthashtag.control.climate.send_telematics_command", fake_send)
|
|
177
|
+
ctrl = _ctrl()
|
|
178
|
+
levels = {RearHeatingLocation.REAR_LEFT: 2, RearHeatingLocation.REAR_RIGHT: 3}
|
|
179
|
+
assert await ctrl.set_rear_heating(True, levels) is True
|
|
180
|
+
assert [_params(raw) for raw in sent] == [
|
|
181
|
+
{"operation": "4", "SH.21": "true", "SH.21.level": "2", "SH.21.duration": "15"},
|
|
182
|
+
{"operation": "4", "SH.29": "true", "SH.29.level": "3", "SH.29.duration": "15"},
|
|
183
|
+
]
|
|
184
|
+
assert ctrl.rear_heating_levels[RearHeatingLocation.REAR_LEFT] == 0
|
|
185
|
+
|
|
186
|
+
sent.clear()
|
|
187
|
+
assert await ctrl.set_rear_heating(False, {RearHeatingLocation.REAR_RIGHT: 0}) is True
|
|
188
|
+
assert [_params(raw) for raw in sent] == [{"operation": "4", "SH.29": "false"}]
|
|
189
|
+
|
|
190
|
+
with pytest.raises(ValueError):
|
|
191
|
+
await ctrl.set_rear_heating(True, {RearHeatingLocation.REAR_LEFT: 4})
|
|
192
|
+
with pytest.raises(NotImplementedError):
|
|
193
|
+
await _ctrl(use_zaf=False).set_rear_heating(True, levels)
|