You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 171c0a6
Browse filesBrowse the repository at this point in the historyBrowse files
| command | The `OBDCommand` object that triggered this response |
6
+
| command | The `OBDCommand` object that triggered this response |
8
7
| message | The internal `Message` object containing the raw response from the car |
9
8
| time | Timestamp of response (as given by [`time.time()`](https://docs.python.org/2/library/time.html#time.time)) |
10
9
11
-
The `value` property typically contains numeric values, but can also hold complex structures (depending upon the command that was sent).
12
10
13
11
14
12
---
@@ -27,36 +25,47 @@ if not r.is_null():
27
25
---
28
26
29
27
30
-
# Units
28
+
# Values
31
29
32
-
Unit values can be found in the `Unit` class (enum).
30
+
The `value` property typically contains a [Pint](http://pint.readthedocs.io/en/latest/)`Quantity` object, but can also hold complex structures (depending on the request). Pint quantities combine a value and unit into a single class, and are used to represent physical values (such as "4 seconds", and "88 mph"). This allows for consistency when doing math and unit conversions. Pint maintains a registry of units, which is exposed in python-OBD as `obd.Unit`.
31
+
32
+
Below are common operations that can be done with Pint units and quantities. For more information, check out the [Pint Documentation](http://pint.readthedocs.io/en/latest/).
33
33
34
34
```python
35
-
from obd.utils import Unit
36
-
```
35
+
import obd
36
+
37
+
>>> response.value
38
+
<Quantity(100, 'kph')>
39
+
40
+
# get the raw python datatype
41
+
>>> response.value.magnitude
42
+
100
43
+
44
+
# converts quantities to strings
45
+
>>>str(response.value)
46
+
'100 kph'
37
47
38
-
| Name | Value |
39
-
|-------------|--------------------|
40
-
| NONE | None |
41
-
| RATIO | "Ratio" |
42
-
| COUNT | "Count" |
43
-
| PERCENT | "%" |
44
-
| RPM | "RPM" |
45
-
| VOLT | "Volt" |
46
-
| F | "F" |
47
-
| C | "C" |
48
-
| SEC | "Second" |
49
-
| MIN | "Minute" |
50
-
| PA | "Pa" |
51
-
| KPA | "kPa" |
52
-
| PSI | "psi" |
53
-
| KPH | "kph" |
54
-
| MPH | "mph" |
55
-
| DEGREES | "Degrees" |
56
-
| GPS | "Grams per Second" |
57
-
| MA | "mA" |
58
-
| KM | "km" |
59
-
| LPH | "Liters per Hour" |
48
+
# convert strings to quantities
49
+
>>> obd.Unit("100 kph")
50
+
<Quantity(100, 'kph')>
51
+
52
+
# handles conversions nicely
53
+
>>> response.value.to('mph')
54
+
<Quantity(62.13711922373341, 'mph')>
55
+
56
+
# scaler math
57
+
>>> response.value /2
58
+
<Quantity(50.0, 'kph')>
59
+
60
+
# non-scaler math requires you to specify units yourself
0 commit comments