cbc2bc03c2
create_node/create_edge persisted rows with design_id=null when the client omitted it (the MCP write tools), so they existed in the DB but never rendered on the canvas until a container restart reconciled them. Both routes now fall back to the first design, matching bulk-approve. Also fix MCP resource reads (homelable://canvas, homelable://edges): the framework passes a pydantic AnyUrl, not a str, which raised "'AnyUrl' object has no attribute 'startswith'". Coerce to str. EdgeResponse now exposes design_id for symmetry with NodeResponse. ha-relevant: no
58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, field_validator
|
|
|
|
from app.schemas.utils import normalize_animated
|
|
|
|
|
|
class EdgeBase(BaseModel):
|
|
source: str
|
|
target: str
|
|
type: str = "ethernet"
|
|
label: str | None = None
|
|
vlan_id: int | None = None
|
|
speed: str | None = None
|
|
custom_color: str | None = None
|
|
path_style: str | None = None
|
|
animated: str = 'none'
|
|
source_handle: str | None = None
|
|
target_handle: str | None = None
|
|
waypoints: list[dict[str, float]] | None = None
|
|
|
|
@field_validator('animated', mode='before')
|
|
@classmethod
|
|
def validate_animated(cls, v: object) -> str:
|
|
return normalize_animated(v)
|
|
|
|
|
|
class EdgeCreate(EdgeBase):
|
|
design_id: str | None = None
|
|
|
|
|
|
class EdgeUpdate(BaseModel):
|
|
type: str | None = None
|
|
label: str | None = None
|
|
vlan_id: int | None = None
|
|
speed: str | None = None
|
|
custom_color: str | None = None
|
|
path_style: str | None = None
|
|
animated: str | None = None
|
|
source_handle: str | None = None
|
|
target_handle: str | None = None
|
|
waypoints: list[dict[str, float]] | None = None
|
|
|
|
@field_validator('animated', mode='before')
|
|
@classmethod
|
|
def validate_animated(cls, v: object) -> str | None:
|
|
if v is None:
|
|
return None
|
|
return normalize_animated(v)
|
|
|
|
|
|
class EdgeResponse(EdgeBase):
|
|
id: str
|
|
design_id: str | None = None
|
|
created_at: datetime
|
|
|
|
model_config = {"from_attributes": True}
|