Skip to content
Snippets Groups Projects
Commit 735cf540 authored by jkerdreu's avatar jkerdreu
Browse files

Added support for 2 steps auto-wash


git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@3040 b32b6428-25c9-4566-ad07-03861ab6144f
parent 6896f91f
No related branches found
No related tags found
No related merge requests found
import time,random
import time
import random
from enum import Enum
from xaal.lib import tools,config
from xaal.lib import tools, config
from xaal.lib import Message
......@@ -10,7 +11,7 @@ logger = logging.getLogger(__name__)
# how often we force refresh the devices attributes/description/keyvalues
REFRESH_RATE = 600
BOOT_TIMER = 1
BOOT_TIMER = 1
REFRESH_TIMER = 7
AUTOWASH_TIMER = 10
......@@ -85,7 +86,7 @@ class Device:
return r
def is_ready(self):
if self.attributes.is_ready() and self.description.is_ready():
if self.attributes.is_ready() and self.description.is_ready() and self.db.is_ready():
#if self.description.is_ready():
return True
return False
......@@ -200,10 +201,12 @@ class Devices:
def auto_wash(self):
now_ =now()
result = []
for dev in self.get():
if dev.next_alive < now_:
logger.info("Auto Washing %s" % dev.address)
self.remove(dev.address)
logger.info("Needed Auto Wash %s" % dev.address)
result.append(dev)
return result
def dump(self):
for d in self.get():
......@@ -255,7 +258,7 @@ class Monitor:
dev = self.devices.get_with_addr(msg.source)
if msg.is_alive():
dev.alive(msg.body['timeout'])
dev.alive(msg.body.get('timeout', config.DEF_ALIVE_TIMER))
elif msg.is_request_isalive():
self.last_isalive = now()
......@@ -269,7 +272,7 @@ class Monitor:
self.notify(Notification.description_change,dev)
elif self.is_from_metadb(msg):
addr = msg.body['device']
addr = msg.body.get('device')
target = self.devices.get_with_addr(addr)
changed = False
if target and 'map' in msg.body:
......@@ -296,7 +299,10 @@ class Monitor:
def auto_wash(self):
"""call the Auto-wash on devices List"""
self.devices.auto_wash()
devs = self.devices.auto_wash()
for d in devs:
self.notify(Notification.drop_device, d)
self.devices.remove(d.address)
def send_is_alive(self):
self.engine.send_is_alive(self.dev)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment