Skip to content

Commit 94db914

Browse files
author
sidey79
committed
feat: Aktualisiere JSON-Schema und MQTT-Nachrichtenverarbeitung; verschiebe Preamble und Modulationsfelder ins Protokollobjekt
1 parent 49dfe6e commit 94db914

File tree

5 files changed

+36
-16
lines changed

5 files changed

+36
-16
lines changed

.devcontainer/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ services:
3838
environment:
3939
- CONFIGTYPE=fhem_signalduino_example.cfg
4040
- FHEM_PERM_DIR=0777
41-
- FHEM_PERM_FILES=0777
41+
- FHEM_PERM_FILE=0777
4242
volumes:
4343
- ./fhem-data:/opt/fhem
4444
depends_on:

docs/architecture/decisions/ADR-006-json-output-schema.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ Der JSON-Output für MQTT-Nutzdaten muss **kompakt** (ohne Zeilenumbrüche und E
5050
| `str`
5151
| Die Preamble (z.B. `W125#`) des erkannten Protokolls.
5252

53-
| `protocol.encoding`
53+
| `protocol.format`
5454
| `str`
55-
| Das Codierungsformat des Signals (z.B. `manchester`, `twostate`, `pulse`).
55+
| Das Format bzw. die Modulationsart des Signals (z.B. `manchester`, `twostate`, `2-FSK`).
5656

5757
| `protocol.clock`
5858
| `float`
5959
| Der Takt-Wert in Mikrosekunden (`us`), der für die Demodulation verwendet wurde.
6060

61-
| `protocol.modulation`
61+
| `protocol.rfmode`
6262
| `str`
63-
| (Optional) Modulationsart (z.B. `2-FSK`, `GFSK`) für FSK-Protokolle.
63+
| (Optional) Der RF-Modus (z.B. `Fine_Offset_WH31_868`), falls verfügbar.
6464

6565
| `protocol.bitlength`
6666
| `int`
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
[source,json]
22
----
33
{
4-
"data": "30E0A1AA4241DE6C000200000BC5",
5-
"raw": "MC;LL=-1017;LH=932;...",
4+
"data": "30E0A1DE4CE6C16C0002000012FC",
5+
"raw": "MN;D=30E0A1DE4CE6C16C0002000012FC;R=193;A=-21;",
66
"metadata": {
7-
"rssi": -74,
8-
"freq_afc": 123
7+
"rssi": -105.5,
8+
"freq_afc": -33
99
},
1010
"protocol": {
11-
"name": "WH31",
1211
"id": "125",
12+
"model": "MN",
1313
"preamble": "W125#",
1414
"format": "2-FSK",
15-
"clock": 17257
15+
"rfmode": "Fine_Offset_WH31_868"
1616
}
1717
}
1818
----

signalduino/mqtt.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,18 @@ def _raw_frame_to_dict(raw_frame: RawFrame) -> dict:
282282
except Exception as e:
283283
self.logger.warning("Failed to get preamble: %s", e)
284284

285-
# Add new 'preamble' field
286-
message_dict["preamble"] = preamble
285+
# Add new 'preamble' field to protocol object
286+
if "protocol" not in message_dict or message_dict["protocol"] is None:
287+
message_dict["protocol"] = {}
288+
289+
message_dict["protocol"]["preamble"] = preamble
290+
291+
# Move modulation and rfmode from metadata to protocol
292+
metadata = message_dict.get("metadata", {})
293+
if "modulation" in metadata:
294+
message_dict["protocol"]["format"] = metadata.pop("modulation")
295+
if "rfmode" in metadata:
296+
message_dict["protocol"]["rfmode"] = metadata.pop("rfmode")
287297

288298
# Ensure data (formerly payload) is uppercase
289299
# Use getattr to be safe even if dataclass structure changed

tests/test_mqtt.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def mock_decoded_message() -> DecodedMessage:
3333
"message_hex": "AABBCC",
3434
"message_bits": "101010101011101111001100",
3535
"is_repeat": False,
36+
"modulation": "ASK",
37+
"rfmode": "Slow",
3638
},
3739
protocol={"id": "1"}, # Hinzugefügtes Protokoll-ID-Feld
3840
)
@@ -131,10 +133,18 @@ async def test_mqtt_publisher_publish_success(MockClient, mock_decoded_message,
131133
payload_dict = json.loads(published_payload.decode("utf-8"))
132134
assert payload_dict["protocol"]["id"] == "1"
133135

134-
# Payload sollte KEINE Preamble mehr enthalten, aber das neue Feld "preamble" schon
136+
# Payload sollte KEINE Preamble mehr enthalten.
137+
# Preamble sollte im "protocol" Feld sein.
135138
# Protocol 1 (Conrad RSL v1) hat Preamble "P1#"
136139
assert payload_dict["data"] == "9374A400"
137-
assert payload_dict["preamble"] == "P1#"
140+
assert payload_dict["protocol"]["preamble"] == "P1#"
141+
assert "preamble" not in payload_dict
142+
143+
# Check moved metadata fields
144+
assert payload_dict["protocol"]["format"] == "ASK"
145+
assert payload_dict["protocol"]["rfmode"] == "Slow"
146+
assert "modulation" not in payload_dict["metadata"]
147+
assert "rfmode" not in payload_dict["metadata"]
138148

139149
# 'raw' sollte jetzt enthalten sein, da es ein String-Feld ist.
140150
assert payload_dict["raw"] == "MS;P1=1154;P2=-697;P3=559;P4=-1303;P5=-7173;D=351234341234341212341212123412343412341234341234343434343434343434;CP=3;SP=5;R=247;O;"
@@ -180,7 +190,7 @@ async def test_mqtt_publisher_strips_preamble_from_data(MockClient, mock_decoded
180190

181191
# 2. Assert, dass die Preamble aus 'data' entfernt wurde
182192
assert payload_dict["data"] == "9374A400"
183-
assert payload_dict["preamble"] == "P1#"
193+
assert payload_dict["protocol"]["preamble"] == "P1#"
184194

185195

186196
@patch("signalduino.mqtt.mqtt.Client")

0 commit comments

Comments
 (0)