Fix the MQTT node, suggest message names, and drop Items

- MQTT nodes failed to build: the topic map was renamed to talk in ports, but
  __slots__ still declared the old name, so every MQTT node raised
  AttributeError. Building one of each node type is now a test, since __slots__
  makes this failure invisible until someone places the node.
- Port names offer the messages already in play: everything published is worth
  reading, and an input nobody provides yet is worth publishing. A message only
  connects when both ends spell it the same way, so choosing beats typing.
- Adding a port focuses its name field.
- Dragging onto an input that already reads something offers the extra port as
  well as the replacement — an MQTT or InfluxDB node usually wants both.
- The template's Item model, its routes, screens and table are gone.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WzrvW7rjQbynnhF6pxh6i
This commit is contained in:
Melvin Strobl
2026-08-15 18:43:17 +02:00
co-authored by Claude Fable 5
parent 8c82549cf6
commit 01af7787c1
27 changed files with 365 additions and 1433 deletions
+82
View File
@@ -0,0 +1,82 @@
"""Every node type the editor offers must actually build.
The node classes use ``__slots__``, so an attribute the class forgot to declare
only fails when someone places that node. Building one of each catches it.
"""
import pytest
from app.flow.controller import NODE_TYPES, node_type_info
from app.flow.messages import DType, MessageSpec
# Enough configuration for each type to construct; the ports decide the
# direction, so every type gets both an input and an output where it allows it.
FIXTURES: dict[str, dict] = {
"mqtt": {
"params": {"topic": "sensors/temp", "broker_host": "broker.local"},
"requires": [],
"provides": [MessageSpec(name="temp", dtype=DType.FLOAT)],
},
"http": {
"params": {"url": "/hook", "method": "POST"},
"requires": [],
"provides": [MessageSpec(name="temp", dtype=DType.FLOAT)],
},
"influxdb": {
"params": {
"url": "http://influx.local",
"token": "t",
"org": "o",
"bucket": "b",
},
"requires": [MessageSpec(name="temp", dtype=DType.FLOAT)],
"provides": [],
},
"delay": {
"params": {"interval": 5},
"requires": [MessageSpec(name="temp", dtype=DType.FLOAT)],
"provides": [MessageSpec(name="temp_out", dtype=DType.FLOAT)],
},
"mlp": {
"params": {"seed": 1},
"requires": [MessageSpec(name="temp", dtype=DType.FLOAT)],
"provides": [MessageSpec(name="score", dtype=DType.FLOAT)],
},
}
@pytest.mark.parametrize("type_name", sorted(FIXTURES))
def test_node_type_builds_and_qualifies(type_name: str):
fixture = FIXTURES[type_name]
node = NODE_TYPES[type_name].cls(
requires=fixture["requires"],
provides=fixture["provides"],
params=fixture["params"],
name=type_name,
)
node.assign_flow("house", type_name)
assert node.id == f"house.{type_name}"
for spec in [*node.input_ports, *node.output_ports]:
assert spec.name.startswith("house.")
def test_mqtt_routes_topics_by_port():
node = NODE_TYPES["mqtt"].cls(
provides=[
MessageSpec(name="temp", dtype=DType.FLOAT),
MessageSpec(name="humidity", dtype=DType.FLOAT),
],
params={"topic": {"temp": "house/temp", "humidity": "house/hum"}},
name="sensors",
)
node.assign_flow("house", "sensors")
# Qualifying the messages must not disturb the topic wiring.
assert node._topic_to_ports == {"house/temp": ["temp"], "house/hum": ["humidity"]}
def test_every_offered_type_has_a_fixture():
# A new node type without a fixture here would ship untested.
offered = {info.type for info in node_type_info() if info.type != "python"}
assert offered == set(FIXTURES)