-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhooks.py
69 lines (54 loc) · 2.12 KB
/
hooks.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
class Hook:
@staticmethod
def is_hook(service_name):
return service_name.startswith("class:")
def init_values(self):
...
def update_service_value(self, dbusServiceName, dbusPath, value):
...
class FixedValueHook(Hook):
def __init__(self, service_name, merger, path, value=None):
self.service_name = service_name
self.merger = merger
self.path = path
self.value = value
self.merger.data_by_path[path] = {service_name: None}
def init_values(self):
self.merger.update_service_value(self.service_name, self.path, self.value)
return [self.path]
def update_service_value(self, dbusServiceName, dbusPath, value):
return []
class CustomChargingHook(Hook):
def __init__(self, service_name, merger, ccls=None, dcls=None):
self.service_name = service_name
self.merger = merger
self.ccls = ccls
self.dcls = dcls
def init_values(self):
initial_voltage = self.merger.get_value("/Dc/0/Voltage")
return self.update_cls(initial_voltage) if initial_voltage is not None else []
def update_service_value(self, dbusServiceName, dbusPath, value):
if dbusPath == "/Dc/0/Voltage":
voltage = self.merger.get_value(dbusPath)
return self.update_cls(voltage)
else:
return []
def update_cls(self, voltage):
paths_changed = []
ccl = None
if self.ccls:
for v, cl in self.ccls.items():
if voltage >= float(v):
ccl = float(cl)
if ccl is not None:
self.merger.update_service_value(self.service_name, "/Info/MaxChargeCurrent", ccl)
paths_changed.append("/Info/MaxChargeCurrent")
dcl = None
if self.dcls:
for v, cl in self.dcls.items():
if voltage >= float(v):
dcl = float(cl)
if dcl is not None:
self.merger.update_service_value(self.service_name, "/Info/MaxDischargeCurrent", dcl)
paths_changed.append("/Info/MaxDischargeCurrent")
return paths_changed