From 95e998d25adcc10919bab488dc341bf03f1e9e55 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Thu, 17 Sep 2020 16:45:55 +0200 Subject: [PATCH] Fix editing tags only get isoformat from datetime (#40174) Co-authored-by: Paulus Schoutsen --- homeassistant/components/tag/__init__.py | 3 ++- tests/components/tag/test_init.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/tag/__init__.py b/homeassistant/components/tag/__init__.py index 0b445fbf575..321dce9a296 100644 --- a/homeassistant/components/tag/__init__.py +++ b/homeassistant/components/tag/__init__.py @@ -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 diff --git a/tests/components/tag/test_init.py b/tests/components/tag/test_init.py index e4b810e0661..ecb927c1c5c 100644 --- a/tests/components/tag/test_init.py +++ b/tests/components/tag/test_init.py @@ -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()