|
22 | 22 | from homeassistant.helpers.automation import move_top_level_schema_fields_to_options |
23 | 23 | from homeassistant.helpers.condition import ( |
24 | 24 | Condition, |
25 | | - ConditionChecker, |
26 | 25 | ConditionCheckParams, |
27 | 26 | ConditionConfig, |
28 | 27 | ) |
@@ -117,44 +116,39 @@ def __init__(self, hass: HomeAssistant, config: ConditionConfig) -> None: |
117 | 116 | super().__init__(hass, config) |
118 | 117 | assert config.options is not None |
119 | 118 | self._options = config.options |
120 | | - |
121 | | - async def async_get_checker(self) -> ConditionChecker: |
122 | | - """Wrap action method with zone based condition.""" |
123 | | - entity_ids = self._options.get(CONF_ENTITY_ID, []) |
124 | | - zone_entity_ids = self._options.get(CONF_ZONE, []) |
125 | | - |
126 | | - def if_in_zone(**kwargs: Unpack[ConditionCheckParams]) -> bool: |
127 | | - """Test if condition.""" |
128 | | - errors = [] |
129 | | - |
130 | | - all_ok = True |
131 | | - for entity_id in entity_ids: |
132 | | - entity_ok = False |
133 | | - for zone_entity_id in zone_entity_ids: |
134 | | - try: |
135 | | - if zone(self._hass, zone_entity_id, entity_id): |
136 | | - entity_ok = True |
137 | | - except ConditionErrorMessage as ex: |
138 | | - errors.append( |
139 | | - ConditionErrorMessage( |
140 | | - "zone", |
141 | | - ( |
142 | | - f"error matching {entity_id} with {zone_entity_id}:" |
143 | | - f" {ex.message}" |
144 | | - ), |
145 | | - ) |
| 119 | + self._entity_ids = self._options.get(CONF_ENTITY_ID, []) |
| 120 | + self._zone_entity_ids = self._options.get(CONF_ZONE, []) |
| 121 | + |
| 122 | + def _async_check(self, **kwargs: Unpack[ConditionCheckParams]) -> bool: |
| 123 | + """Test if condition.""" |
| 124 | + errors = [] |
| 125 | + |
| 126 | + all_ok = True |
| 127 | + for entity_id in self._entity_ids: |
| 128 | + entity_ok = False |
| 129 | + for zone_entity_id in self._zone_entity_ids: |
| 130 | + try: |
| 131 | + if zone(self._hass, zone_entity_id, entity_id): |
| 132 | + entity_ok = True |
| 133 | + except ConditionErrorMessage as ex: |
| 134 | + errors.append( |
| 135 | + ConditionErrorMessage( |
| 136 | + "zone", |
| 137 | + ( |
| 138 | + f"error matching {entity_id} with {zone_entity_id}:" |
| 139 | + f" {ex.message}" |
| 140 | + ), |
146 | 141 | ) |
| 142 | + ) |
147 | 143 |
|
148 | | - if not entity_ok: |
149 | | - all_ok = False |
150 | | - |
151 | | - # Raise the errors only if no definitive result was found |
152 | | - if errors and not all_ok: |
153 | | - raise ConditionErrorContainer("zone", errors=errors) |
| 144 | + if not entity_ok: |
| 145 | + all_ok = False |
154 | 146 |
|
155 | | - return all_ok |
| 147 | + # Raise the errors only if no definitive result was found |
| 148 | + if errors and not all_ok: |
| 149 | + raise ConditionErrorContainer("zone", errors=errors) |
156 | 150 |
|
157 | | - return if_in_zone |
| 151 | + return all_ok |
158 | 152 |
|
159 | 153 |
|
160 | 154 | CONDITIONS: dict[str, type[Condition]] = { |
|
0 commit comments