Skip to content

Commit

Permalink
feat: support more sensors for set_temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
kodebach committed Feb 16, 2025
1 parent e66ae52 commit 921895d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
23 changes: 19 additions & 4 deletions custom_components/idm_heatpump/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
from homeassistant.core import HomeAssistant, HomeAssistantError, ServiceCall
from homeassistant.helpers import entity_platform
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from pymodbus.client.mixin import ModbusClientMixin

from .const import (
DOMAIN,
SERVICE_SET_BATTERY,
SERVICE_SET_CIRCUIT_MODE,
SERVICE_SET_HUMIDITY,
SERVICE_SET_POWER,
SERVICE_SET_ROOM_MODE,
SERVICE_SET_CIRCUIT_MODE,
SERVICE_SET_SYSTEM_STATUS,
SERVICE_SET_TEMPERATURE,
RoomMode,
CircuitMode,
RoomMode,
SensorFeatures,
SystemStatus,
)
Expand Down Expand Up @@ -141,8 +142,6 @@ async def handle_set_temperature(call: ServiceCall):
},
)

entity: IdmHeatpumpEntity[float]

acknowledge = call.data.get("acknowledge_risk")
if acknowledge is not True:
raise HomeAssistantError(
Expand All @@ -151,7 +150,23 @@ async def handle_set_temperature(call: ServiceCall):
translation_key="risk_not_acknowledged",
)

entity: IdmHeatpumpEntity[int | float]

value: float = call.data.get("value")

if entity.sensor_address.datatype != ModbusClientMixin.DATATYPE.FLOAT32:
if int(value) != value:
raise HomeAssistantError(
f"Must be integer value to use {SERVICE_SET_TEMPERATURE} on {entity.entity_id}",
translation_domain=DOMAIN,
translation_key="integer_required",
translation_placeholders={
"entity_id": entity.entity_id,
},
)

value = int(value)

LOGGER.debug(
"Calling %s with value %s on %s",
SERVICE_SET_TEMPERATURE,
Expand Down
3 changes: 3 additions & 0 deletions custom_components/idm_heatpump/sensor_addresses.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ def heating_circuit_sensors(circuit: HeatingCircuit) -> list[IdmSensorAddress]:
unit=UnitOfTemperature.CELSIUS,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
supported_features=SensorFeatures.SET_TEMPERATURE,
min_value=-10,
max_value=80,
),
Expand All @@ -433,6 +434,7 @@ def heating_circuit_sensors(circuit: HeatingCircuit) -> list[IdmSensorAddress]:
unit=UnitOfTemperature.CELSIUS,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
supported_features=SensorFeatures.SET_TEMPERATURE,
min_value=-10,
max_value=80,
),
Expand Down Expand Up @@ -504,6 +506,7 @@ def heating_circuit_sensors(circuit: HeatingCircuit) -> list[IdmSensorAddress]:
address=1505 + offset,
name=f"curve_offset_{circuit_name}",
unit=UnitOfTemperature.CELSIUS,
supported_features=SensorFeatures.SET_TEMPERATURE,
),
_FloatSensorAddress(
address=1650 + offset * 2,
Expand Down
11 changes: 9 additions & 2 deletions custom_components/idm_heatpump/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,14 @@
}
},
"exceptions": {
"entity_not_supported": "Entität {entity_id} unterstützt diesen Service nicht.",
"risk_not_acknowledged": "'Bestätigung' muss aktiviert sein (d.h. acknowledge_risk=true gesetzt) um diesen Service auszuführen."
"entity_not_supported": {
"message": "Entität {entity_id} unterstützt diesen Service nicht."
},
"risk_not_acknowledged": {
"message": "'Bestätigung' muss aktiviert sein (d.h. acknowledge_risk=true gesetzt) um diesen Service auszuführen."
},
"integer_required": {
"message": "Entität {entity_id} unterstützt nur ganzzahlige Werte."
}
}
}
3 changes: 3 additions & 0 deletions custom_components/idm_heatpump/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@
},
"risk_not_acknowledged": {
"message": "You must enable 'Confirmation' (i.e. set acknowledge_risk=true) to call this service."
},
"integer_required": {
"message": "Enitty {entity_id} supports only integer values."
}
}
}

0 comments on commit 921895d

Please sign in to comment.