mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Fix tag last scanned serialization (#40067)
This commit is contained in:
parent
a38e047e83
commit
3ef821d62f
@ -70,7 +70,7 @@ class TagStorageCollection(collection.StorageCollection):
|
|||||||
data[TAG_ID] = str(uuid.uuid4())
|
data[TAG_ID] = str(uuid.uuid4())
|
||||||
# make last_scanned JSON serializeable
|
# make last_scanned JSON serializeable
|
||||||
if LAST_SCANNED in data:
|
if LAST_SCANNED in data:
|
||||||
data[LAST_SCANNED] = str(data[LAST_SCANNED])
|
data[LAST_SCANNED] = data[LAST_SCANNED].isoformat()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@ -83,7 +83,7 @@ class TagStorageCollection(collection.StorageCollection):
|
|||||||
data = {**data, **self.UPDATE_SCHEMA(update_data)}
|
data = {**data, **self.UPDATE_SCHEMA(update_data)}
|
||||||
# make last_scanned JSON serializeable
|
# make last_scanned JSON serializeable
|
||||||
if LAST_SCANNED in data:
|
if LAST_SCANNED in data:
|
||||||
data[LAST_SCANNED] = str(data[LAST_SCANNED])
|
data[LAST_SCANNED] = data[LAST_SCANNED].isoformat()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,6 +6,9 @@ import pytest
|
|||||||
from homeassistant.components.tag import DOMAIN, TAGS, async_scan_tag
|
from homeassistant.components.tag import DOMAIN, TAGS, async_scan_tag
|
||||||
from homeassistant.helpers import collection
|
from homeassistant.helpers import collection
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
|
from tests.async_mock import patch
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -60,7 +63,10 @@ async def test_tag_scanned(hass, hass_ws_client, storage_setup):
|
|||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
assert "test tag" in result
|
assert "test tag" in result
|
||||||
|
|
||||||
|
now = dt_util.utcnow()
|
||||||
|
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||||
await async_scan_tag(hass, "new tag", "some_scanner")
|
await async_scan_tag(hass, "new tag", "some_scanner")
|
||||||
|
|
||||||
await client.send_json({"id": 7, "type": f"{DOMAIN}/list"})
|
await client.send_json({"id": 7, "type": f"{DOMAIN}/list"})
|
||||||
resp = await client.receive_json()
|
resp = await client.receive_json()
|
||||||
assert resp["success"]
|
assert resp["success"]
|
||||||
@ -70,7 +76,7 @@ async def test_tag_scanned(hass, hass_ws_client, storage_setup):
|
|||||||
assert len(result) == 2
|
assert len(result) == 2
|
||||||
assert "test tag" in result
|
assert "test tag" in result
|
||||||
assert "new tag" in result
|
assert "new tag" in result
|
||||||
assert result["new tag"]["last_scanned"] is not None
|
assert result["new tag"]["last_scanned"] == now.isoformat()
|
||||||
|
|
||||||
|
|
||||||
def track_changes(coll: collection.ObservableCollection):
|
def track_changes(coll: collection.ObservableCollection):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user