DoorPiStatus.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
import logging
5
logger = logging.getLogger(__name__)
6
logger.debug("%s loaded", __name__)
7
8
import json
9
from datetime import datetime
0 ignored issues
show
Unused Code introduced by Thomas Meissner
Unused datetime imported from datetime
Loading history...
10
11
import importlib
12
13
MODULES = [
14
    'status_time',
15
    #'additional_informations',
16
    'config',
17
    'keyboard',
18
    'sipphone',
19
    'event_handler',
20
    'history_event',
21
    'history_snapshot',
22
    #'history_action',
23
    'environment',
24
    'webserver'
25
]
26
27
def collect_status(doorpi_object, modules = MODULES, value = list(), name = list()):
28
    return DoorPiStatus(doorpi_object, modules, value, name)
29
30
class DoorPiStatus(object):
31
32
    @property
33
    def dictionary(self): return self.__status
34
35
    @property
36
    def json(self): return json.dumps(self.__status)
37
38
    @property
39
    def json_beautified(self): return json.dumps(self.__status, sort_keys=True, indent=4)
40
41
    def __init__(self, DoorPiObject, modules = MODULES, value = list(), name = list()):
42
        self.__status = {}
43
        self.collect_status(DoorPiObject, modules, value, name)
44
45
    def collect_status(self, DoorPiObject, modules = MODULES, value = list(), name = list()):
46
        if len(modules) == 0: modules = MODULES
47
48
        for module in modules:
49
            if module not in MODULES:
50
                logger.warning('skipping unknown status module %s', module)
51
                continue
52
            self.__status[module] = {}
53
            try:
54
                self.__status[module] = importlib.import_module('doorpi.status.status_lib.'+module).get(
55
                    modules = modules,
56
                    module = module,
57
                    name = name,
58
                    value = value,
59
                    DoorPiObject = DoorPiObject
60
                )
61
            except ImportError as exp:
62
                logger.exception('status %s not found @ status.status_lib.%s (msg: %s)', module, module, exp)
63
            except Exception as exp:
64
                logger.exception('status %s error (msg: %s)', module, exp)
65