custom device name for fake udp

This commit is contained in:
2025-02-13 10:43:33 +01:00
parent aa2069d4f4
commit 77af8c760e
3 changed files with 18 additions and 13 deletions

View File

@ -19,7 +19,7 @@ class EnumConvert(dict):
class SecopStream(Stream):
ping_time = 0
def init(self):
def init(self, device=None, **kwds):
self._buffer = []
self.send('*IDN?')
resend = True
@ -41,7 +41,7 @@ class SecopStream(Stream):
else:
raise ValueError('missing describing message')
self.descr = json.loads(match.group(1))
self.device = self.descr['equipment_id']
self.device = device or self.descr['equipment_id']
if self.device.endswith('psi.ch'):
self.device[-6:] = []
self.tags['device'] = self.device
@ -110,13 +110,18 @@ class UdpStream(Base):
except socket.error: # pragma: no cover
return None
msg = json.loads(msg.decode('utf-8'))
if msg['SECoP'] == 'for_other_node':
uri = msg['uri']
elif msg['SECoP'] == 'node':
kind = msg.pop('SECoP', None)
if not kind:
continue
if kind == 'for_other_node':
uri = msg.pop('uri')
kwargs = msg
elif kind == 'node':
uri = f"{addr[0]}:{msg['port']}"
kwargs = {'name': msg['equipment_id']}
else:
continue
yield SecopStream, uri, msg['equipment_id']
yield SecopStream, uri, kwargs
class ScanReply(UdpStream):