volkswagencarnet 5.0.0b3__py3-none-any.whl → 5.0.0b4__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.

@@ -0,0 +1,7 @@
1
+ """Backend specific exceptions."""
2
+
3
+
4
+ class AuthenticationException(Exception):
5
+ """Login fails for whatever reason."""
6
+
7
+ pass
@@ -1,9 +1,9 @@
1
1
  """Common utility functions."""
2
2
 
3
- from datetime import datetime
4
3
  import json
5
4
  import logging
6
5
  import re
6
+ from datetime import datetime
7
7
 
8
8
  _LOGGER = logging.getLogger(__name__)
9
9
 
@@ -19,12 +19,13 @@ 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.""" # pylint: disable=pointless-string-statement
22
+ """The value was not a date."""
23
23
  return obj
24
24
 
25
25
 
26
26
  def find_path_in_dict(src: dict | list, path: str | list) -> object:
27
- """Return data at path in dictionary source.
27
+ """
28
+ Return data at path in dictionary source.
28
29
 
29
30
  Simple navigation of a hierarchical dict structure using XPATH-like syntax.
30
31
 
@@ -64,10 +65,10 @@ def find_path_in_dict(src: dict | list, path: str | list) -> object:
64
65
  if f.is_integer() and len(src) > 0:
65
66
  return find_path_in_dict(src[int(f)], path[1:])
66
67
  raise KeyError("Key not found")
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
68
+ except ValueError:
69
+ raise KeyError(f"{path[0]} should be an integer")
70
+ except IndexError:
71
+ raise KeyError("Index out of range")
71
72
  return find_path_in_dict(src[path[0]], path[1:])
72
73
 
73
74
 
@@ -76,14 +77,13 @@ def find_path(src: dict | list, path: str | list) -> object:
76
77
  try:
77
78
  return find_path_in_dict(src, path)
78
79
  except KeyError:
79
- _LOGGER.error(
80
- "Dictionary path: %s is no longer present. Dictionary: %s", path, src
81
- )
80
+ _LOGGER.error("Dictionary path: %s is no longer present. Dictionary: %s", path, src)
82
81
  return None
83
82
 
84
83
 
85
84
  def is_valid_path(src, path):
86
- """Check if path exists in source.
85
+ """
86
+ Check if path exists in source.
87
87
 
88
88
  >>> is_valid_path(dict(a=1), 'a')
89
89
  True
@@ -105,10 +105,9 @@ def is_valid_path(src, path):
105
105
  """
106
106
  try:
107
107
  find_path_in_dict(src, path)
108
+ return True
108
109
  except KeyError:
109
110
  return False
110
- else:
111
- return True
112
111
 
113
112
 
114
113
  def camel2slug(s: str) -> str:
@@ -122,16 +121,33 @@ def camel2slug(s: str) -> str:
122
121
  return re.sub("((?<!_)[A-Z])", "_\\1", s).lower().strip("_ \n\t\r")
123
122
 
124
123
 
125
- def make_url(url: str, **kwargs: str) -> str:
126
- """Replace placeholders in a URL with given keyword arguments."""
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))
133
-
134
- # Check if any unreplaced placeholders remain
124
+ def make_url(url: str, **kwargs):
125
+ """Replace placeholders in URLs."""
126
+ for a in kwargs:
127
+ url = url.replace("{" + a + "}", str(kwargs[a]))
128
+ url = url.replace("$" + a, str(kwargs[a]))
135
129
  if "{" in url or "}" in url:
136
- raise ValueError("Not all placeholders were replaced in the URL")
130
+ raise ValueError("Not all values were substituted")
137
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)))
143
+
144
+
145
+ def vw_to_celsius(val: int) -> float:
146
+ """Convert Celsius to VW format."""
147
+ return round(2 * ((val / 10) - 273.15)) / 2
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))