diff --git a/apps/abstraction/vendors/test.py b/apps/abstraction/vendors/test.py new file mode 100644 index 0000000..a25a7bb --- /dev/null +++ b/apps/abstraction/vendors/test.py @@ -0,0 +1,62 @@ +"""test vendor transformations.""" + +import json +import logging +from typing import Any + +logger = logging.getLogger(__name__) + + +def transform_contact_sensor_to_vendor(payload: dict[str, Any]) -> str: + """Transform abstract contact sensor payload to MAX! format. + + Contact sensors are read-only. + """ + logger.warning("Contact sensors are read-only - SET commands should not be used") + return json.dumps(payload) + + +def transform_contact_sensor_to_abstract(payload: str) -> dict[str, Any]: + try: + contact_value = payload.strip().lower() + return { + "contact": "open" if (contact_value == "open") else "closed" + } + except (ValueError, TypeError) as e: + logger.error(f"contact sensor failed to parse: {payload}, error: {e}") + return {"contact": "closed"} + + +def transform_thermostat_to_vendor(payload: dict[str, Any]) -> str: + if "target" not in payload: + logger.warning(f"thermostat payload missing 'target': {payload}") + return "21" + + target_temp = payload["target"] + + if isinstance(target_temp, (int, float)): + int_temp = int(round(target_temp)) + return str(int_temp) + + logger.warning(f"invalid target temperature type: {type(target_temp)}") + return "21" + + +def transform_thermostat_to_abstract(payload: str) -> dict[str, Any]: + target_temp = float(payload.strip()) + + return { + "target": target_temp, + "mode": "heat" + } + + +# Registry of handlers for this vendor +HANDLERS = { + ("contact_sensor", "to_vendor"): transform_contact_sensor_to_vendor, + ("contact_sensor", "to_abstract"): transform_contact_sensor_to_abstract, + ("contact", "to_vendor"): transform_contact_sensor_to_vendor, + ("contact", "to_abstract"): transform_contact_sensor_to_abstract, + ("thermostat", "to_vendor"): transform_thermostat_to_vendor, + ("thermostat", "to_abstract"): transform_thermostat_to_abstract, +} diff --git a/config/devices.yaml b/config/devices.yaml index 3380666..47c18bf 100644 --- a/config/devices.yaml +++ b/config/devices.yaml @@ -466,6 +466,21 @@ devices: model: "MAX! Thermostat" peer_id: "41" channel: "1" +- device_id: thermostat_bad_unten + homekit_aid: 31 + name: Heizung + type: thermostat + cap_version: "thermostat@1.0.0" + technology: zigbee2mqtt + features: + heating: true + temperature_range: + - 5 + - 30 + temperature_step: 0.5 + topics: + state: "zigbee2mqtt/0x003c84fffebdcc28" + set: "zigbee2mqtt/0x003c84fffebdcc28/set" - device_id: sterne_wohnzimmer homekit_aid: 32 name: Sterne @@ -1137,19 +1152,3 @@ devices: topics: state: "zigbee2mqtt/0x842e14fffefe4ba4" set: "zigbee2mqtt/0x842e14fffefe4ba4/set" - -- device_id: thermostat_bad_unten - homekit_aid: 31 - name: Heizung - type: thermostat - cap_version: "thermostat@1.0.0" - technology: zigbee2mqtt - features: - heating: true - temperature_range: - - 5 - - 30 - temperature_step: 0.5 - topics: - state: "zigbee2mqtt/0x003c84fffebdcc28" - set: "zigbee2mqtt/0x003c84fffebdcc28/set" \ No newline at end of file diff --git a/config/rules.yaml b/config/rules.yaml index 54a95ef..9cdc7c2 100644 --- a/config/rules.yaml +++ b/config/rules.yaml @@ -9,7 +9,11 @@ rules: thermostats: - thermostat_bad_unten params: +<<<<<<< HEAD eco_target: 6.0 +======= + eco_target: 5.0 +>>>>>>> main open_min_secs: 20 close_min_secs: 20 - id: window_setback_esszimmer @@ -23,7 +27,11 @@ rules: thermostats: - thermostat_esszimmer params: +<<<<<<< HEAD eco_target: 6.0 +======= + eco_target: 5.0 +>>>>>>> main open_min_secs: 20 close_min_secs: 20 previous_target_ttl_secs: 86400 @@ -38,7 +46,11 @@ rules: thermostats: - thermostat_wohnzimmer params: +<<<<<<< HEAD eco_target: 6.0 +======= + eco_target: 5.0 +>>>>>>> main open_min_secs: 20 close_min_secs: 20 previous_target_ttl_secs: 86400 @@ -55,7 +67,11 @@ rules: thermostats: - thermostat_kueche params: +<<<<<<< HEAD eco_target: 6.0 +======= + eco_target: 5.0 +>>>>>>> main open_min_secs: 20 close_min_secs: 20 previous_target_ttl_secs: 86400 @@ -71,7 +87,11 @@ rules: thermostats: - thermostat_patty params: +<<<<<<< HEAD eco_target: 6.0 +======= + eco_target: 5.0 +>>>>>>> main open_min_secs: 20 close_min_secs: 20 previous_target_ttl_secs: 86400 @@ -85,7 +105,11 @@ rules: thermostats: - thermostat_schlafzimmer params: +<<<<<<< HEAD eco_target: 6.0 +======= + eco_target: 5.0 +>>>>>>> main open_min_secs: 20 close_min_secs: 20 previous_target_ttl_secs: 86400 @@ -99,7 +123,11 @@ rules: thermostats: - thermostat_wolfgang params: +<<<<<<< HEAD eco_target: 6.0 +======= + eco_target: 5.0 +>>>>>>> main open_min_secs: 20 close_min_secs: 20 - id: window_setback_bad_oben @@ -112,6 +140,10 @@ rules: thermostats: - thermostat_bad_oben params: +<<<<<<< HEAD eco_target: 6.0 +======= + eco_target: 5.0 +>>>>>>> main open_min_secs: 20 close_min_secs: 20