优化拔出设备逻辑

This commit is contained in:
2025-09-12 13:44:26 +08:00
parent 9770ce3ad3
commit 9cf094986c
5 changed files with 66 additions and 84 deletions

View File

@@ -92,21 +92,18 @@ listener_thread.start()
def deviceList():
try:
with listLock:
# 1. 一次性消费完队列
# 1. 消费完队列
while not dataQueue.empty():
obj = dataQueue.get()
if obj["type"] == 1:
# 上线:先踢掉同 deviceId 的旧记录(端口可能变)
listData[:] = [d for d in listData if d.get("deviceId") != obj.get("deviceId")]
listData.append(obj)
else:
# 倒序删除,安全
for i in range(len(listData) - 1, -1, -1):
d = listData[i]
if d.get("deviceId") == obj.get("deviceId") and \
d.get("screenPort") == obj.get("screenPort"):
listData.pop(i)
break # 同一端口同一设备只删一次
# 下线:只要同 deviceId 就删,不管端口
listData[:] = [d for d in listData if d.get("deviceId") != obj.get("deviceId")]
# 2. 兜底:只保留 type == 1 的在线设备
# 2. 兜底:只保留在线
listData[:] = [d for d in listData if d.get('type') == 1]
return ResultData(data=listData.copy()).toJson()