DUMMY   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 50
Duplicated Lines 28 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 14
loc 50
rs 10
c 1
b 0
f 0
wmc 12

4 Methods

Rating   Name   Duplication   Size   Complexity  
B set_output() 14 14 5
A __init__() 0 16 2
A destroy() 0 9 3
A status_input() 0 5 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
from doorpi.keyboard.AbstractBaseClass import KeyboardAbstractBaseClass, HIGH_LEVEL, LOW_LEVEL
9
import doorpi
10
11
def get(**kwargs): return DUMMY(**kwargs)
12
class DUMMY(KeyboardAbstractBaseClass):
13
    name = 'DUMMY Keyboard'
14
15
    def __init__(self, input_pins, output_pins, keyboard_name, bouncetime = 200, polarity = 0, *args, **kwargs):
0 ignored issues
show
Unused Code introduced by
The argument args seems to be unused.
Loading history...
16
        logger.debug("__init__(input_pins = %s, output_pins = %s, bouncetime = %s, polarity = %s)",
17
                     input_pins, output_pins, bouncetime, polarity)
18
19
        conf_pre = kwargs['conf_pre']
20
        conf_post = kwargs['conf_post']
21
22
        self.keyboard_name = keyboard_name
23
        self._polarity = polarity
24
        self._InputPins = doorpi.DoorPi().config.get_keys(conf_pre+'InputPins'+conf_post)
25
        self._OutputPins = doorpi.DoorPi().config.get_keys(conf_pre+'OutputPins'+conf_post)
26
27
        for output_pin in self._OutputPins:
28
            self.set_output(output_pin, 0, False)
29
30
        self.register_destroy_action()
31
32
    def destroy(self):
33
        if self.is_destroyed: return
34
35
        logger.debug("destroy")
36
        # shutdown all output-pins
37
        for output_pin in self._OutputPins:
38
            self.set_output(output_pin, 0, False)
39
        doorpi.DoorPi().event_handler.unregister_source(__name__, True)
40
        self.__destroyed = True
41
42
    def status_input(self, pin):
0 ignored issues
show
Unused Code introduced by
The argument pin seems to be unused.
Loading history...
43
        if self._polarity is 0:
44
            return str(0).lower() in HIGH_LEVEL
45
        else:
46
            return str(0).lower() in LOW_LEVEL
47
48 View Code Duplication
    def set_output(self, pin, value, log_output = True):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
49
        parsed_pin = doorpi.DoorPi().parse_string("!"+str(pin)+"!")
50
        if parsed_pin != "!"+str(pin)+"!":
51
            pin = parsed_pin
52
53
        value = str(value).lower() in HIGH_LEVEL
54
        if self._polarity is 1: value = not value
55
        log_output = str(log_output).lower() in HIGH_LEVEL
56
57
        if pin not in self._OutputPins: return False
58
        if log_output: logger.debug("out(pin = %s, value = %s, log_output = %s)", pin, value, log_output)
59
60
        self._OutputStatus[pin] = value
61
        return True
62