From 3d73f166bed0996965be3764ee0f4a9f9de3be92 Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Wed, 1 Apr 2020 08:41:16 -0400 Subject: [PATCH] Correct issue on new device joins in ZHA (#33470) --- homeassistant/components/zha/core/gateway.py | 5 ++++- homeassistant/components/zha/core/store.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/zha/core/gateway.py b/homeassistant/components/zha/core/gateway.py index 21f2f636128..e032de4d94c 100644 --- a/homeassistant/components/zha/core/gateway.py +++ b/homeassistant/components/zha/core/gateway.py @@ -5,6 +5,7 @@ import collections import itertools import logging import os +import time import traceback from typing import List, Optional @@ -478,7 +479,9 @@ class ZHAGateway: async def async_device_initialized(self, device: zha_typing.ZigpyDeviceType): """Handle device joined and basic information discovered (async).""" zha_device = self._async_get_or_create_device(device) - + # This is an active device so set a last seen if it is none + if zha_device.last_seen is None: + zha_device.async_update_last_seen(time.time()) _LOGGER.debug( "device - %s:%s entering async_device_initialized - is_new_join: %s", device.nwk, diff --git a/homeassistant/components/zha/core/store.py b/homeassistant/components/zha/core/store.py index 3838e9b6a50..0171ded67fe 100644 --- a/homeassistant/components/zha/core/store.py +++ b/homeassistant/components/zha/core/store.py @@ -46,8 +46,8 @@ class ZhaStorage: name=device.name, ieee=str(device.ieee), last_seen=device.last_seen ) self.devices[device_entry.ieee] = device_entry - - return self.async_update_device(device) + self.async_schedule_save() + return device_entry @callback def async_get_or_create_device(self, device: ZhaDeviceType) -> ZhaDeviceEntry: