diff --git a/esphome/core/entity_helpers.py b/esphome/core/entity_helpers.py index 2742c636c07..aeb36c267be 100644 --- a/esphome/core/entity_helpers.py +++ b/esphome/core/entity_helpers.py @@ -559,6 +559,8 @@ class SubEntities: raise ValueError(f"{entity_id}: apply= needs a parent") if publish is not None and (apply is None or self.apply_entity.publish is None): raise ValueError(f"{entity_id}: publish= needs apply= on a stateful domain") + if publish not in (None, "before", "after"): + raise ValueError(f'{entity_id}: publish= must be "before" or "after"') if apply is None: var = await self.new_entity(conf, *args, **kwargs) diff --git a/tests/unit_tests/core/test_entity_helpers.py b/tests/unit_tests/core/test_entity_helpers.py index bd754ca6620..7d6d7960429 100644 --- a/tests/unit_tests/core/test_entity_helpers.py +++ b/tests/unit_tests/core/test_entity_helpers.py @@ -1458,6 +1458,12 @@ async def test_sub_entities_apply_parent_id( {"publish": "before"}, "publish= needs", ), + ( + _SWITCH_APPLY, + _apply_conf("k_id"), + {"apply": "x()", "publish": "Before"}, + "must be", + ), ], ) async def test_sub_entities_apply_errors(