mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2024-11-15 17:10:46 +00:00
observer example updated.
some docstrings added
This commit is contained in:
parent
d12f988c7d
commit
b3267c1cbf
@ -4,20 +4,25 @@ import vban_cmd
|
|||||||
class Observer:
|
class Observer:
|
||||||
def __init__(self, vban):
|
def __init__(self, vban):
|
||||||
self.vban = vban
|
self.vban = vban
|
||||||
|
# register your app as event observer
|
||||||
|
self.vban.subject.add(self)
|
||||||
|
# add level updates, since they are disabled by default.
|
||||||
|
self.vm.event.add("ldirty")
|
||||||
|
|
||||||
|
# define an 'on_update' callback function to receive event updates
|
||||||
def on_update(self, subject):
|
def on_update(self, subject):
|
||||||
if subject == "pdirty":
|
if subject == "pdirty":
|
||||||
print("pdirty!")
|
print("pdirty!")
|
||||||
if subject == "ldirty":
|
elif subject == "ldirty":
|
||||||
info = (
|
info = (
|
||||||
f"[{self.vban.bus[0]} {self.vban.bus[0].levels.is_updated}]",
|
f"[{self.vban.bus[0]} {self.vban.bus[0].levels.isdirty}]",
|
||||||
f"[{self.vban.bus[1]} {self.vban.bus[1].levels.is_updated}]",
|
f"[{self.vban.bus[1]} {self.vban.bus[1].levels.isdirty}]",
|
||||||
f"[{self.vban.bus[2]} {self.vban.bus[2].levels.is_updated}]",
|
f"[{self.vban.bus[2]} {self.vban.bus[2].levels.isdirty}]",
|
||||||
f"[{self.vban.bus[3]} {self.vban.bus[3].levels.is_updated}]",
|
f"[{self.vban.bus[3]} {self.vban.bus[3].levels.isdirty}]",
|
||||||
f"[{self.vban.bus[4]} {self.vban.bus[4].levels.is_updated}]",
|
f"[{self.vban.bus[4]} {self.vban.bus[4].levels.isdirty}]",
|
||||||
f"[{self.vban.bus[5]} {self.vban.bus[5].levels.is_updated}]",
|
f"[{self.vban.bus[5]} {self.vban.bus[5].levels.isdirty}]",
|
||||||
f"[{self.vban.bus[6]} {self.vban.bus[6].levels.is_updated}]",
|
f"[{self.vban.bus[6]} {self.vban.bus[6].levels.isdirty}]",
|
||||||
f"[{self.vban.bus[7]} {self.vban.bus[7].levels.is_updated}]",
|
f"[{self.vban.bus[7]} {self.vban.bus[7].levels.isdirty}]",
|
||||||
)
|
)
|
||||||
print(" ".join(info))
|
print(" ".join(info))
|
||||||
|
|
||||||
@ -25,7 +30,6 @@ class Observer:
|
|||||||
def main():
|
def main():
|
||||||
with vban_cmd.api(kind_id, **opts) as vban:
|
with vban_cmd.api(kind_id, **opts) as vban:
|
||||||
obs = Observer(vban)
|
obs = Observer(vban)
|
||||||
vban.subject.add(obs)
|
|
||||||
|
|
||||||
while cmd := input("Press <Enter> to exit\n"):
|
while cmd := input("Press <Enter> to exit\n"):
|
||||||
if not cmd:
|
if not cmd:
|
||||||
|
Loading…
Reference in New Issue
Block a user