clean up
This commit is contained in:
@ -71,37 +71,35 @@ class BSCache:
|
||||
new_chans = {}
|
||||
for name, kwargs in names.items():
|
||||
if name not in FIXED_CHANNELS and name not in self.channels:
|
||||
if not is_available(name):
|
||||
raise ValueError(f"channel {name} is not available")
|
||||
check_availability(name)
|
||||
cfg = make_channel_config(name, *kwargs)
|
||||
new_chans[name] = cfg
|
||||
|
||||
self.update_source_multiple(new_chans)
|
||||
if new_chans:
|
||||
print("add new channels", sorted(new_chans))
|
||||
self.add_vars(new_chans)
|
||||
|
||||
return {n: BSVar(n, self) for n in names}
|
||||
|
||||
|
||||
def update_source_multiple(self, chans):
|
||||
self.stop()
|
||||
print("add channels", sorted(chans))
|
||||
self.channels.update(chans)
|
||||
self.start()
|
||||
|
||||
|
||||
def get_var(self, name, modulo=None, offset=None):
|
||||
if name not in FIXED_CHANNELS and name not in self.channels:
|
||||
if not is_available(name):
|
||||
raise ValueError(f"channel {name} is not available")
|
||||
check_availability(name)
|
||||
cfg = make_channel_config(name, modulo, offset)
|
||||
self.update_source(name, cfg)
|
||||
print("add new channel", name)
|
||||
self.add_var(name, cfg)
|
||||
return BSVar(name, self)
|
||||
|
||||
|
||||
def update_source(self, name, cfg):
|
||||
def add_vars(self, chans):
|
||||
self.stop()
|
||||
print("add channel", name)
|
||||
self.channels[name] = cfg
|
||||
self.channels.update(chans)
|
||||
self.start()
|
||||
|
||||
def add_var(self, name, cfg):
|
||||
self.stop()
|
||||
self.channels[name] = cfg
|
||||
self.start()
|
||||
|
||||
def rem_vars(self, names):
|
||||
self.stop()
|
||||
@ -117,12 +115,17 @@ class BSCache:
|
||||
def clear_vars(self):
|
||||
self.stop()
|
||||
self.channels.clear()
|
||||
# cannot start without any channel
|
||||
|
||||
def flush(self):
|
||||
self.pt.queue.clear()
|
||||
|
||||
|
||||
|
||||
def check_availability(name):
|
||||
if not is_available(name):
|
||||
raise ValueError(f"channel {name} is not available")
|
||||
|
||||
def is_available(name):
|
||||
available = get_available_channels()
|
||||
return name in available
|
||||
|
Reference in New Issue
Block a user