2022-09-28 18:14:06 +01:00
|
|
|
import logging
|
|
|
|
|
2022-07-09 12:24:19 +01:00
|
|
|
import vban_cmd
|
|
|
|
|
2022-10-28 20:19:05 +01:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
2022-07-09 12:24:19 +01:00
|
|
|
|
2023-06-25 14:47:48 +01:00
|
|
|
class App:
|
2022-07-09 12:24:19 +01:00
|
|
|
def __init__(self, vban):
|
|
|
|
self.vban = vban
|
2022-08-02 09:31:41 +01:00
|
|
|
# register your app as event observer
|
2023-06-25 14:47:48 +01:00
|
|
|
self.vban.observer.add(self)
|
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
|
2023-06-25 14:47:48 +01:00
|
|
|
def on_update(self, event):
|
2025-01-17 02:51:17 +00:00
|
|
|
if event == 'pdirty':
|
|
|
|
print('pdirty!')
|
|
|
|
elif event == '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():
|
2025-01-17 02:51:17 +00:00
|
|
|
KIND_ID = 'banana'
|
2022-10-18 15:20:20 +01:00
|
|
|
|
2023-06-25 14:47:48 +01:00
|
|
|
with vban_cmd.api(KIND_ID, pdirty=True, ldirty=True) as vban:
|
|
|
|
App(vban)
|
2022-07-09 12:24:19 +01:00
|
|
|
|
2025-01-17 02:51:17 +00:00
|
|
|
while _ := input('Press <Enter> to exit\n'):
|
2023-06-25 14:47:48 +01:00
|
|
|
pass
|
2022-07-09 12:24:19 +01:00
|
|
|
|
|
|
|
|
2025-01-17 02:51:17 +00:00
|
|
|
if __name__ == '__main__':
|
2022-07-09 12:24:19 +01:00
|
|
|
main()
|