From 97c6fd0f8d8785fc3dd2b12b73b893496eb5adb2 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Thu, 8 Feb 2024 15:34:43 +0100 Subject: [PATCH] Allow modbus negative min/max value. (#109995) --- homeassistant/components/modbus/__init__.py | 4 ++-- tests/components/modbus/test_sensor.py | 22 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/modbus/__init__.py b/homeassistant/components/modbus/__init__.py index 0ceb1a2523fc3c..1151a5f1f013db 100644 --- a/homeassistant/components/modbus/__init__.py +++ b/homeassistant/components/modbus/__init__.py @@ -342,8 +342,8 @@ vol.Optional(CONF_UNIT_OF_MEASUREMENT): cv.string, vol.Exclusive(CONF_VIRTUAL_COUNT, "vir_sen_count"): cv.positive_int, vol.Exclusive(CONF_SLAVE_COUNT, "vir_sen_count"): cv.positive_int, - vol.Optional(CONF_MIN_VALUE): cv.positive_float, - vol.Optional(CONF_MAX_VALUE): cv.positive_float, + vol.Optional(CONF_MIN_VALUE): vol.Coerce(float), + vol.Optional(CONF_MAX_VALUE): vol.Coerce(float), vol.Optional(CONF_NAN_VALUE): nan_validator, vol.Optional(CONF_ZERO_SUPPRESS): cv.positive_float, } diff --git a/tests/components/modbus/test_sensor.py b/tests/components/modbus/test_sensor.py index 5ca38873c423c7..aa8b15585dc887 100644 --- a/tests/components/modbus/test_sensor.py +++ b/tests/components/modbus/test_sensor.py @@ -185,6 +185,28 @@ } ] }, + { + CONF_SENSORS: [ + { + CONF_NAME: TEST_ENTITY_NAME, + CONF_ADDRESS: 51, + CONF_DATA_TYPE: DataType.INT16, + CONF_MIN_VALUE: 1, + CONF_MAX_VALUE: 3, + } + ] + }, + { + CONF_SENSORS: [ + { + CONF_NAME: TEST_ENTITY_NAME, + CONF_ADDRESS: 51, + CONF_DATA_TYPE: DataType.INT16, + CONF_MIN_VALUE: -3, + CONF_MAX_VALUE: -1, + } + ] + }, ], ) async def test_config_sensor(hass: HomeAssistant, mock_modbus) -> None: