diff --git a/zigate/core.py b/zigate/core.py index 17f1f417..442ee176 100644 --- a/zigate/core.py +++ b/zigate/core.py @@ -494,12 +494,15 @@ def _tag_missing(self, addr): ''' tag a device as missing ''' + last_24h = datetime.datetime.now()-datetime.timedelta(hours=24) + last_24h = last_24h.strftime('%Y-%m-%d %H:%M:%S') if addr in self._devices: - self._devices[addr].missing = True - LOGGER.warning('The device {} is missing'.format(addr)) - dispatch_signal(ZIGATE_DEVICE_UPDATED, - self, **{'zigate': self, - 'device': self._devices[addr]}) + if self._devices[addr].last_seen and self._devices[addr].last_seen < last_24h: + self._devices[addr].missing = True + LOGGER.warning('The device {} is missing'.format(addr)) + dispatch_signal(ZIGATE_DEVICE_UPDATED, + self, **{'zigate': self, + 'device': self._devices[addr]}) def get_missing(self): ''' @@ -1504,6 +1507,10 @@ def rssi(self): def rssi(self, value): self.info['rssi'] = value + @property + def last_seen(self): + return self.info.get('last_seen') + @property def battery_percent(self): percent = self.get_property_value('battery_percent')