volkswagencarnet 5.0.0b4__py3-none-any.whl → 5.0.0b5__py3-none-any.whl
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.
Potentially problematic release.
This version of volkswagencarnet might be problematic. Click here for more details.
- volkswagencarnet/version.py +1 -1
- volkswagencarnet/vw_connection.py +489 -398
- volkswagencarnet/vw_const.py +1 -1
- volkswagencarnet/vw_dashboard.py +548 -139
- volkswagencarnet/vw_utilities.py +24 -40
- volkswagencarnet/vw_vehicle.py +1712 -687
- {volkswagencarnet-5.0.0b4.dist-info → volkswagencarnet-5.0.0b5.dist-info}/METADATA +5 -5
- volkswagencarnet-5.0.0b5.dist-info/RECORD +12 -0
- volkswagencarnet/vw_exceptions.py +0 -7
- volkswagencarnet-5.0.0b4.dist-info/RECORD +0 -13
- {volkswagencarnet-5.0.0b4.dist-info → volkswagencarnet-5.0.0b5.dist-info}/LICENSE.txt +0 -0
- {volkswagencarnet-5.0.0b4.dist-info → volkswagencarnet-5.0.0b5.dist-info}/WHEEL +0 -0
- {volkswagencarnet-5.0.0b4.dist-info → volkswagencarnet-5.0.0b5.dist-info}/top_level.txt +0 -0
volkswagencarnet/vw_utilities.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"""Common utility functions."""
|
|
2
2
|
|
|
3
|
+
from datetime import datetime
|
|
3
4
|
import json
|
|
4
5
|
import logging
|
|
5
6
|
import re
|
|
6
|
-
from datetime import datetime
|
|
7
7
|
|
|
8
8
|
_LOGGER = logging.getLogger(__name__)
|
|
9
9
|
|
|
@@ -19,13 +19,12 @@ def obj_parser(obj: dict) -> dict:
|
|
|
19
19
|
try:
|
|
20
20
|
obj[key] = datetime.strptime(val, "%Y-%m-%dT%H:%M:%S%z")
|
|
21
21
|
except (TypeError, ValueError):
|
|
22
|
-
"""The value was not a date."""
|
|
22
|
+
"""The value was not a date.""" # pylint: disable=pointless-string-statement
|
|
23
23
|
return obj
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
def find_path_in_dict(src: dict | list, path: str | list) -> object:
|
|
27
|
-
"""
|
|
28
|
-
Return data at path in dictionary source.
|
|
27
|
+
"""Return data at path in dictionary source.
|
|
29
28
|
|
|
30
29
|
Simple navigation of a hierarchical dict structure using XPATH-like syntax.
|
|
31
30
|
|
|
@@ -65,10 +64,10 @@ def find_path_in_dict(src: dict | list, path: str | list) -> object:
|
|
|
65
64
|
if f.is_integer() and len(src) > 0:
|
|
66
65
|
return find_path_in_dict(src[int(f)], path[1:])
|
|
67
66
|
raise KeyError("Key not found")
|
|
68
|
-
except ValueError:
|
|
69
|
-
raise KeyError(f"{path[0]} should be an integer")
|
|
70
|
-
except IndexError:
|
|
71
|
-
raise KeyError("Index out of range")
|
|
67
|
+
except ValueError as valerr:
|
|
68
|
+
raise KeyError(f"{path[0]} should be an integer") from valerr
|
|
69
|
+
except IndexError as idxerr:
|
|
70
|
+
raise KeyError("Index out of range") from idxerr
|
|
72
71
|
return find_path_in_dict(src[path[0]], path[1:])
|
|
73
72
|
|
|
74
73
|
|
|
@@ -77,13 +76,14 @@ def find_path(src: dict | list, path: str | list) -> object:
|
|
|
77
76
|
try:
|
|
78
77
|
return find_path_in_dict(src, path)
|
|
79
78
|
except KeyError:
|
|
80
|
-
_LOGGER.error(
|
|
79
|
+
_LOGGER.error(
|
|
80
|
+
"Dictionary path: %s is no longer present. Dictionary: %s", path, src
|
|
81
|
+
)
|
|
81
82
|
return None
|
|
82
83
|
|
|
83
84
|
|
|
84
85
|
def is_valid_path(src, path):
|
|
85
|
-
"""
|
|
86
|
-
Check if path exists in source.
|
|
86
|
+
"""Check if path exists in source.
|
|
87
87
|
|
|
88
88
|
>>> is_valid_path(dict(a=1), 'a')
|
|
89
89
|
True
|
|
@@ -105,9 +105,10 @@ def is_valid_path(src, path):
|
|
|
105
105
|
"""
|
|
106
106
|
try:
|
|
107
107
|
find_path_in_dict(src, path)
|
|
108
|
-
return True
|
|
109
108
|
except KeyError:
|
|
110
109
|
return False
|
|
110
|
+
else:
|
|
111
|
+
return True
|
|
111
112
|
|
|
112
113
|
|
|
113
114
|
def camel2slug(s: str) -> str:
|
|
@@ -121,33 +122,16 @@ def camel2slug(s: str) -> str:
|
|
|
121
122
|
return re.sub("((?<!_)[A-Z])", "_\\1", s).lower().strip("_ \n\t\r")
|
|
122
123
|
|
|
123
124
|
|
|
124
|
-
def make_url(url: str, **kwargs):
|
|
125
|
-
"""Replace placeholders in
|
|
126
|
-
for a in kwargs:
|
|
127
|
-
url = url.replace("{" + a + "}", str(kwargs[a]))
|
|
128
|
-
url = url.replace("$" + a, str(kwargs[a]))
|
|
129
|
-
if "{" in url or "}" in url:
|
|
130
|
-
raise ValueError("Not all values were substituted")
|
|
131
|
-
return url
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
# TODO: is VW using 273.15 or 273? :)
|
|
135
|
-
def celsius_to_vw(val: float) -> int:
|
|
136
|
-
"""Convert Celsius to VW format."""
|
|
137
|
-
return int(5 * round(2 * (273.15 + val)))
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
def fahrenheit_to_vw(val: float) -> int:
|
|
141
|
-
"""Convert Fahrenheit to VW format."""
|
|
142
|
-
return int(5 * round(2 * (273.15 + (val - 32) * 5 / 9)))
|
|
125
|
+
def make_url(url: str, **kwargs: str) -> str:
|
|
126
|
+
"""Replace placeholders in a URL with given keyword arguments."""
|
|
143
127
|
|
|
128
|
+
# Replace both `{key}` and `$key` in the URL
|
|
129
|
+
for key, value in kwargs.items():
|
|
130
|
+
placeholder1 = f"{{{key}}}"
|
|
131
|
+
placeholder2 = f"${key}"
|
|
132
|
+
url = url.replace(placeholder1, str(value)).replace(placeholder2, str(value))
|
|
144
133
|
|
|
145
|
-
|
|
146
|
-
""
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
# TODO: are F ints of floats?
|
|
151
|
-
def vw_to_fahrenheit(val: int) -> int:
|
|
152
|
-
"""Convert Fahrenheit to VW format."""
|
|
153
|
-
return int(round((val / 10 - 273.15) * 9 / 5 + 32))
|
|
134
|
+
# Check if any unreplaced placeholders remain
|
|
135
|
+
if "{" in url or "}" in url:
|
|
136
|
+
raise ValueError("Not all placeholders were replaced in the URL")
|
|
137
|
+
return url
|