feat: 完成 issue #21 点位字典 CSV schema 增加协议(protocol)维度
This commit is contained in:
@@ -58,14 +58,27 @@ class CollectorEngine:
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
def _build_routing(self) -> Dict[str, Driver]:
|
||||
"""按设备前缀把点位路由到对应驱动实例(模板配置驱动)。"""
|
||||
"""点位 → 驱动实例路由。
|
||||
|
||||
匹配优先级(issue #21「协议」维度):
|
||||
1. 点位级:点位字典 CSV protocol 列精确匹配驱动槽位协议;
|
||||
2. 模板级(缺省):按设备前缀 device_prefixes 匹配;
|
||||
3. 兜底:无前缀的空槽位接收未匹配点位。
|
||||
"""
|
||||
routing: Dict[str, Driver] = {}
|
||||
slot_by_protocol: Dict[str, Driver] = {}
|
||||
for protocol, driver, prefixes in self.driver_slots:
|
||||
if protocol:
|
||||
slot_by_protocol.setdefault(protocol, driver)
|
||||
for p in self.point_dict.points:
|
||||
if p.point_id in routing:
|
||||
continue
|
||||
if not prefixes or any(p.device_id.startswith(pre) for pre in prefixes):
|
||||
routing[p.point_id] = driver
|
||||
# 点位级协议覆盖:优先于前缀路由
|
||||
for p in self.point_dict.points:
|
||||
if p.protocol and p.protocol in slot_by_protocol:
|
||||
routing[p.point_id] = slot_by_protocol[p.protocol]
|
||||
return routing
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user