Fixes re: zognia's testing #2

Merged
skeh merged 11 commits from feat/zogpog into main 2025-01-24 08:28:14 +00:00
2 changed files with 12 additions and 7 deletions
Showing only changes of commit 1e2b88f1c9 - Show all commits

View file

@ -14,6 +14,7 @@ from ovtk_audiencekit.utils import format_exception
class Scene:
name: str
group: str
oneshot: bool
enter: Callable
exit: Callable
entry_context: dict = field(default_factory=dict)
@ -35,16 +36,16 @@ class ScenePlugin(PluginBase):
self.blueprint.add_url_rule('/<name>/<cmd>', 'api-sceneset', self.ui_setscene)
self.blueprint.add_url_rule('/monitor', 'monitor', self.ui_monitor_ws, is_websocket=True)
async def run(self, name, _children=None, _ctx={}, active=None, group=None, immediate=True, **kwargs):
async def run(self, name, _children=None, _ctx={}, active=None, group=None, immediate=True, oneshot=False, **kwargs):
if _children is None and active is None:
raise UsageError('Either define a new scene or set `--active` to true / false')
if _children:
await self.define(name, group, _children, default_active=active, ctx=_ctx)
await self.define(name, group, _children, default_active=active, oneshot=oneshot, ctx=_ctx)
else:
await self.switch(name, active, is_immediate=immediate, ctx=_ctx)
async def define(self, name, group, children, default_active=False, ctx={}):
async def define(self, name, group, children, default_active=False, oneshot=False, ctx={}):
if self.scenes.get(name) is not None:
raise UsageError(f'Scene with name "{name}" already exists!')
@ -63,7 +64,7 @@ class ScenePlugin(PluginBase):
async def exit(ctx):
await self.execute_kdl(exit_nodes, _ctx=ctx)
scene = Scene(name, group, enter, exit)
scene = Scene(name, group, oneshot, enter, exit)
self.scenes[name] = scene
if default_active:
@ -74,7 +75,9 @@ class ScenePlugin(PluginBase):
if scene is None:
raise UsageError(f'No defined scene with name "{name}"')
if active:
if scene.oneshot:
await self._execute(scene, 'enter', is_immediate, ctx)
elif active:
if current := self.active.get(scene.group):
if current == scene:
return

View file

@ -24,8 +24,10 @@
})
})
const toggle = async (group_name, scene_name) => {
if (inflight.value.includes(scene_name)) return
inflight.value.push(scene_name)
if (!groups.value[group_name][scene_name].oneshot) {
if (inflight.value.includes(scene_name)) return
inflight.value.push(scene_name)
}
const next_state = !groups.value[group_name][scene_name]
await fetch(`${scene_name}/${next_state ? 'activate' : 'deactivate'}`, { method: 'GET' })
}