Fix tag last scanned serialization (#40067)
parent
a38e047e83
commit
3ef821d62f
|
@ -70,7 +70,7 @@ class TagStorageCollection(collection.StorageCollection):
|
|||
data[TAG_ID] = str(uuid.uuid4())
|
||||
# make last_scanned JSON serializeable
|
||||
if LAST_SCANNED in data:
|
||||
data[LAST_SCANNED] = str(data[LAST_SCANNED])
|
||||
data[LAST_SCANNED] = data[LAST_SCANNED].isoformat()
|
||||
return data
|
||||
|
||||
@callback
|
||||
|
@ -83,7 +83,7 @@ class TagStorageCollection(collection.StorageCollection):
|
|||
data = {**data, **self.UPDATE_SCHEMA(update_data)}
|
||||
# make last_scanned JSON serializeable
|
||||
if LAST_SCANNED in data:
|
||||
data[LAST_SCANNED] = str(data[LAST_SCANNED])
|
||||
data[LAST_SCANNED] = data[LAST_SCANNED].isoformat()
|
||||
return data
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,9 @@ import pytest
|
|||
from homeassistant.components.tag import DOMAIN, TAGS, async_scan_tag
|
||||
from homeassistant.helpers import collection
|
||||
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__)
|
||||
|
||||
|
@ -60,7 +63,10 @@ async def test_tag_scanned(hass, hass_ws_client, storage_setup):
|
|||
assert len(result) == 1
|
||||
assert "test tag" in result
|
||||
|
||||
await async_scan_tag(hass, "new tag", "some_scanner")
|
||||
now = dt_util.utcnow()
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
await async_scan_tag(hass, "new tag", "some_scanner")
|
||||
|
||||
await client.send_json({"id": 7, "type": f"{DOMAIN}/list"})
|
||||
resp = await client.receive_json()
|
||||
assert resp["success"]
|
||||
|
@ -70,7 +76,7 @@ async def test_tag_scanned(hass, hass_ws_client, storage_setup):
|
|||
assert len(result) == 2
|
||||
assert "test 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):
|
||||
|
|
Loading…
Reference in New Issue