Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Commit

Permalink
only tag missing if missing for more than 24 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
doudz committed Nov 22, 2018
1 parent a6ac55a commit f2f5898
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions zigate/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
'''
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit f2f5898

Please sign in to comment.