2022-09-28 18:14:06 +01:00
|
|
|
import logging
|
|
|
|
|
2022-07-09 12:24:19 +01:00
|
|
|
import vban_cmd
|
|
|
|
|
|
|
|
|
|
|
|
class Observer:
|
|
|
|
def __init__(self, vban):
|
|
|
|
self.vban = vban
|
2022-08-02 09:31:41 +01:00
|
|
|
# register your app as event observer
|
|
|
|
self.vban.subject.add(self)
|
2022-10-06 16:45:15 +01:00
|
|
|
# enable level updates, since they are disabled by default.
|
|
|
|
self.vban.event.ldirty = True
|
2022-07-09 12:24:19 +01:00
|
|
|
|
2022-08-02 09:31:41 +01:00
|
|
|
# define an 'on_update' callback function to receive event updates
|
2022-07-09 12:24:19 +01:00
|
|
|
def on_update(self, subject):
|
|
|
|
if subject == "pdirty":
|
|
|
|
print("pdirty!")
|
2022-08-02 09:31:41 +01:00
|
|
|
elif subject == "ldirty":
|
2022-10-04 15:43:09 +01:00
|
|
|
for bus in self.vban.bus:
|
|
|
|
if bus.levels.isdirty:
|
|
|
|
print(bus, bus.levels.all)
|
2022-07-09 12:24:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2022-10-18 15:20:20 +01:00
|
|
|
kind_id = "potato"
|
|
|
|
|
|
|
|
with vban_cmd.api(kind_id) as vban:
|
2022-09-28 18:14:06 +01:00
|
|
|
Observer(vban)
|
2022-07-09 12:24:19 +01:00
|
|
|
|
|
|
|
while cmd := input("Press <Enter> to exit\n"):
|
|
|
|
if not cmd:
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-09-28 18:14:06 +01:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
2022-07-09 12:24:19 +01:00
|
|
|
main()
|