Completed
Push — master ( 0bc61b...16fc24 )
by Thomas
8s
created

doorpi/keyboard/from_dummy.py (2 issues)

Severity
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
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
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
    def set_output(self, pin, value, log_output = True):
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