ota-flasher/app/zeroconf_listener.py

32 lines
1 KiB
Python
Raw Normal View History

2024-05-19 00:42:36 +00:00
import wx
2024-06-09 17:38:32 +00:00
from zeroconf import Zeroconf
2024-05-19 00:42:36 +00:00
class ZeroconfListener:
2024-06-09 17:38:32 +00:00
'''Zeroconf Handler to find BTClocks in the network'''
2024-05-19 00:42:36 +00:00
release_name = ""
firmware_file = ""
def __init__(self, update_callback):
self.update_callback = update_callback
# self.update_service = update_callback
self.services = {}
def update_service(self, zc: Zeroconf, type: str, name: str) -> None:
if (name.startswith('btclock-')):
info = zc.get_service_info(type, name)
self.services[name] = info
wx.CallAfter(self.update_callback, type, name, "Added", info)
def remove_service(self, zeroconf, type, name):
if name in self.services:
del self.services[name]
wx.CallAfter(self.update_callback, type, name, "Removed")
def add_service(self, zeroconf, type, name):
if (name.startswith('btclock-')):
info = zeroconf.get_service_info(type, name)
self.services[name] = info
2024-06-09 17:38:32 +00:00
wx.CallAfter(self.update_callback, type, name, "Added", info)