mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Fix entity state dispatching for Tag entities (#118662)
This commit is contained in:
parent
3c012c497b
commit
1708b60ecf
@ -267,7 +267,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
# When tags are changed or updated in storage
|
||||
async_dispatcher_send(
|
||||
hass,
|
||||
SIGNAL_TAG_CHANGED,
|
||||
f"{SIGNAL_TAG_CHANGED}-{updated_config[TAG_ID]}",
|
||||
updated_config.get(DEVICE_ID),
|
||||
updated_config.get(LAST_SCANNED),
|
||||
)
|
||||
@ -414,7 +414,7 @@ class TagEntity(Entity):
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
SIGNAL_TAG_CHANGED,
|
||||
f"{SIGNAL_TAG_CHANGED}-{self._tag_id}",
|
||||
self.async_handle_event,
|
||||
)
|
||||
)
|
||||
|
@ -1,5 +1,7 @@
|
||||
"""Tests for the Tag integration."""
|
||||
|
||||
TEST_TAG_ID = "test tag id"
|
||||
TEST_TAG_ID_2 = "test tag id 2"
|
||||
TEST_TAG_NAME = "test tag name"
|
||||
TEST_TAG_NAME_2 = "test tag name 2"
|
||||
TEST_DEVICE_ID = "device id"
|
||||
|
@ -13,7 +13,7 @@ from homeassistant.helpers import collection, entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import TEST_DEVICE_ID, TEST_TAG_ID, TEST_TAG_NAME
|
||||
from . import TEST_DEVICE_ID, TEST_TAG_ID, TEST_TAG_ID_2, TEST_TAG_NAME, TEST_TAG_NAME_2
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
from tests.typing import WebSocketGenerator
|
||||
@ -34,7 +34,11 @@ def storage_setup(hass: HomeAssistant, hass_storage):
|
||||
{
|
||||
"id": TEST_TAG_ID,
|
||||
"tag_id": TEST_TAG_ID,
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": TEST_TAG_ID_2,
|
||||
"tag_id": TEST_TAG_ID_2,
|
||||
},
|
||||
]
|
||||
},
|
||||
}
|
||||
@ -42,6 +46,7 @@ def storage_setup(hass: HomeAssistant, hass_storage):
|
||||
hass_storage[DOMAIN] = items
|
||||
entity_registry = er.async_get(hass)
|
||||
_create_entry(entity_registry, TEST_TAG_ID, TEST_TAG_NAME)
|
||||
_create_entry(entity_registry, TEST_TAG_ID_2, TEST_TAG_NAME_2)
|
||||
config = {DOMAIN: {}}
|
||||
return await async_setup_component(hass, DOMAIN, config)
|
||||
|
||||
@ -131,7 +136,8 @@ async def test_ws_list(
|
||||
resp = await client.receive_json()
|
||||
assert resp["success"]
|
||||
assert resp["result"] == [
|
||||
{"id": TEST_TAG_ID, "name": "test tag name", "tag_id": TEST_TAG_ID}
|
||||
{"id": TEST_TAG_ID, "name": "test tag name", "tag_id": TEST_TAG_ID},
|
||||
{"id": TEST_TAG_ID_2, "name": "test tag name 2", "tag_id": TEST_TAG_ID_2},
|
||||
]
|
||||
|
||||
|
||||
@ -175,7 +181,8 @@ async def test_tag_scanned(
|
||||
result = {item["id"]: item for item in resp["result"]}
|
||||
|
||||
assert resp["result"] == [
|
||||
{"id": TEST_TAG_ID, "name": "test tag name", "tag_id": TEST_TAG_ID}
|
||||
{"id": TEST_TAG_ID, "name": "test tag name", "tag_id": TEST_TAG_ID},
|
||||
{"id": TEST_TAG_ID_2, "name": "test tag name 2", "tag_id": TEST_TAG_ID_2},
|
||||
]
|
||||
|
||||
now = dt_util.utcnow()
|
||||
@ -188,9 +195,10 @@ async def test_tag_scanned(
|
||||
|
||||
result = {item["id"]: item for item in resp["result"]}
|
||||
|
||||
assert len(result) == 2
|
||||
assert len(result) == 3
|
||||
assert resp["result"] == [
|
||||
{"id": TEST_TAG_ID, "name": "test tag name", "tag_id": TEST_TAG_ID},
|
||||
{"id": TEST_TAG_ID_2, "name": "test tag name 2", "tag_id": TEST_TAG_ID_2},
|
||||
{
|
||||
"device_id": "some_scanner",
|
||||
"id": "new tag",
|
||||
@ -256,6 +264,10 @@ async def test_entity(
|
||||
"friendly_name": "test tag name",
|
||||
}
|
||||
|
||||
entity = hass.states.get("tag.test_tag_name_2")
|
||||
assert entity
|
||||
assert entity.state == STATE_UNKNOWN
|
||||
|
||||
|
||||
async def test_entity_created_and_removed(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
|
Loading…
x
Reference in New Issue
Block a user