Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
5364b855aa
|
|||
|
3a1841a8a9
|
@@ -18,6 +18,7 @@ from apps.abstraction.vendors import (
|
|||||||
shelly,
|
shelly,
|
||||||
tasmota,
|
tasmota,
|
||||||
hottis_pv_modbus,
|
hottis_pv_modbus,
|
||||||
|
hottis_wago_modbus,
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -40,6 +41,7 @@ for vendor_name, vendor_module in [
|
|||||||
("shelly", shelly),
|
("shelly", shelly),
|
||||||
("tasmota", tasmota),
|
("tasmota", tasmota),
|
||||||
("hottis_pv_modbus", hottis_pv_modbus),
|
("hottis_pv_modbus", hottis_pv_modbus),
|
||||||
|
("hottis_wago_modbus", hottis_wago_modbus),
|
||||||
]:
|
]:
|
||||||
for (device_type, direction), handler in vendor_module.HANDLERS.items():
|
for (device_type, direction), handler in vendor_module.HANDLERS.items():
|
||||||
key = (device_type, vendor_name, direction)
|
key = (device_type, vendor_name, direction)
|
||||||
|
|||||||
58
apps/abstraction/vendors/hottis_wago_modbus.py
vendored
Normal file
58
apps/abstraction/vendors/hottis_wago_modbus.py
vendored
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
"""Hottis Wago Modbus vendor transformations."""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
def transform_relay_to_vendor(payload: dict[str, Any]) -> str:
|
||||||
|
"""Transform abstract relay payload to Hottis Wago Modbus format.
|
||||||
|
|
||||||
|
Hottis Wago Modbus expects plain text 'true' or 'false' (not JSON).
|
||||||
|
|
||||||
|
Example:
|
||||||
|
- Abstract: {'power': 'on'}
|
||||||
|
- Hottis Wago Modbus: 'true' or 'false'
|
||||||
|
"""
|
||||||
|
power = payload.get("power", "off")
|
||||||
|
|
||||||
|
# Map abstract "on"/"off" to vendor "true"/"false"
|
||||||
|
if isinstance(power, str):
|
||||||
|
power_lower = power.lower()
|
||||||
|
if power_lower in {"on", "true", "1"}:
|
||||||
|
return "true"
|
||||||
|
if power_lower in {"off", "false", "0"}:
|
||||||
|
return "false"
|
||||||
|
|
||||||
|
# Fallback: any truthy value -> "true", else "false"
|
||||||
|
return "true" if power else "false"
|
||||||
|
|
||||||
|
|
||||||
|
def transform_relay_to_abstract(payload: str) -> dict[str, Any]:
|
||||||
|
"""Transform Hottis Wago Modbus relay payload to abstract format.
|
||||||
|
|
||||||
|
Hottis Wago Modbus sends plain text 'true' or 'false'.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
- Hottis Wago Modbus: 'true'
|
||||||
|
- Abstract: {'power': 'on'}
|
||||||
|
"""
|
||||||
|
value = payload.strip().lower()
|
||||||
|
|
||||||
|
if value == "true":
|
||||||
|
power = "on"
|
||||||
|
elif value == "false":
|
||||||
|
power = "off"
|
||||||
|
else:
|
||||||
|
# Fallback for unexpected values: keep as-is
|
||||||
|
logger.warning("Unexpected relay payload from Hottis Wago Modbus: %r", payload)
|
||||||
|
power = value
|
||||||
|
|
||||||
|
return {"power": power}
|
||||||
|
|
||||||
|
|
||||||
|
# Registry of handlers for this vendor
|
||||||
|
HANDLERS = {
|
||||||
|
("relay", "to_vendor"): transform_relay_to_vendor,
|
||||||
|
("relay", "to_abstract"): transform_relay_to_abstract,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user