From 9d697c502663a89c8c994fb4d93a2bbb7e31c445 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Wed, 3 Jan 2024 13:42:55 +0100 Subject: [PATCH] Only set precision in modbus if not configured. (#106952) Only set precision if not configured. --- homeassistant/components/modbus/__init__.py | 2 +- homeassistant/components/modbus/base_platform.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/modbus/__init__.py b/homeassistant/components/modbus/__init__.py index 89a50862b6c..cc1b3c74356 100644 --- a/homeassistant/components/modbus/__init__.py +++ b/homeassistant/components/modbus/__init__.py @@ -190,7 +190,7 @@ BASE_STRUCT_SCHEMA = BASE_COMPONENT_SCHEMA.extend( vol.Optional(CONF_STRUCTURE): cv.string, vol.Optional(CONF_SCALE, default=1): number_validator, vol.Optional(CONF_OFFSET, default=0): number_validator, - vol.Optional(CONF_PRECISION, default=0): cv.positive_int, + vol.Optional(CONF_PRECISION): cv.positive_int, vol.Optional( CONF_SWAP, ): vol.In( diff --git a/homeassistant/components/modbus/base_platform.py b/homeassistant/components/modbus/base_platform.py index 1c7c8f65140..d3ec06bbdd7 100644 --- a/homeassistant/components/modbus/base_platform.py +++ b/homeassistant/components/modbus/base_platform.py @@ -185,10 +185,8 @@ class BaseStructPlatform(BasePlatform, RestoreEntity): self._swap = config[CONF_SWAP] self._data_type = config[CONF_DATA_TYPE] self._structure: str = config[CONF_STRUCTURE] - self._precision = config[CONF_PRECISION] self._scale = config[CONF_SCALE] - if self._scale < 1 and not self._precision: - self._precision = 2 + self._precision = config.get(CONF_PRECISION, 2 if self._scale < 1 else 0) self._offset = config[CONF_OFFSET] self._slave_count = config.get(CONF_SLAVE_COUNT, None) or config.get( CONF_VIRTUAL_COUNT, 0