mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Fix entity hash collisions by enforcing unique names across devices per platform (#9276)
This commit is contained in:
		| @@ -1,6 +1,6 @@ | ||||
| esphome: | ||||
|   name: duplicate-entities-test | ||||
|   # Define devices to test multi-device duplicate handling | ||||
|   # Define devices to test multi-device unique name validation | ||||
|   devices: | ||||
|     - id: controller_1 | ||||
|       name: Controller 1 | ||||
| @@ -13,31 +13,31 @@ host: | ||||
| api:  # Port will be automatically injected | ||||
| logger: | ||||
| 
 | ||||
| # Test that duplicate entity names are allowed on different devices | ||||
| # Test that duplicate entity names are NOT allowed on different devices | ||||
| 
 | ||||
| # Scenario 1: Same sensor name on different devices (allowed) | ||||
| # Scenario 1: Different sensor names on different devices (allowed) | ||||
| sensor: | ||||
|   - platform: template | ||||
|     name: Temperature | ||||
|     name: Temperature Controller 1 | ||||
|     device_id: controller_1 | ||||
|     lambda: return 21.0; | ||||
|     update_interval: 0.1s | ||||
| 
 | ||||
|   - platform: template | ||||
|     name: Temperature | ||||
|     name: Temperature Controller 2 | ||||
|     device_id: controller_2 | ||||
|     lambda: return 22.0; | ||||
|     update_interval: 0.1s | ||||
| 
 | ||||
|   - platform: template | ||||
|     name: Temperature | ||||
|     name: Temperature Controller 3 | ||||
|     device_id: controller_3 | ||||
|     lambda: return 23.0; | ||||
|     update_interval: 0.1s | ||||
| 
 | ||||
|   # Main device sensor (no device_id) | ||||
|   - platform: template | ||||
|     name: Temperature | ||||
|     name: Temperature Main | ||||
|     lambda: return 20.0; | ||||
|     update_interval: 0.1s | ||||
| 
 | ||||
| @@ -47,20 +47,20 @@ sensor: | ||||
|     lambda: return 60.0; | ||||
|     update_interval: 0.1s | ||||
| 
 | ||||
| # Scenario 2: Same binary sensor name on different devices (allowed) | ||||
| # Scenario 2: Different binary sensor names on different devices | ||||
| binary_sensor: | ||||
|   - platform: template | ||||
|     name: Status | ||||
|     name: Status Controller 1 | ||||
|     device_id: controller_1 | ||||
|     lambda: return true; | ||||
| 
 | ||||
|   - platform: template | ||||
|     name: Status | ||||
|     name: Status Controller 2 | ||||
|     device_id: controller_2 | ||||
|     lambda: return false; | ||||
| 
 | ||||
|   - platform: template | ||||
|     name: Status | ||||
|     name: Status Main | ||||
|     lambda: return true;  # Main device | ||||
| 
 | ||||
|   # Different platform can have same name as sensor | ||||
| @@ -68,43 +68,43 @@ binary_sensor: | ||||
|     name: Temperature | ||||
|     lambda: return true; | ||||
| 
 | ||||
| # Scenario 3: Same text sensor name on different devices | ||||
| # Scenario 3: Different text sensor names on different devices | ||||
| text_sensor: | ||||
|   - platform: template | ||||
|     name: Device Info | ||||
|     name: Device Info Controller 1 | ||||
|     device_id: controller_1 | ||||
|     lambda: return {"Controller 1 Active"}; | ||||
|     update_interval: 0.1s | ||||
| 
 | ||||
|   - platform: template | ||||
|     name: Device Info | ||||
|     name: Device Info Controller 2 | ||||
|     device_id: controller_2 | ||||
|     lambda: return {"Controller 2 Active"}; | ||||
|     update_interval: 0.1s | ||||
| 
 | ||||
|   - platform: template | ||||
|     name: Device Info | ||||
|     name: Device Info Main | ||||
|     lambda: return {"Main Device Active"}; | ||||
|     update_interval: 0.1s | ||||
| 
 | ||||
| # Scenario 4: Same switch name on different devices | ||||
| # Scenario 4: Different switch names on different devices | ||||
| switch: | ||||
|   - platform: template | ||||
|     name: Power | ||||
|     name: Power Controller 1 | ||||
|     device_id: controller_1 | ||||
|     lambda: return false; | ||||
|     turn_on_action: [] | ||||
|     turn_off_action: [] | ||||
| 
 | ||||
|   - platform: template | ||||
|     name: Power | ||||
|     name: Power Controller 2 | ||||
|     device_id: controller_2 | ||||
|     lambda: return true; | ||||
|     turn_on_action: [] | ||||
|     turn_off_action: [] | ||||
| 
 | ||||
|   - platform: template | ||||
|     name: Power | ||||
|     name: Power Controller 3 | ||||
|     device_id: controller_3 | ||||
|     lambda: return false; | ||||
|     turn_on_action: [] | ||||
| @@ -117,26 +117,54 @@ switch: | ||||
|     turn_on_action: [] | ||||
|     turn_off_action: [] | ||||
| 
 | ||||
| # Scenario 5: Empty names on different devices (should use device name) | ||||
| # Scenario 5: Buttons with unique names | ||||
| button: | ||||
|   - platform: template | ||||
|     name: "" | ||||
|     name: "Reset Controller 1" | ||||
|     device_id: controller_1 | ||||
|     on_press: [] | ||||
| 
 | ||||
|   - platform: template | ||||
|     name: "" | ||||
|     name: "Reset Controller 2" | ||||
|     device_id: controller_2 | ||||
|     on_press: [] | ||||
| 
 | ||||
|   - platform: template | ||||
|     name: "" | ||||
|     name: "Reset Main" | ||||
|     on_press: []  # Main device | ||||
| 
 | ||||
| # Scenario 6: Special characters in names | ||||
| # Scenario 6: Empty names (should use device names) | ||||
| select: | ||||
|   - platform: template | ||||
|     name: "" | ||||
|     device_id: controller_1 | ||||
|     options: | ||||
|       - "Option 1" | ||||
|       - "Option 2" | ||||
|     lambda: return {"Option 1"}; | ||||
|     set_action: [] | ||||
| 
 | ||||
|   - platform: template | ||||
|     name: "" | ||||
|     device_id: controller_2 | ||||
|     options: | ||||
|       - "Option 1" | ||||
|       - "Option 2" | ||||
|     lambda: return {"Option 1"}; | ||||
|     set_action: [] | ||||
| 
 | ||||
|   - platform: template | ||||
|     name: ""  # Main device | ||||
|     options: | ||||
|       - "Option 1" | ||||
|       - "Option 2" | ||||
|     lambda: return {"Option 1"}; | ||||
|     set_action: [] | ||||
| 
 | ||||
| # Scenario 7: Special characters in names - now with unique names | ||||
| number: | ||||
|   - platform: template | ||||
|     name: "Temperature Setpoint!" | ||||
|     name: "Temperature Setpoint! Controller 1" | ||||
|     device_id: controller_1 | ||||
|     min_value: 10.0 | ||||
|     max_value: 30.0 | ||||
| @@ -145,7 +173,7 @@ number: | ||||
|     set_action: [] | ||||
| 
 | ||||
|   - platform: template | ||||
|     name: "Temperature Setpoint!" | ||||
|     name: "Temperature Setpoint! Controller 2" | ||||
|     device_id: controller_2 | ||||
|     min_value: 10.0 | ||||
|     max_value: 30.0 | ||||
		Reference in New Issue
	
	Block a user