mirror of
https://github.com/home-assistant/core
synced 2024-10-01 05:30:36 +02:00
Fix TriggerEntity.async_added_to_hass (#100119)
This commit is contained in:
parent
a6e9bf830c
commit
42046a3ce2
@ -23,8 +23,7 @@ class TriggerEntity(TriggerBaseEntity, CoordinatorEntity[TriggerUpdateCoordinato
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Handle being added to Home Assistant."""
|
||||
await TriggerBaseEntity.async_added_to_hass(self)
|
||||
await CoordinatorEntity.async_added_to_hass(self) # type: ignore[arg-type]
|
||||
await super().async_added_to_hass()
|
||||
if self.coordinator.data is not None:
|
||||
self._process_data()
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""The test for the Template sensor platform."""
|
||||
from asyncio import Event
|
||||
from datetime import timedelta
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import ANY, patch
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
@ -1192,6 +1192,48 @@ async def test_trigger_entity(
|
||||
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(
|
||||
"config",
|
||||
|
Loading…
Reference in New Issue
Block a user