Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
288bb62
Support of current temp scale and offset
illia-piskurov Aug 21, 2025
3d222d0
Merge branch 'dev' into curr_temp_scale_and_offset
janiversen Aug 21, 2025
6feb103
Try another way
illia-piskurov Aug 22, 2025
5061afb
Separated offset and scale
illia-piskurov Sep 1, 2025
ab50e43
Removed mistakes
illia-piskurov Sep 2, 2025
29b3202
Change in sensor.py
illia-piskurov Sep 2, 2025
2fd3da3
Merge branch 'home-assistant:dev' into curr_temp_scale_and_offset
crug80 Sep 5, 2025
818221d
rev2-crug
crug80 Sep 5, 2025
148002c
Merge branch 'dev' into curr_temp_scale_and_offset
crug80 Sep 5, 2025
57af459
Merge branch 'dev' into curr_temp_scale_and_offset
crug80 Sep 8, 2025
ad3da15
Merge branch 'dev' into curr_temp_scale_and_offset
janiversen Sep 8, 2025
33fec8d
floats
crug80 Sep 8, 2025
a8da718
fix requests
crug80 Sep 9, 2025
cf5662d
Merge branch 'dev' into curr_temp_scale_and_offset
crug80 Sep 9, 2025
0cd6f6a
fix requests 2
crug80 Sep 9, 2025
e45ce85
Merge branch 'home-assistant:dev' into curr_temp_scale_and_offset
crug80 Sep 12, 2025
91366b5
Merge branch 'dev' into curr_temp_scale_and_offset
janiversen Sep 13, 2025
c9ae098
fix requests 3
crug80 Sep 13, 2025
30ef8e5
Merge branch 'dev' into curr_temp_scale_and_offset
crug80 Sep 16, 2025
cab1082
Merge branch 'dev' into curr_temp_scale_and_offset
crug80 Sep 22, 2025
2b650a2
fix ruff
crug80 Sep 22, 2025
010f556
Merge branch 'dev' into curr_temp_scale_and_offset
illia-piskurov Sep 24, 2025
82a53ed
Merge branch 'dev' into curr_temp_scale_and_offset
illia-piskurov Sep 30, 2025
7188f6c
Merge branch 'dev' into curr_temp_scale_and_offset
crug80 Oct 8, 2025
de33a03
Merge branch 'dev' into curr_temp_scale_and_offset
crug80 Oct 19, 2025
f7d30ef
Merge branch 'dev' into curr_temp_scale_and_offset
frenck Oct 19, 2025
bea9139
Update homeassistant/components/modbus/validators.py
crug80 Oct 20, 2025
ae53aef
Merge branch 'dev' into curr_temp_scale_and_offset
illia-piskurov Oct 30, 2025
9032dbf
Merge branch 'home-assistant:dev' into curr_temp_scale_and_offset
crug80 Oct 30, 2025
3496c7c
fix emontnemery request
crug80 Oct 30, 2025
c56ef49
Merge branch 'dev' into curr_temp_scale_and_offset
crug80 Oct 30, 2025
d60deca
Merge branch 'dev' into curr_temp_scale_and_offset
crug80 Oct 31, 2025
4153de7
Merge branch 'dev' into curr_temp_scale_and_offset
emontnemery Nov 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions homeassistant/components/modbus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
CONF_BYTESIZE,
CONF_CLIMATES,
CONF_COLOR_TEMP_REGISTER,
CONF_CURRENT_TEMP_OFFSET,
CONF_CURRENT_TEMP_SCALE,
CONF_DATA_TYPE,
CONF_DEVICE_ADDRESS,
CONF_FAN_MODE_AUTO,
Expand Down Expand Up @@ -212,6 +214,8 @@
vol.Optional(CONF_STRUCTURE): cv.string,
vol.Optional(CONF_SCALE, default=1): vol.Coerce(float),
vol.Optional(CONF_OFFSET, default=0): vol.Coerce(float),
vol.Inclusive(CONF_CURRENT_TEMP_SCALE, "current_temp"): vol.Coerce(float),
Comment thread
illia-piskurov marked this conversation as resolved.
Outdated
vol.Inclusive(CONF_CURRENT_TEMP_OFFSET, "current_temp"): vol.Coerce(float),
Comment thread
illia-piskurov marked this conversation as resolved.
Outdated
vol.Optional(CONF_PRECISION): cv.positive_int,
vol.Optional(
CONF_SWAP,
Expand Down
19 changes: 18 additions & 1 deletion homeassistant/components/modbus/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
CALL_TYPE_WRITE_REGISTER,
CALL_TYPE_WRITE_REGISTERS,
CONF_CLIMATES,
CONF_CURRENT_TEMP_OFFSET,
CONF_CURRENT_TEMP_SCALE,
CONF_FAN_MODE_AUTO,
CONF_FAN_MODE_DIFFUSE,
CONF_FAN_MODE_FOCUS,
Expand Down Expand Up @@ -301,6 +303,13 @@ def __init__(
else:
self._hvac_onoff_coil = None

if CONF_CURRENT_TEMP_SCALE in config:
Comment thread
illia-piskurov marked this conversation as resolved.
Outdated
self._current_temp_scale = config[CONF_CURRENT_TEMP_SCALE]
self._current_temp_offset = config[CONF_CURRENT_TEMP_OFFSET]
Comment thread
illia-piskurov marked this conversation as resolved.
Outdated
else:
self._current_temp_scale = None
self._current_temp_offset = None

async def async_added_to_hass(self) -> None:
"""Handle entity which will be added."""
await self.async_base_added_to_hass()
Expand Down Expand Up @@ -474,9 +483,17 @@ async def _async_update(self) -> None:
],
)

self._attr_current_temperature = await self._async_read_register(
current_temp_register_value = await self._async_read_register(
Comment thread
illia-piskurov marked this conversation as resolved.
Outdated
self._input_type, self._address
)
if self._current_temp_scale is None:
self._attr_current_temperature = current_temp_register_value
else:
# Undo global scale/offset
raw_value = (current_temp_register_value - self._offset) / self._scale
new_value = raw_value * self._current_temp_scale + self._current_temp_offset
self._attr_current_temperature = new_value
Comment thread
illia-piskurov marked this conversation as resolved.
Outdated

# Read the HVAC mode register if defined
if self._hvac_mode_register is not None:
hvac_mode = await self._async_read_register(
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/modbus/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
CONF_CLIMATES = "climates"
CONF_BRIGHTNESS_REGISTER = "brightness_address"
CONF_COLOR_TEMP_REGISTER = "color_temp_address"
CONF_CURRENT_TEMP_SCALE = "current_temp_scale"
CONF_CURRENT_TEMP_OFFSET = "current_temp_offset"
CONF_DATA_TYPE = "data_type"
CONF_DEVICE_ADDRESS = "device_address"
CONF_FANS = "fans"
Expand Down
81 changes: 81 additions & 0 deletions tests/components/modbus/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
from homeassistant.components.homeassistant import SERVICE_UPDATE_ENTITY
from homeassistant.components.modbus.const import (
CONF_CLIMATES,
CONF_CURRENT_TEMP_OFFSET,
CONF_CURRENT_TEMP_SCALE,
CONF_DATA_TYPE,
CONF_DEVICE_ADDRESS,
CONF_FAN_MODE_AUTO,
Expand Down Expand Up @@ -74,6 +76,7 @@
CONF_HVAC_ONOFF_REGISTER,
CONF_MAX_TEMP,
CONF_MIN_TEMP,
CONF_SCALE,
CONF_SWING_MODE_REGISTER,
CONF_SWING_MODE_SWING_BOTH,
CONF_SWING_MODE_SWING_HORIZ,
Expand All @@ -92,6 +95,7 @@
ATTR_TEMPERATURE,
CONF_ADDRESS,
CONF_NAME,
CONF_OFFSET,
CONF_PLATFORM,
CONF_SCAN_INTERVAL,
CONF_SLAVE,
Expand Down Expand Up @@ -928,6 +932,83 @@ async def test_hvac_onoff_register_transition_update(
assert state.state == result_after


@pytest.mark.parametrize(
("do_config", "result", "register_words"),
[
(
{
CONF_CLIMATES: [
{
CONF_NAME: TEST_ENTITY_NAME,
CONF_TARGET_TEMP: 120,
CONF_ADDRESS: 117,
CONF_SLAVE: 10,
CONF_SCAN_INTERVAL: 0,
CONF_DATA_TYPE: DataType.INT32,
},
]
},
17,
[0, 17],
),
(
{
CONF_CLIMATES: [
{
CONF_NAME: TEST_ENTITY_NAME,
CONF_TARGET_TEMP: 120,
CONF_ADDRESS: 117,
CONF_SLAVE: 10,
CONF_SCAN_INTERVAL: 0,
CONF_CURRENT_TEMP_SCALE: 0.01,
CONF_CURRENT_TEMP_OFFSET: 10,
CONF_SCALE: 10,
CONF_OFFSET: 20,
},
]
},
35,
[2500],
),
(
{
CONF_CLIMATES: [
{
CONF_NAME: TEST_ENTITY_NAME,
CONF_TARGET_TEMP: 120,
CONF_ADDRESS: 117,
CONF_SLAVE: 10,
CONF_SCAN_INTERVAL: 0,
CONF_CURRENT_TEMP_SCALE: 0.01,
CONF_CURRENT_TEMP_OFFSET: 10,
CONF_SCALE: 10,
CONF_OFFSET: -20,
},
]
},
29,
[1900],
),
],
)
async def test_config_current_temp_scale_and_offset(
hass: HomeAssistant, mock_modbus_ha, result, register_words
) -> None:
"""Test behavior with different configurations for temperature scaling."""
mock_modbus_ha.read_holding_registers.return_value = ReadResult(register_words)

await hass.services.async_call(
HOMEASSISTANT_DOMAIN,
SERVICE_UPDATE_ENTITY,
{ATTR_ENTITY_ID: ENTITY_ID},
blocking=True,
)
await hass.async_block_till_done()

state = hass.states.get(ENTITY_ID)
assert state.attributes.get("current_temperature") == result


@pytest.mark.parametrize(
("do_config", "result", "register_words"),
[
Expand Down