mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2025-01-18 10:30:48 +00:00
rename subject to event.
use self.observer over self.subject
This commit is contained in:
parent
37a9c88867
commit
7a3abfc372
@ -5,33 +5,30 @@ import vban_cmd
|
|||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
class Observer:
|
class App:
|
||||||
def __init__(self, vban):
|
def __init__(self, vban):
|
||||||
self.vban = vban
|
self.vban = vban
|
||||||
# register your app as event observer
|
# register your app as event observer
|
||||||
self.vban.subject.add(self)
|
self.vban.observer.add(self)
|
||||||
# enable level updates, since they are disabled by default.
|
|
||||||
self.vban.event.ldirty = True
|
|
||||||
|
|
||||||
# define an 'on_update' callback function to receive event updates
|
# define an 'on_update' callback function to receive event updates
|
||||||
def on_update(self, subject):
|
def on_update(self, event):
|
||||||
if subject == "pdirty":
|
if event == "pdirty":
|
||||||
print("pdirty!")
|
print("pdirty!")
|
||||||
elif subject == "ldirty":
|
elif event == "ldirty":
|
||||||
for bus in self.vban.bus:
|
for bus in self.vban.bus:
|
||||||
if bus.levels.isdirty:
|
if bus.levels.isdirty:
|
||||||
print(bus, bus.levels.all)
|
print(bus, bus.levels.all)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
kind_id = "potato"
|
KIND_ID = "banana"
|
||||||
|
|
||||||
with vban_cmd.api(kind_id) as vban:
|
with vban_cmd.api(KIND_ID, pdirty=True, ldirty=True) as vban:
|
||||||
Observer(vban)
|
App(vban)
|
||||||
|
|
||||||
while cmd := input("Press <Enter> to exit\n"):
|
while cmd := input("Press <Enter> to exit\n"):
|
||||||
if not cmd:
|
pass
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user