mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
modbus config: count and slave_count can normally not be mixed. (#97902)
This commit is contained in:
parent
66685b796d
commit
1c56c39897
@ -67,6 +67,17 @@ def struct_validator(config: dict[str, Any]) -> dict[str, Any]:
|
|||||||
slave_count = config.get(CONF_SLAVE_COUNT, 0) + 1
|
slave_count = config.get(CONF_SLAVE_COUNT, 0) + 1
|
||||||
slave = config.get(CONF_SLAVE, 0)
|
slave = config.get(CONF_SLAVE, 0)
|
||||||
swap_type = config.get(CONF_SWAP, CONF_SWAP_NONE)
|
swap_type = config.get(CONF_SWAP, CONF_SWAP_NONE)
|
||||||
|
if (
|
||||||
|
slave_count > 1
|
||||||
|
and count > 1
|
||||||
|
and data_type not in (DataType.CUSTOM, DataType.STRING)
|
||||||
|
):
|
||||||
|
error = f"{name} {CONF_COUNT} cannot be mixed with {data_type}"
|
||||||
|
raise vol.Invalid(error)
|
||||||
|
if config[CONF_DATA_TYPE] != DataType.CUSTOM:
|
||||||
|
if structure:
|
||||||
|
error = f"{name} structure: cannot be mixed with {data_type}"
|
||||||
|
|
||||||
if config[CONF_DATA_TYPE] == DataType.CUSTOM:
|
if config[CONF_DATA_TYPE] == DataType.CUSTOM:
|
||||||
if slave or slave_count > 1:
|
if slave or slave_count > 1:
|
||||||
error = f"{name}: `{CONF_STRUCTURE}` illegal with `{CONF_SLAVE_COUNT}` / `{CONF_SLAVE}`"
|
error = f"{name}: `{CONF_STRUCTURE}` illegal with `{CONF_SLAVE_COUNT}` / `{CONF_SLAVE}`"
|
||||||
@ -96,17 +107,11 @@ def struct_validator(config: dict[str, Any]) -> dict[str, Any]:
|
|||||||
CONF_STRUCTURE: structure,
|
CONF_STRUCTURE: structure,
|
||||||
CONF_SWAP: swap_type,
|
CONF_SWAP: swap_type,
|
||||||
}
|
}
|
||||||
|
|
||||||
if structure:
|
|
||||||
error = f"{name} structure: cannot be mixed with {data_type}"
|
|
||||||
raise vol.Invalid(error)
|
|
||||||
if data_type not in DEFAULT_STRUCT_FORMAT:
|
if data_type not in DEFAULT_STRUCT_FORMAT:
|
||||||
error = f"Error in sensor {name}. data_type `{data_type}` not supported"
|
error = f"Error in sensor {name}. data_type `{data_type}` not supported"
|
||||||
raise vol.Invalid(error)
|
raise vol.Invalid(error)
|
||||||
if (slave or slave_count > 1) and data_type == DataType.STRING:
|
if slave_count > 1 and data_type == DataType.STRING:
|
||||||
error = (
|
error = f"{name}: `{data_type}` illegal with `{CONF_SLAVE_COUNT}`"
|
||||||
f"{name}: `{data_type}` illegal with `{CONF_SLAVE_COUNT}` / `{CONF_SLAVE}`"
|
|
||||||
)
|
|
||||||
raise vol.Invalid(error)
|
raise vol.Invalid(error)
|
||||||
|
|
||||||
if CONF_COUNT not in config:
|
if CONF_COUNT not in config:
|
||||||
|
@ -248,6 +248,12 @@ async def test_ok_struct_validator(do_config) -> None:
|
|||||||
CONF_DATA_TYPE: DataType.INT16,
|
CONF_DATA_TYPE: DataType.INT16,
|
||||||
CONF_SWAP: CONF_SWAP_WORD,
|
CONF_SWAP: CONF_SWAP_WORD,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
CONF_NAME: TEST_ENTITY_NAME,
|
||||||
|
CONF_COUNT: 2,
|
||||||
|
CONF_SLAVE_COUNT: 2,
|
||||||
|
CONF_DATA_TYPE: DataType.INT32,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_exception_struct_validator(do_config) -> None:
|
async def test_exception_struct_validator(do_config) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user