From: Benjamin Braatz Date: Wed, 30 Jun 2021 12:35:13 +0000 (+0200) Subject: Continue JSON interface. X-Git-Url: http://git.graph-it.com/?a=commitdiff_plain;h=8b718a46b7f8f792481289ec7bfeae8ab3c70c71;p=graphit%2Fcontrolpi-graph.git Continue JSON interface. --- diff --git a/controlpi_plugins/graphjson.py b/controlpi_plugins/graphjson.py index 4cb1911..53688a4 100644 --- a/controlpi_plugins/graphjson.py +++ b/controlpi_plugins/graphjson.py @@ -36,31 +36,36 @@ class GraphJSON(BasePlugin): 'items': {'type': 'string'}}}, 'required': ['url', 'crt', 'node', 'mac attribute', 'interface']} - + async def _receive(self, message: Message) -> None: if ('target' in message and message['target'] == self.name and 'command' in message): if message['command'] == 'pull conf': conf = await self._call('attribut', - [self._guid, - f"{self.conf['node']}_{self.conf['conf attribute']}"]) + [self._guid, self._confattribute]) if conf != self._conf: await self.bus.send(Message(self.name, {'event': 'conf changed', 'new conf': conf})) - # TODO: Write file + try: + with open(sys.argv[1], 'w') as conf_file: + conf_file.write(conf) + except IndexError: + pass elif message['command'] == 'sync state': sync = await self._call('attribut', - [self._guid, - f"{self.conf['node']}_{self.conf['sync attribute']}"]) - if 'state' in message and message['sender'] in self.conf['sync states']: + [self._guid, self._syncattribute]) + + + if ('state' in message and + message['sender'] in self.conf['sync states']): self._states[message['sender']] = message['state'] async def _call(self, method, params): await self._lock.acquire() self._call_id += 1 - request = { 'jsonrpc': '2.0', 'method': method, - 'params': params, 'id': self._call_id } + request = {'jsonrpc': '2.0', 'method': method, + 'params': params, 'id': self._call_id} message = msgpack.packb(request) size = struct.pack(' None: - """Open connection and test it.""" + """Open connection and get node instance for MAC address.""" self._lock = asyncio.Lock() (self._reader, self._writer) = await asyncio.open_connection( self._host, self._port, ssl=self._ssl_ctx) + # Read banner: banner_size = await self._reader.readexactly(4) banner_size = struct.unpack('