74 lines
2.2 KiB
Python
74 lines
2.2 KiB
Python
from typing import Dict, Any
|
||
from core import VorkNode
|
||
from core.form_descriptors import get_form_descriptor
|
||
from model_nodes.node_switch_models import (
|
||
SwitchNodeData,
|
||
SwitchNodeLinks,
|
||
SwitchNodeCoreSchema,
|
||
SwitchNodeCoreSchemaData
|
||
)
|
||
|
||
|
||
class VorkNodeSwitch(VorkNode):
|
||
|
||
def __init__(self, data: Dict[str, Any], links: Dict[str, Any] = None):
|
||
"""
|
||
Инициализация узла switch
|
||
"""
|
||
super().__init__(data, links or {})
|
||
|
||
@property
|
||
def id(self) -> str:
|
||
return "SWITCH"
|
||
|
||
@classmethod
|
||
def form(cls) -> Dict[str, Any]:
|
||
"""
|
||
Возвращает статический дескриптор формы для узла Switch
|
||
"""
|
||
return get_form_descriptor("SWITCH")
|
||
|
||
def validate(self) -> SwitchNodeCoreSchema:
|
||
"""
|
||
Валидирует данные узла switch и возвращает схему
|
||
"""
|
||
try:
|
||
# Валидируем данные узла
|
||
validated_data = self.validate_data()
|
||
|
||
# Валидируем связи узла
|
||
validated_links = self.validate_links()
|
||
|
||
# Создаем данные портов (default=0, case_1=1)
|
||
node_data = SwitchNodeCoreSchemaData(
|
||
default_port_number=0,
|
||
case_1_port_number=1,
|
||
)
|
||
|
||
# Создаем схему с валидированными данными
|
||
return SwitchNodeCoreSchema(
|
||
ps_id=validated_data.ps_id,
|
||
node_type=validated_data.node_type,
|
||
parent_id=validated_links.parent_id,
|
||
parent_port_number=validated_links.parent_port_number,
|
||
data=node_data
|
||
)
|
||
except Exception as e:
|
||
print(f"Switch node validation error: {e}")
|
||
raise
|
||
|
||
def validate_data(self) -> SwitchNodeData:
|
||
"""
|
||
Валидирует данные узла switch
|
||
"""
|
||
return SwitchNodeData(**self.data)
|
||
|
||
def validate_links(self) -> SwitchNodeLinks:
|
||
"""
|
||
Валидирует связи узла switch
|
||
"""
|
||
return SwitchNodeLinks(**self.links)
|
||
|
||
def process(self, context):
|
||
pass
|