use write_registers also for target temp (#97475)
This commit is contained in:
parent
e4303e4534
commit
3ce05314e0
4 changed files with 126 additions and 10 deletions
|
@ -45,6 +45,7 @@ from .const import (
|
|||
CONF_MIN_TEMP,
|
||||
CONF_STEP,
|
||||
CONF_TARGET_TEMP,
|
||||
CONF_TARGET_TEMP_WRITE_REGISTERS,
|
||||
CONF_WRITE_REGISTERS,
|
||||
DataType,
|
||||
)
|
||||
|
@ -84,6 +85,9 @@ class ModbusThermostat(BaseStructPlatform, RestoreEntity, ClimateEntity):
|
|||
"""Initialize the modbus thermostat."""
|
||||
super().__init__(hub, config)
|
||||
self._target_temperature_register = config[CONF_TARGET_TEMP]
|
||||
self._target_temperature_write_registers = config[
|
||||
CONF_TARGET_TEMP_WRITE_REGISTERS
|
||||
]
|
||||
self._unit = config[CONF_TEMPERATURE_UNIT]
|
||||
|
||||
self._attr_current_temperature = None
|
||||
|
@ -107,7 +111,7 @@ class ModbusThermostat(BaseStructPlatform, RestoreEntity, ClimateEntity):
|
|||
self._attr_hvac_modes = cast(list[HVACMode], [])
|
||||
self._attr_hvac_mode = None
|
||||
self._hvac_mode_mapping: list[tuple[int, HVACMode]] = []
|
||||
self._hvac_mode_write_type = mode_config[CONF_WRITE_REGISTERS]
|
||||
self._hvac_mode_write_registers = mode_config[CONF_WRITE_REGISTERS]
|
||||
mode_value_config = mode_config[CONF_HVAC_MODE_VALUES]
|
||||
|
||||
for hvac_mode_kw, hvac_mode in (
|
||||
|
@ -133,7 +137,7 @@ class ModbusThermostat(BaseStructPlatform, RestoreEntity, ClimateEntity):
|
|||
|
||||
if CONF_HVAC_ONOFF_REGISTER in config:
|
||||
self._hvac_onoff_register = config[CONF_HVAC_ONOFF_REGISTER]
|
||||
self._hvac_onoff_write_type = config[CONF_WRITE_REGISTERS]
|
||||
self._hvac_onoff_write_registers = config[CONF_WRITE_REGISTERS]
|
||||
if HVACMode.OFF not in self._attr_hvac_modes:
|
||||
self._attr_hvac_modes.append(HVACMode.OFF)
|
||||
else:
|
||||
|
@ -150,7 +154,7 @@ class ModbusThermostat(BaseStructPlatform, RestoreEntity, ClimateEntity):
|
|||
"""Set new target hvac mode."""
|
||||
if self._hvac_onoff_register is not None:
|
||||
# Turn HVAC Off by writing 0 to the On/Off register, or 1 otherwise.
|
||||
if self._hvac_onoff_write_type:
|
||||
if self._hvac_onoff_write_registers:
|
||||
await self._hub.async_pymodbus_call(
|
||||
self._slave,
|
||||
self._hvac_onoff_register,
|
||||
|
@ -169,7 +173,7 @@ class ModbusThermostat(BaseStructPlatform, RestoreEntity, ClimateEntity):
|
|||
# Write a value to the mode register for the desired mode.
|
||||
for value, mode in self._hvac_mode_mapping:
|
||||
if mode == hvac_mode:
|
||||
if self._hvac_mode_write_type:
|
||||
if self._hvac_mode_write_registers:
|
||||
await self._hub.async_pymodbus_call(
|
||||
self._slave,
|
||||
self._hvac_mode_register,
|
||||
|
@ -212,12 +216,20 @@ class ModbusThermostat(BaseStructPlatform, RestoreEntity, ClimateEntity):
|
|||
DataType.INT16,
|
||||
DataType.UINT16,
|
||||
):
|
||||
result = await self._hub.async_pymodbus_call(
|
||||
self._slave,
|
||||
self._target_temperature_register,
|
||||
int(float(registers[0])),
|
||||
CALL_TYPE_WRITE_REGISTER,
|
||||
)
|
||||
if self._target_temperature_write_registers:
|
||||
result = await self._hub.async_pymodbus_call(
|
||||
self._slave,
|
||||
self._target_temperature_register,
|
||||
[int(float(registers[0]))],
|
||||
CALL_TYPE_WRITE_REGISTERS,
|
||||
)
|
||||
else:
|
||||
result = await self._hub.async_pymodbus_call(
|
||||
self._slave,
|
||||
self._target_temperature_register,
|
||||
int(float(registers[0])),
|
||||
CALL_TYPE_WRITE_REGISTER,
|
||||
)
|
||||
else:
|
||||
result = await self._hub.async_pymodbus_call(
|
||||
self._slave,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue