Skip to content

Commit

Permalink
feat: implement set_circuit_mode
Browse files Browse the repository at this point in the history
Closes #142
  • Loading branch information
swoga committed Dec 1, 2024
1 parent 2daa0a6 commit e222160
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 0 deletions.
2 changes: 2 additions & 0 deletions custom_components/idm_heatpump/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"

Expand Down
50 changes: 50 additions & 0 deletions custom_components/idm_heatpump/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions custom_components/idm_heatpump/sensor_addresses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 27 additions & 0 deletions custom_components/idm_heatpump/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 28 additions & 0 deletions custom_components/idm_heatpump/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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",
Expand Down
28 changes: 28 additions & 0 deletions custom_components/idm_heatpump/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit e222160

Please sign in to comment.