def __init__(self, conf, logger): self._logger = logger self._client = None self._data = common.DataStorage({ 'address': conf['address'], 'components': [] })
def __init__(self, conf: json.Data, logger: common.Logger): self._logger = logger self._async_group = aio.Group() self._run_subgroup = self.async_group.create_subgroup() self._autostart_subgroup = self.async_group.create_subgroup() device_logger = common.Logger() handler = device_logger.register_log_cb(self._log) self._async_group.spawn(aio.call_on_cancel, handler.cancel) self._device = devices.create_device(conf, device_logger) self._data = common.DataStorage({'type': conf['type'], 'name': conf['name'], 'autostart': conf['autostart'], 'status': _Status.STOPPED.value, 'data': self._device.data.data}) on_change = functools.partial(self._data.set, 'data') handler = self._device.data.register_change_cb(on_change) self._async_group.spawn(aio.call_on_cancel, handler.cancel) self._log('device created') self._async_group.spawn(aio.call_on_cancel, self._log, 'removing device') if self._data.data['autostart']: self._run_autostart()
def __init__(self, conf, logger): self._logger = logger self._master = None self._data = common.DataStorage({ 'properties': conf['properties'], 'data': [] })
def __init__(self, conf, logger): self._logger = logger self._next_data_ids = (str(i) for i in itertools.count(1)) self._data = common.DataStorage({ 'properties': conf['properties'], 'slave_count': 0, 'data': {next(self._next_data_ids): i for i in conf['data']} })
async def server(port): server = Server() server._data = common.DataStorage() server._receive_queue = aio.Queue() server._srv = await juggler.listen('127.0.0.1', port, server._on_connection, autoflush_delay=0) try: yield server finally: await server.async_close()
def __init__(self, conf, logger): self._logger = logger self._next_data_ids = (str(i) for i in itertools.count(1)) self._next_command_ids = (str(i) for i in itertools.count(1)) self._data_change_cbs = util.CallbackRegistry() self._data = common.DataStorage({ 'properties': conf['properties'], 'connection_count': 0, 'data': {next(self._next_data_ids): i for i in conf['data']}, 'commands': { next(self._next_command_ids): dict(i, value=None) for i in conf['commands'] } })
async def create_server(conf: json.Data, conf_path: Path, ui_path: Path ) -> 'Server': """Create server Args: conf: configuration defined by ``hat://manager/main.yaml#`` conf_path: configuration file path ui_path: static web ui frontent directory path """ addr = urllib.parse.urlparse(conf['settings']['ui']['address']) server = Server() server._conf_path = conf_path server._devices = {} server._next_device_ids = (str(i) for i in itertools.count(1)) server._data = common.DataStorage({'log': [], 'devices': {}, 'settings': conf['settings']}) server._srv = await juggler.listen(host=addr.hostname, port=addr.port, connection_cb=server._on_connection, static_dir=ui_path, autoflush_delay=autoflush_delay) server._logger = common.Logger() handler = server._logger.register_log_cb(server._on_log) server.async_group.spawn(aio.call_on_cancel, handler.cancel) for device_conf in conf['devices']: server._create_device(device_conf) return server
def __init__(self, conf, logger): self._conf = conf self._logger = logger self._data = common.DataStorage()