Allow duplicate names in different modbus entities (#112701)
Allow duplicate names in different entities.pull/113250/head
parent
c2543289b7
commit
f7b64244b8
|
@ -301,13 +301,14 @@ def check_config(config: dict) -> dict:
|
|||
|
||||
def validate_entity(
|
||||
hub_name: str,
|
||||
component: str,
|
||||
entity: dict,
|
||||
minimum_scan_interval: int,
|
||||
ent_names: set,
|
||||
ent_addr: set,
|
||||
) -> bool:
|
||||
"""Validate entity."""
|
||||
name = entity[CONF_NAME]
|
||||
name = f"{component}.{entity[CONF_NAME]}"
|
||||
addr = f"{hub_name}{entity[CONF_ADDRESS]}"
|
||||
scan_interval = entity.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
|
||||
if 0 < scan_interval < 5:
|
||||
|
@ -370,7 +371,7 @@ def check_config(config: dict) -> dict:
|
|||
continue
|
||||
minimum_scan_interval = 9999
|
||||
no_entities = True
|
||||
for _component, conf_key in PLATFORMS:
|
||||
for component, conf_key in PLATFORMS:
|
||||
if conf_key not in hub:
|
||||
continue
|
||||
no_entities = False
|
||||
|
@ -379,6 +380,7 @@ def check_config(config: dict) -> dict:
|
|||
while entity_inx < len(entities):
|
||||
if not validate_entity(
|
||||
hub[CONF_NAME],
|
||||
component,
|
||||
entities[entity_inx],
|
||||
minimum_scan_interval,
|
||||
ent_names,
|
||||
|
|
|
@ -858,6 +858,30 @@ async def test_duplicate_fan_mode_validator(do_config) -> None:
|
|||
],
|
||||
2,
|
||||
),
|
||||
(
|
||||
[
|
||||
{
|
||||
CONF_NAME: TEST_MODBUS_NAME,
|
||||
CONF_TYPE: TCP,
|
||||
CONF_HOST: TEST_MODBUS_HOST,
|
||||
CONF_PORT: TEST_PORT_TCP,
|
||||
CONF_TIMEOUT: 3,
|
||||
CONF_SENSORS: [
|
||||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME,
|
||||
CONF_ADDRESS: 117,
|
||||
CONF_SLAVE: 0,
|
||||
},
|
||||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME,
|
||||
CONF_ADDRESS: 1179,
|
||||
CONF_SLAVE: 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
1,
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_duplicate_addresses(do_config, sensor_cnt) -> None:
|
||||
|
@ -867,6 +891,41 @@ async def test_duplicate_addresses(do_config, sensor_cnt) -> None:
|
|||
assert len(do_config[use_inx][CONF_SENSORS]) == sensor_cnt
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"do_config",
|
||||
[
|
||||
[
|
||||
{
|
||||
CONF_NAME: TEST_MODBUS_NAME,
|
||||
CONF_TYPE: TCP,
|
||||
CONF_HOST: TEST_MODBUS_HOST,
|
||||
CONF_PORT: TEST_PORT_TCP,
|
||||
CONF_TIMEOUT: 3,
|
||||
CONF_SENSORS: [
|
||||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME,
|
||||
CONF_ADDRESS: 117,
|
||||
CONF_SLAVE: 0,
|
||||
},
|
||||
],
|
||||
CONF_BINARY_SENSORS: [
|
||||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME + "1",
|
||||
CONF_ADDRESS: 1179,
|
||||
CONF_SLAVE: 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
],
|
||||
)
|
||||
async def test_no_duplicate_names(do_config) -> None:
|
||||
"""Test duplicate entity validator."""
|
||||
check_config(do_config)
|
||||
assert len(do_config[0][CONF_SENSORS]) == 1
|
||||
assert len(do_config[0][CONF_BINARY_SENSORS]) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"do_config",
|
||||
[
|
||||
|
|
Loading…
Reference in New Issue