"node": "testnode",
"guid": "0123456789",
"attribute": "testboolean",
- "value": "1" }
+ "value": true }
},
"State to Graph Off": {
"plugin": "Alias",
"from": { "sender": { "const": "Example State" },
- "state": { "const": true } },
+ "state": { "const": false } },
"to": { "target": "Test Graph",
"command": "set",
"node": "testnode",
"guid": "0123456789",
"attribute": "testboolean",
- "value": "0" }
+ "value": false }
},
"Get from Graph": {
"plugin": "Alias",
"node": "testnode",
"guid": "0123456789",
"attribute": "testboolean" }
+ },
+ "Set with Key": {
+ "plugin": "Alias",
+ "from": { "target": { "const": "Set with Key" },
+ "command": { "const": "execute" } },
+ "to": { "target": "Test Graph",
+ "command": "set key",
+ "node": "testnode",
+ "key attribute": "name",
+ "key value": "test",
+ "attribute": "testnumber",
+ "value": 42000 }
+ },
+ "Get with Key": {
+ "plugin": "Alias",
+ "from": { "target": { "const": "Get with Key" },
+ "command": { "const": "execute" } },
+ "to": { "target": "Test Graph",
+ "command": "get key",
+ "node": "testnode",
+ "key attribute": "name",
+ "key value": "test",
+ "attribute": "testnumber" }
}
}
'required': ['url', 'crt']}
async def _receive(self, message: Message) -> None:
- await self.bus.send(Message(self.name, {'spam': self.conf['spam']}))
+ if message['command'] == 'set':
+ await self._call('setze',
+ [message['guid'],
+ f"{message['node']}_{message['attribute']}",
+ message['value']])
+ await self.bus.send(Message(self.name,
+ {'event': 'attributevalue',
+ 'node': message['node'],
+ 'guid': message['guid'],
+ 'attribute': message['attribute'],
+ 'value': message['value']}))
+ elif message['command'] == 'get':
+ value = await self._call('attribut',
+ [message['guid'],
+ f"{message['node']}_{message['attribute']}"])
+ await self.bus.send(Message(self.name,
+ {'event': 'attributevalue',
+ 'node': message['node'],
+ 'guid': message['guid'],
+ 'attribute': message['attribute'],
+ 'value': value}))
+ elif message['command'] == 'set key':
+ guid = await self._call('attributsknoten',
+ [f"{message['node']}_{message['key attribute']}",
+ message['key value']])
+ await self._call('setze',
+ [guid,
+ f"{message['node']}_{message['attribute']}",
+ message['value']])
+ await self.bus.send(Message(self.name,
+ {'event': 'attributevalue',
+ 'node': message['node'],
+ 'guid': guid,
+ 'attribute': message['attribute'],
+ 'value': message['value']}))
+ elif message['command'] == 'get key':
+ guid = await self._call('attributsknoten',
+ [f"{message['node']}_{message['key attribute']}",
+ message['key value']])
+ value = await self._call('attribut',
+ [guid,
+ f"{message['node']}_{message['attribute']}"])
+ await self.bus.send(Message(self.name,
+ {'event': 'attributevalue',
+ 'node': message['node'],
+ 'guid': guid,
+ 'attribute': message['attribute'],
+ 'value': value}))
async def _call(self, method, params):
await self._lock.acquire()
self._ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
self._ssl_ctx.load_cert_chain(self.conf['crt'])
self._call_id = 0
- #message = Message(self.name, {'spam': self.conf['spam']})
- #sends = [MessageTemplate.from_message(message)]
- #receives = [MessageTemplate({'target': {'const': self.name}})]
- #self.bus.register(self.name, 'Plugin', sends, receives, self._receive)
+ sends = [MessageTemplate({'event': {'const': 'attributevalue'},
+ 'node': {'type': 'string'},
+ 'guid': {'type': 'string'},
+ 'attribute': {'type': 'string'},
+ 'value': {}})]
+ receives = [MessageTemplate({'target': {'const': self.name},
+ 'command': {'const': 'set'},
+ 'node': {'type': 'string'},
+ 'guid': {'type': 'string'},
+ 'attribute': {'type': 'string'},
+ 'value': {}}),
+ MessageTemplate({'target': {'const': self.name},
+ 'command': {'const': 'get'},
+ 'node': {'type': 'string'},
+ 'guid': {'type': 'string'},
+ 'attribute': {'type': 'string'}}),
+ MessageTemplate({'target': {'const': self.name},
+ 'command': {'const': 'set key'},
+ 'node': {'type': 'string'},
+ 'key attribute': {'type': 'string'},
+ 'key value': {},
+ 'attribute': {'type': 'string'},
+ 'value': {}}),
+ MessageTemplate({'target': {'const': self.name},
+ 'command': {'const': 'get key'},
+ 'node': {'type': 'string'},
+ 'key attribute': {'type': 'string'},
+ 'key value': {},
+ 'attribute': {'type': 'string'}})]
+ self.bus.register(self.name, 'GraphConnection',
+ sends, receives, self._receive)
async def run(self) -> None:
"""Open connection and test it."""
self._lock = asyncio.Lock()
(self._reader, self._writer) = await asyncio.open_connection(
self._host, self._port, ssl=self._ssl_ctx)
- size = await self._reader.readexactly(4)
- size = struct.unpack('<i', size)[0]
- message = await self._reader.readexactly(size)
+ banner_size = await self._reader.readexactly(4)
+ banner_size = struct.unpack('<i', banner_size)[0]
+ banner_message = await self._reader.readexactly(banner_size)
knoten_guid = await self._call('attributsknoten',
['knoten_name', 'knoten'])