mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Fix TriggerEntity.async_added_to_hass (#100119)
This commit is contained in:
parent
df718ca509
commit
7a4a792b7b
@ -23,8 +23,7 @@ class TriggerEntity(TriggerBaseEntity, CoordinatorEntity[TriggerUpdateCoordinato
|
|||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Handle being added to Home Assistant."""
|
"""Handle being added to Home Assistant."""
|
||||||
await TriggerBaseEntity.async_added_to_hass(self)
|
await super().async_added_to_hass()
|
||||||
await CoordinatorEntity.async_added_to_hass(self) # type: ignore[arg-type]
|
|
||||||
if self.coordinator.data is not None:
|
if self.coordinator.data is not None:
|
||||||
self._process_data()
|
self._process_data()
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""The test for the Template sensor platform."""
|
"""The test for the Template sensor platform."""
|
||||||
from asyncio import Event
|
from asyncio import Event
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import patch
|
from unittest.mock import ANY, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -1140,6 +1140,48 @@ async def test_trigger_entity(
|
|||||||
assert state.context is context
|
assert state.context is context
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(("count", "domain"), [(1, "template")])
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"config",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"template": [
|
||||||
|
{
|
||||||
|
"trigger": {"platform": "event", "event_type": "test_event"},
|
||||||
|
"sensors": {
|
||||||
|
"hello": {
|
||||||
|
"friendly_name": "Hello Name",
|
||||||
|
"value_template": "{{ trigger.event.data.beer }}",
|
||||||
|
"entity_picture_template": "{{ '/local/dogs.png' }}",
|
||||||
|
"icon_template": "{{ 'mdi:pirate' }}",
|
||||||
|
"attribute_templates": {
|
||||||
|
"last": "{{now().strftime('%D %X')}}",
|
||||||
|
"history_1": "{{this.attributes.last|default('Not yet set')}}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_trigger_entity_runs_once(
|
||||||
|
hass: HomeAssistant, start_ha, entity_registry: er.EntityRegistry
|
||||||
|
) -> None:
|
||||||
|
"""Test trigger entity handles a trigger once."""
|
||||||
|
state = hass.states.get("sensor.hello_name")
|
||||||
|
assert state is not None
|
||||||
|
assert state.state == STATE_UNKNOWN
|
||||||
|
|
||||||
|
hass.bus.async_fire("test_event", {"beer": 2})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get("sensor.hello_name")
|
||||||
|
assert state.state == "2"
|
||||||
|
assert state.attributes.get("last") == ANY
|
||||||
|
assert state.attributes.get("history_1") == "Not yet set"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(("count", "domain"), [(1, "template")])
|
@pytest.mark.parametrize(("count", "domain"), [(1, "template")])
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"config",
|
"config",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user