Fix editing tags only get isoformat from datetime (#40174)

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
Bram Kragten 2020-09-17 16:45:55 +02:00 committed by GitHub
parent 30de984827
commit 95e998d25a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View file

@ -82,7 +82,7 @@ class TagStorageCollection(collection.StorageCollection):
"""Return a new updated data object."""
data = {**data, **self.UPDATE_SCHEMA(update_data)}
# make last_scanned JSON serializeable
if LAST_SCANNED in data:
if LAST_SCANNED in update_data:
data[LAST_SCANNED] = data[LAST_SCANNED].isoformat()
return data
@ -100,6 +100,7 @@ async def async_setup(hass: HomeAssistant, config: dict):
collection.StorageCollectionWebsocket(
storage_collection, DOMAIN, DOMAIN, CREATE_FIELDS, UPDATE_FIELDS
).async_setup(hass)
return True

View file

@ -48,6 +48,30 @@ async def test_ws_list(hass, hass_ws_client, storage_setup):
assert "test tag" in result
async def test_ws_update(hass, hass_ws_client, storage_setup):
"""Test listing tags via WS."""
assert await storage_setup()
await async_scan_tag(hass, "test tag", "some_scanner")
client = await hass_ws_client(hass)
await client.send_json(
{
"id": 6,
"type": f"{DOMAIN}/update",
f"{DOMAIN}_id": "test tag",
"name": "New name",
}
)
resp = await client.receive_json()
assert resp["success"]
item = resp["result"]
assert item["id"] == "test tag"
assert item["name"] == "New name"
async def test_tag_scanned(hass, hass_ws_client, storage_setup):
"""Test scanning tags."""
assert await storage_setup()