Skip to content

Commit 2dec3be

Browse files
authored
Assign hass in Condition init (home-assistant#158062)
1 parent 7d065bf commit 2dec3be

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

homeassistant/components/device_automation/condition.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ async def async_get_conditions(
5656
class DeviceCondition(Condition):
5757
"""Device condition."""
5858

59-
_hass: HomeAssistant
6059
_config: ConfigType
6160

6261
@classmethod
@@ -87,7 +86,7 @@ async def async_validate_config(
8786

8887
def __init__(self, hass: HomeAssistant, config: ConditionConfig) -> None:
8988
"""Initialize condition."""
90-
self._hass = hass
89+
super().__init__(hass, config)
9190
assert config.options is not None
9291
self._config = config.options
9392

homeassistant/components/light/condition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(
5252
self, hass: HomeAssistant, config: ConditionConfig, state: str
5353
) -> None:
5454
"""Initialize condition."""
55-
self._hass = hass
55+
super().__init__(hass, config)
5656
if TYPE_CHECKING:
5757
assert config.target
5858
assert config.options

homeassistant/components/sun/condition.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ async def async_validate_config(
150150

151151
def __init__(self, hass: HomeAssistant, config: ConditionConfig) -> None:
152152
"""Initialize condition."""
153+
super().__init__(hass, config)
153154
assert config.options is not None
154155
self._options = config.options
155156

homeassistant/components/zone/condition.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ async def async_validate_config(
114114

115115
def __init__(self, hass: HomeAssistant, config: ConditionConfig) -> None:
116116
"""Initialize condition."""
117+
super().__init__(hass, config)
117118
assert config.options is not None
118119
self._options = config.options
119120

homeassistant/helpers/condition.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ async def _register_condition_platform(
259259
class Condition(abc.ABC):
260260
"""Condition class."""
261261

262+
_hass: HomeAssistant
263+
262264
@classmethod
263265
async def async_validate_complete_config(
264266
cls, hass: HomeAssistant, complete_config: ConfigType
@@ -293,6 +295,7 @@ async def async_validate_config(
293295

294296
def __init__(self, hass: HomeAssistant, config: ConditionConfig) -> None:
295297
"""Initialize condition."""
298+
self._hass = hass
296299

297300
@abc.abstractmethod
298301
async def async_get_checker(self) -> ConditionCheckerType:

tests/helpers/test_condition.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
from homeassistant.helpers.condition import (
3838
Condition,
3939
ConditionCheckerType,
40-
ConditionConfig,
4140
async_validate_condition_config,
4241
)
4342
from homeassistant.helpers.template import Template
@@ -2124,9 +2123,6 @@ async def async_validate_config(
21242123
"""Validate config."""
21252124
return config
21262125

2127-
def __init__(self, hass: HomeAssistant, config: ConditionConfig) -> None:
2128-
"""Initialize condition."""
2129-
21302126
class MockCondition1(MockCondition):
21312127
"""Mock condition 1."""
21322128

0 commit comments

Comments
 (0)