diff --git a/custom_components/idm_heatpump/const.py b/custom_components/idm_heatpump/const.py index 295bac2..e8a7a01 100644 --- a/custom_components/idm_heatpump/const.py +++ b/custom_components/idm_heatpump/const.py @@ -15,6 +15,7 @@ class SensorFeatures(IntFlag): SET_ROOM_MODE = 16 SET_BINARY = 32 SET_SYSTEM_STATUS = 64 + SET_CIRCUIT_MODE = 128 class _CaseInsensitiveEnumMeta(EnumMeta): @@ -225,6 +226,7 @@ def _missing_(cls, value) -> Any: SERVICE_SET_TEMPERATURE = "set_temperature" SERVICE_SET_HUMIDITY = "set_humidity" SERVICE_SET_ROOM_MODE = "set_room_mode" +SERVICE_SET_CIRCUIT_MODE = "set_circuit_mode" SERVICE_SET_BINARY = "set_binary" SERVICE_SET_SYSTEM_STATUS = "set_system_status" diff --git a/custom_components/idm_heatpump/sensor.py b/custom_components/idm_heatpump/sensor.py index 5de16da..b8ab732 100644 --- a/custom_components/idm_heatpump/sensor.py +++ b/custom_components/idm_heatpump/sensor.py @@ -12,9 +12,11 @@ SERVICE_SET_HUMIDITY, SERVICE_SET_POWER, SERVICE_SET_ROOM_MODE, + SERVICE_SET_CIRCUIT_MODE, SERVICE_SET_SYSTEM_STATUS, SERVICE_SET_TEMPERATURE, RoomMode, + CircuitMode, SensorFeatures, SystemStatus, ) @@ -254,6 +256,54 @@ async def handle_set_room_mode(call: ServiceCall): service_func=handle_set_room_mode, ) + async def handle_set_circuit_mode(call: ServiceCall): + target = call.data.get("target") + entity = platform.entities[target] + + if ( + not isinstance(entity, IdmHeatpumpEntity) + or SensorFeatures.SET_CIRCUIT_MODE not in entity.supported_features + ): + raise HomeAssistantError( + f"Entity {entity.entity_id} does not support this service.", + translation_domain=DOMAIN, + translation_key="entity_not_supported", + translation_placeholders={ + "entity_id": entity.entity_id, + }, + ) + + entity: IdmHeatpumpEntity[CircuitMode] + + acknowledge = call.data.get("acknowledge_risk") + if acknowledge is not True: + raise HomeAssistantError( + f"Must acknowledge risk to call {SERVICE_SET_CIRCUIT_MODE}", + translation_domain=DOMAIN, + translation_key="risk_not_acknowledged", + ) + + raw_value = call.data.get("value") + + value = CircuitMode[raw_value] + + if value is None: + raise HomeAssistantError("invalid value: {value}") + + LOGGER.debug( + "Calling %s with value %s on %s", + SERVICE_SET_CIRCUIT_MODE, + value, + entity.entity_id, + ) + await entity.async_write_value(value) + + hass.services.async_register( + domain=DOMAIN, + service=SERVICE_SET_CIRCUIT_MODE, + service_func=handle_set_circuit_mode, + ) + async def handle_set_system_status(call: ServiceCall): target = call.data.get("target") entity = platform.entities[target] diff --git a/custom_components/idm_heatpump/sensor_addresses.py b/custom_components/idm_heatpump/sensor_addresses.py index 1c0bb57..71f9fb6 100644 --- a/custom_components/idm_heatpump/sensor_addresses.py +++ b/custom_components/idm_heatpump/sensor_addresses.py @@ -369,6 +369,8 @@ def heating_circuit_sensors(circuit: HeatingCircuit) -> list[IdmSensorAddress]: enum=CircuitMode, address=1393 + offset, name=f"mode_circuit_{circuit_name}", + device_class=SensorDeviceClass.ENUM, + supported_features=SensorFeatures.SET_CIRCUIT_MODE, ), _FloatSensorAddress( address=1401 + offset * 2, diff --git a/custom_components/idm_heatpump/services.yaml b/custom_components/idm_heatpump/services.yaml index 4c2ce83..62e3a43 100644 --- a/custom_components/idm_heatpump/services.yaml +++ b/custom_components/idm_heatpump/services.yaml @@ -112,6 +112,33 @@ set_room_mode: value: true translation_key: acknowledge_set_value +set_circuit_mode: + fields: + target: + required: true + selector: + entity: + integration: idm_heatpump + domain: sensor + device_class: enum + value: + required: true + selector: + select: + options: + - "off" + - timed + - normal + - eco + - manual_heat + - manual_cool + translation_key: circuit_mode_options + acknowledge_risk: + selector: + constant: + value: true + translation_key: acknowledge_set_value + set_binary: fields: target: diff --git a/custom_components/idm_heatpump/translations/de.json b/custom_components/idm_heatpump/translations/de.json index 4191b7c..6d36117 100644 --- a/custom_components/idm_heatpump/translations/de.json +++ b/custom_components/idm_heatpump/translations/de.json @@ -188,6 +188,24 @@ } } }, + "set_circuit_mode": { + "name": "Heizkreismodus setzen", + "description": "Sendet einen Wert vom Typ 'Heizkreismodus' an die Wärmepumpe.", + "fields": { + "target": { + "name": "Ziel", + "description": "Der Sensor für welchen der Wert gesendet werden soll." + }, + "value": { + "name": "Wert", + "description": "Der Wert der gesendet werden soll." + }, + "acknowledge_risk": { + "name": "Bestätigung", + "description": "Ich akzeptiere das Risiko" + } + } + }, "set_binary": { "name": "An-/Aus-Wert setzen", "description": "Sendet einen Wert vom Typ 'An/Aus' an die Wärmepumpe.", @@ -238,6 +256,16 @@ "comfort": "Komfort" } }, + "circuit_mode_options": { + "options": { + "off": "Aus", + "timed": "Zeitprogramm", + "normal": "Normal", + "eco": "Eco", + "manual_heat": "Manuell Heizen", + "manual_cool": "Manuell Kühlen" + } + }, "system_status_options": { "options": { "standby": "Standby", diff --git a/custom_components/idm_heatpump/translations/en.json b/custom_components/idm_heatpump/translations/en.json index f885791..8d3f0c6 100644 --- a/custom_components/idm_heatpump/translations/en.json +++ b/custom_components/idm_heatpump/translations/en.json @@ -188,6 +188,24 @@ } } }, + "set_circuit_mode": { + "name": "Set circuit mode value", + "description": "Sends a ciruict mode value to the heat pump.", + "fields": { + "target": { + "name": "Target", + "description": "The sensor for which to set the value." + }, + "value": { + "name": "Value", + "description": "The value to send." + }, + "acknowledge_risk": { + "name": "Confirmation", + "description": "I accept the risks" + } + } + }, "set_binary": { "name": "Set on/off value", "description": "Set on/off value", @@ -238,6 +256,16 @@ "comfort": "Comfort" } }, + "circuit_mode_options": { + "options": { + "off": "Off", + "timed": "Timed", + "normal": "Normal", + "eco": "Eco", + "manual_heat": "Manual Heating", + "manual_cool": "Manual Cooling" + } + }, "system_status_options": { "options": { "standby": "Standby",