custom device name for fake udp
This commit is contained in:
17
secop.py
17
secop.py
@ -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):
|
||||
|
Reference in New Issue
Block a user