forked from victronenergy/dbus_generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_utils.py
78 lines (63 loc) · 1.72 KB
/
gen_utils.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
dummy = {'code': None, 'whenToLog': 'configChange', 'accessLevel': None}
class BaseEnum(object):
@classmethod
def lookup(klass, v):
return klass._lookup[v]
def enum(**kw):
c = type('Enum', (BaseEnum,), kw)
c._lookup = { x.lower(): y for x, y in kw.iteritems() }
return c
class Errors:
NONE, REMOTEDISABLED, REMOTEINFAULT = range(3)
@staticmethod
def get_description(value):
description = [
'No error',
'Remote control disabled',
'Remote in fault condition']
d = ''
try:
d = description[value]
except IndexError:
pass
return d
class States:
STOPPED = 0
RUNNING = 1
ERROR = 10
@staticmethod
def get_description(value):
description = [
'Stopped',
'Running',
'Error']
d = ''
try:
d = description[value]
except IndexError:
pass
return d
class SettingsPrefix:
def __init__(self, settings, prefix):
self._settings = settings
self._prefix = prefix
def removeprefix(self, setting):
return setting.replace(self._prefix, "")
def __getitem__(self, setting):
return self._settings[setting + self._prefix]
def __setitem__(self, setting, value):
self._settings[setting + self._prefix] = value
class DBusServicePrefix:
def __init__(self, service, prefix):
self._service = service
self._prefix = "/" + prefix
def add_path(self, path, value, description="", writeable=False,
onchangecallback=None, gettextcallback=None):
self._service.add_path(self._prefix + path, value, description,
writeable, onchangecallback, gettextcallback)
def __delitem__(self, path):
self._service.__delitem__(self._prefix + path)
def __getitem__(self, path):
return self._service[self._prefix + path]
def __setitem__(self, path, value):
self._service[self._prefix + path] = value