mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	[gpio] Auto-disable interrupts for shared GPIO pins in binary sensors (#9701)
This commit is contained in:
		
				
					committed by
					
						 Jesse Hills
						Jesse Hills
					
				
			
			
				
	
			
			
			
						parent
						
							6fe4ffa0cf
						
					
				
				
					commit
					7ac60c15dc
				
			| @@ -4,7 +4,13 @@ from esphome import pins | ||||
| import esphome.codegen as cg | ||||
| from esphome.components import binary_sensor | ||||
| import esphome.config_validation as cv | ||||
| from esphome.const import CONF_ID, CONF_NAME, CONF_NUMBER, CONF_PIN | ||||
| from esphome.const import ( | ||||
|     CONF_ALLOW_OTHER_USES, | ||||
|     CONF_ID, | ||||
|     CONF_NAME, | ||||
|     CONF_NUMBER, | ||||
|     CONF_PIN, | ||||
| ) | ||||
| from esphome.core import CORE | ||||
|  | ||||
| from .. import gpio_ns | ||||
| @@ -76,6 +82,18 @@ async def to_code(config): | ||||
|         ) | ||||
|         use_interrupt = False | ||||
|  | ||||
|     # Check if pin is shared with other components (allow_other_uses) | ||||
|     # When a pin is shared, interrupts can interfere with other components | ||||
|     # (e.g., duty_cycle sensor) that need to monitor the pin's state changes | ||||
|     if use_interrupt and config[CONF_PIN].get(CONF_ALLOW_OTHER_USES, False): | ||||
|         _LOGGER.info( | ||||
|             "GPIO binary_sensor '%s': Disabling interrupts because pin %s is shared with other components. " | ||||
|             "The sensor will use polling mode for compatibility with other pin uses.", | ||||
|             config.get(CONF_NAME, config[CONF_ID]), | ||||
|             config[CONF_PIN][CONF_NUMBER], | ||||
|         ) | ||||
|         use_interrupt = False | ||||
|  | ||||
|     cg.add(var.set_use_interrupt(use_interrupt)) | ||||
|     if use_interrupt: | ||||
|         cg.add(var.set_interrupt_type(config[CONF_INTERRUPT_TYPE])) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user