diff --git a/homeassistant/components/modbus/__init__.py b/homeassistant/components/modbus/__init__.py index d6fe41f66fc..fd8e15b9b7e 100644 --- a/homeassistant/components/modbus/__init__.py +++ b/homeassistant/components/modbus/__init__.py @@ -136,7 +136,7 @@ BASE_STRUCT_SCHEMA = BASE_COMPONENT_SCHEMA.extend( ] ), vol.Optional(CONF_COUNT): cv.positive_int, - vol.Optional(CONF_DATA_TYPE, default=DataType.INT): vol.In( + vol.Optional(CONF_DATA_TYPE, default=DataType.INT16): vol.In( [ DataType.INT8, DataType.INT16, @@ -150,9 +150,6 @@ BASE_STRUCT_SCHEMA = BASE_COMPONENT_SCHEMA.extend( DataType.FLOAT32, DataType.FLOAT64, DataType.STRING, - DataType.INT, - DataType.UINT, - DataType.FLOAT, DataType.STRING, DataType.CUSTOM, ] diff --git a/homeassistant/components/modbus/const.py b/homeassistant/components/modbus/const.py index 7244e2a16e6..b09d75f27e0 100644 --- a/homeassistant/components/modbus/const.py +++ b/homeassistant/components/modbus/const.py @@ -76,9 +76,6 @@ class DataType(str, Enum): """Data types used by sensor etc.""" CUSTOM = "custom" - FLOAT = "float" # deprecated - INT = "int" # deprecated - UINT = "uint" # deprecated STRING = "string" INT8 = "int8" INT16 = "int16" diff --git a/homeassistant/components/modbus/validators.py b/homeassistant/components/modbus/validators.py index 4f910043d12..646e1129c4e 100644 --- a/homeassistant/components/modbus/validators.py +++ b/homeassistant/components/modbus/validators.py @@ -39,23 +39,6 @@ from .const import ( _LOGGER = logging.getLogger(__name__) -OLD_DATA_TYPES = { - DataType.INT: { - 1: DataType.INT16, - 2: DataType.INT32, - 4: DataType.INT64, - }, - DataType.UINT: { - 1: DataType.UINT16, - 2: DataType.UINT32, - 4: DataType.UINT64, - }, - DataType.FLOAT: { - 1: DataType.FLOAT16, - 2: DataType.FLOAT32, - 4: DataType.FLOAT64, - }, -} ENTRY = namedtuple("ENTRY", ["struct_id", "register_count"]) DEFAULT_STRUCT_FORMAT = { DataType.INT8: ENTRY("b", 1), @@ -81,19 +64,14 @@ def struct_validator(config: dict[str, Any]) -> dict[str, Any]: name = config[CONF_NAME] structure = config.get(CONF_STRUCTURE) swap_type = config.get(CONF_SWAP) - if data_type in (DataType.INT, DataType.UINT, DataType.FLOAT): - error = f"{name} with {data_type} is not valid, trying to convert" - _LOGGER.warning(error) - try: - data_type = OLD_DATA_TYPES[data_type][config.get(CONF_COUNT, 1)] - config[CONF_DATA_TYPE] = data_type - except KeyError as exp: - error = f"{name} cannot convert automatically {data_type}" - raise vol.Invalid(error) from exp if config[CONF_DATA_TYPE] != DataType.CUSTOM: if structure: error = f"{name} structure: cannot be mixed with {data_type}" raise vol.Invalid(error) + if data_type not in DEFAULT_STRUCT_FORMAT: + error = f"Error in sensor {name}. data_type `{data_type}` not supported" + raise vol.Invalid(error) + structure = f">{DEFAULT_STRUCT_FORMAT[data_type].struct_id}" if CONF_COUNT not in config: config[CONF_COUNT] = DEFAULT_STRUCT_FORMAT[data_type].register_count diff --git a/tests/components/modbus/test_init.py b/tests/components/modbus/test_init.py index b416ebad537..127389ee50f 100644 --- a/tests/components/modbus/test_init.py +++ b/tests/components/modbus/test_init.py @@ -176,7 +176,7 @@ async def test_ok_struct_validator(do_config): { CONF_NAME: TEST_ENTITY_NAME, CONF_COUNT: 8, - CONF_DATA_TYPE: DataType.INT, + CONF_DATA_TYPE: "int", }, { CONF_NAME: TEST_ENTITY_NAME,