-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhardware.py
More file actions
36 lines (29 loc) · 1.04 KB
/
hardware.py
File metadata and controls
36 lines (29 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from config import ConfigError
class Component:
""" Base class for hardware components"""
def __init__(self, config, callback=None):
self.config = config
self.callback = callback
def set_callback(self, callback):
self.callback = callback
def connect(self):
raise NotImplemented("connect should be implemented by subcalsses of Component")
def from_config(config, callback=None):
if 'type' not in config:
raise ConfigError("No type defined for this component")
component_class = {
'button': Button,
}.get(config['type'])
if component_class is None:
raise ConfigError("Unknown hardware component type %s" % (config['type']))
return component_class(config, callback=callback)
def poll():
pass
class Button(Component):
def connect(self):
pass
# TODO read the config and figure out how
# to set an interrupt (or to start polling)
# which calls self.state_callback
def poll():
pass