@@ -84,22 +84,26 @@ def validate_binary_sensor_auto_off_has_trigger(obj: dict) -> dict:
8484 if CONF_TRIGGERS not in obj and DOMAIN_BINARY_SENSOR in obj :
8585 binary_sensors : list [ConfigType ] = obj [DOMAIN_BINARY_SENSOR ]
8686 for binary_sensor in binary_sensors :
87- if binary_sensor_platform .CONF_AUTO_OFF in binary_sensor :
88- identifier = f"{ CONF_NAME } : { binary_sensor_platform .DEFAULT_NAME } "
89- if (
90- (name := binary_sensor .get (CONF_NAME ))
91- and isinstance (name , Template )
92- and name .template != binary_sensor_platform .DEFAULT_NAME
93- ):
94- identifier = f"{ CONF_NAME } : { name .template } "
95- elif default_entity_id := binary_sensor .get (CONF_DEFAULT_ENTITY_ID ):
96- identifier = f"{ CONF_DEFAULT_ENTITY_ID } : { default_entity_id } "
97- elif unique_id := binary_sensor .get (CONF_UNIQUE_ID ):
98- identifier = f"{ CONF_UNIQUE_ID } : { unique_id } "
87+ if binary_sensor_platform .CONF_AUTO_OFF not in binary_sensor :
88+ continue
9989
100- raise vol .Invalid (
101- f"The auto_off option for template binary sensor: { identifier } requires a trigger, remove the auto_off option or rewrite configuration to use a trigger"
102- )
90+ identifier = f"{ CONF_NAME } : { binary_sensor_platform .DEFAULT_NAME } "
91+ if (
92+ (name := binary_sensor .get (CONF_NAME ))
93+ and isinstance (name , Template )
94+ and name .template != binary_sensor_platform .DEFAULT_NAME
95+ ):
96+ identifier = f"{ CONF_NAME } : { name .template } "
97+ elif default_entity_id := binary_sensor .get (CONF_DEFAULT_ENTITY_ID ):
98+ identifier = f"{ CONF_DEFAULT_ENTITY_ID } : { default_entity_id } "
99+ elif unique_id := binary_sensor .get (CONF_UNIQUE_ID ):
100+ identifier = f"{ CONF_UNIQUE_ID } : { unique_id } "
101+
102+ raise vol .Invalid (
103+ f"The auto_off option for template binary sensor: { identifier } "
104+ "requires a trigger, remove the auto_off option or rewrite "
105+ "configuration to use a trigger"
106+ )
103107
104108 return obj
105109
0 commit comments