Skip to content

Commit

Permalink
Integrate OscInterface with Config
Browse files Browse the repository at this point in the history
  • Loading branch information
nocarryr committed Jan 27, 2017
1 parent e2023a1 commit 298ac8a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/test_osc.py
Expand Up @@ -184,3 +184,30 @@ async def wait(self):

await client.stop()
await interface.stop()

@pytest.mark.asyncio
async def test_interface_config(tempconfig):
from vidhubcontrol.config import Config
from vidhubcontrol.backends.dummy import DummyBackend
from vidhubcontrol.interfaces.osc.interface import OscInterface

config = Config.load(str(tempconfig))
interface = OscInterface(config=config)

await config.start()
await interface.start()

vidhub = await DummyBackend.create_async(device_id='foo')
config.add_vidhub(vidhub)

while 'foo' not in interface.vidhubs:
await asyncio.sleep(.1)

vidhub_node = interface.root_node.find('vidhubs/by-id/foo')

for i in range(vidhub.num_outputs):
assert vidhub_node.find('crosspoints/{}'.format(i)) is not None
assert vidhub_node.find('labels/output/{}'.format(i)) is not None

for i in range(vidhub.num_inputs):
assert vidhub_node.find('labels/input/{}'.format(i)) is not None
15 changes: 15 additions & 0 deletions vidhubcontrol/interfaces/osc/interface.py
Expand Up @@ -30,8 +30,11 @@ class OscInterface(Dispatcher):
iface_name = Property()
hostport = Property(9000)
hostiface = Property()
config = Property()
vidhubs = DictProperty(copy_on_change=True)
def __init__(self, **kwargs):
self.bind(config=self.on_config)
self.config = kwargs.get('config')
self.iface_name = kwargs.get('iface_name')
self.hostport = kwargs.get('hostport', 9000)
hostaddr = kwargs.get('hostaddr')
Expand Down Expand Up @@ -75,6 +78,18 @@ async def stop(self):
if self.server is not None:
await self.server.stop()
self.server = None
def on_config(self, instance, config, **kwargs):
if config is None:
return
self.update_config_vidhubs()
config.bind(vidhubs=self.update_config_vidhubs)
def update_config_vidhubs(self, *args, **kwargs):
for vidhub_conf in self.config.vidhubs.values():
if vidhub_conf.device_id is None:
continue
vidhub = vidhub_conf.backend
asyncio.ensure_future(self.add_vidhub(vidhub))


class VidhubNode(OscNode):
_info_properties = [
Expand Down

0 comments on commit 298ac8a

Please sign in to comment.