diff --git a/custom_components/idm_heatpump/sensor.py b/custom_components/idm_heatpump/sensor.py index b8ab732..654e937 100644 --- a/custom_components/idm_heatpump/sensor.py +++ b/custom_components/idm_heatpump/sensor.py @@ -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, ) @@ -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( @@ -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, diff --git a/custom_components/idm_heatpump/sensor_addresses.py b/custom_components/idm_heatpump/sensor_addresses.py index a2125f0..47bd1a2 100644 --- a/custom_components/idm_heatpump/sensor_addresses.py +++ b/custom_components/idm_heatpump/sensor_addresses.py @@ -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, ), @@ -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, ), @@ -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, diff --git a/custom_components/idm_heatpump/translations/de.json b/custom_components/idm_heatpump/translations/de.json index b5206fc..c88e929 100644 --- a/custom_components/idm_heatpump/translations/de.json +++ b/custom_components/idm_heatpump/translations/de.json @@ -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." + } } } \ No newline at end of file diff --git a/custom_components/idm_heatpump/translations/en.json b/custom_components/idm_heatpump/translations/en.json index f0a2331..a3cb32b 100644 --- a/custom_components/idm_heatpump/translations/en.json +++ b/custom_components/idm_heatpump/translations/en.json @@ -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." } } } \ No newline at end of file