Fixes re: zognia's testing #2
2 changed files with 12 additions and 7 deletions
|
@ -14,6 +14,7 @@ from ovtk_audiencekit.utils import format_exception
|
||||||
class Scene:
|
class Scene:
|
||||||
name: str
|
name: str
|
||||||
group: str
|
group: str
|
||||||
|
oneshot: bool
|
||||||
enter: Callable
|
enter: Callable
|
||||||
exit: Callable
|
exit: Callable
|
||||||
entry_context: dict = field(default_factory=dict)
|
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('/<name>/<cmd>', 'api-sceneset', self.ui_setscene)
|
||||||
self.blueprint.add_url_rule('/monitor', 'monitor', self.ui_monitor_ws, is_websocket=True)
|
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:
|
if _children is None and active is None:
|
||||||
raise UsageError('Either define a new scene or set `--active` to true / false')
|
raise UsageError('Either define a new scene or set `--active` to true / false')
|
||||||
|
|
||||||
if _children:
|
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:
|
else:
|
||||||
await self.switch(name, active, is_immediate=immediate, ctx=_ctx)
|
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:
|
if self.scenes.get(name) is not None:
|
||||||
raise UsageError(f'Scene with name "{name}" already exists!')
|
raise UsageError(f'Scene with name "{name}" already exists!')
|
||||||
|
|
||||||
|
@ -63,7 +64,7 @@ class ScenePlugin(PluginBase):
|
||||||
async def exit(ctx):
|
async def exit(ctx):
|
||||||
await self.execute_kdl(exit_nodes, _ctx=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
|
self.scenes[name] = scene
|
||||||
|
|
||||||
if default_active:
|
if default_active:
|
||||||
|
@ -74,7 +75,9 @@ class ScenePlugin(PluginBase):
|
||||||
if scene is None:
|
if scene is None:
|
||||||
raise UsageError(f'No defined scene with name "{name}"')
|
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 := self.active.get(scene.group):
|
||||||
if current == scene:
|
if current == scene:
|
||||||
return
|
return
|
||||||
|
|
|
@ -24,8 +24,10 @@
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
const toggle = async (group_name, scene_name) => {
|
const toggle = async (group_name, scene_name) => {
|
||||||
|
if (!groups.value[group_name][scene_name].oneshot) {
|
||||||
if (inflight.value.includes(scene_name)) return
|
if (inflight.value.includes(scene_name)) return
|
||||||
inflight.value.push(scene_name)
|
inflight.value.push(scene_name)
|
||||||
|
}
|
||||||
const next_state = !groups.value[group_name][scene_name]
|
const next_state = !groups.value[group_name][scene_name]
|
||||||
await fetch(`${scene_name}/${next_state ? 'activate' : 'deactivate'}`, { method: 'GET' })
|
await fetch(`${scene_name}/${next_state ? 'activate' : 'deactivate'}`, { method: 'GET' })
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue