Modes   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 1
c 3
b 0
f 0
dl 0
loc 21
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 15 1
1
from obdlib.obd.pids import *
2
3
# OBD Modes (described in OBD-II standard SAE J1979)
4
CURRENT_DATA = 1
5
FREEZE_FRAME_DATA = 2
6
REQUEST_TROUBLE_CODES = 3
7
CLEAR_TROUBLE_CODES_AND_VALUES = "04"
8
OXYGEN_SENSOR_DATA = "05"
9
SYSTEM_MONITORING_DATA = "06"
10
PENDING_TROUBLE_CODES = "07"
11
CONTROL_OPERATION = "08"
12
VEHICLE_INFORMATION_DATA = 9
13
PERMANENT_TROUBLE_CODES = "0A"
14
15
DEFAULT_OBD_MODE = CURRENT_DATA
16
17
18
class DictModes(dict):
19
    pids = None
20
21
    def __getitem__(self, key):
22
        """
23
            Override the base getitem method,
24
            because we need to set a mode before
25
            retrieves value of dict
26
        """
27
        # sets current mode
28
        DictModes.pids.set_mode(key)
29
        val = dict.__getitem__(self, key)
30
        return val
31
32
33
class Modes(object):
34
    """
35
        Provides list of OBD modes
36
    """
37
    __slots__ = ['modes']
38
39
    def __init__(self, units):
40
        set_unit(units)
41
        # In order to choose right pid you
42
        # need to do next request (ex: get engine coolant temperature -
43
        # self.modes[1][5])
44
        DictModes.pids = Pids()
45
        pre_dict = {
46
            # Current data - 01
47
            CURRENT_DATA: DictModes.pids,
48
            # Trouble codes
49
            REQUEST_TROUBLE_CODES: DictModes.pids,
50
            # Common info
51
            VEHICLE_INFORMATION_DATA: DictModes.pids
52
        }
53
        self.modes = DictModes(pre_dict)