From af7a7640574382ffa8d5427426520c3a1b02a425 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Thu, 8 Feb 2024 10:00:00 +0100 Subject: [PATCH 1/2] Allow "scale" to be negative. --- homeassistant/components/modbus/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/modbus/__init__.py b/homeassistant/components/modbus/__init__.py index 0f674d4d0df49e..36e841f7859745 100644 --- a/homeassistant/components/modbus/__init__.py +++ b/homeassistant/components/modbus/__init__.py @@ -186,7 +186,7 @@ ] ), vol.Optional(CONF_STRUCTURE): cv.string, - vol.Optional(CONF_SCALE, default=1): cv.positive_float, + vol.Optional(CONF_SCALE, default=1): vol.Coerce(float), vol.Optional(CONF_OFFSET, default=0): vol.Coerce(float), vol.Optional(CONF_PRECISION): cv.positive_int, vol.Optional( From aa0e433fb11f8c785c2ea7f6716cc3cfef441591 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Thu, 8 Feb 2024 10:43:50 +0100 Subject: [PATCH 2/2] Review comments. --- tests/components/modbus/test_sensor.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/components/modbus/test_sensor.py b/tests/components/modbus/test_sensor.py index 97571041482e41..5ca38873c423c7 100644 --- a/tests/components/modbus/test_sensor.py +++ b/tests/components/modbus/test_sensor.py @@ -688,6 +688,16 @@ async def test_config_wrong_struct_sensor( False, "112594", ), + ( + { + CONF_DATA_TYPE: DataType.INT16, + CONF_SCALE: -1, + CONF_OFFSET: 0, + }, + [0x000A], + False, + "-10", + ), ], ) async def test_all_sensor(hass: HomeAssistant, mock_do_cycle, expected) -> None: