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