handle device shudown when schedule is off

This commit is contained in:
Jakob Ketterl 2021-02-26 22:36:15 +01:00
parent 4e7f02fc2c
commit 3164683e74
2 changed files with 26 additions and 14 deletions

View File

@ -209,7 +209,7 @@ class ServiceScheduler(SdrSourceEventClient):
def __init__(self, source):
self.source = source
self.selectionTimer = None
self.currentProfile = None
self.currentEntry = None
self.source.addClient(self)
self.schedule = None
props = self.source.getProps()
@ -246,7 +246,7 @@ class ServiceScheduler(SdrSourceEventClient):
self.selectionTimer.cancel()
def getClientClass(self) -> SdrClientClass:
if self.currentProfile is None:
if self.currentEntry is None:
return SdrClientClass.INACTIVE
else:
return SdrClientClass.BACKGROUND
@ -264,28 +264,10 @@ class ServiceScheduler(SdrSourceEventClient):
def onFrequencyChange(self, changes):
self.scheduleSelection()
def selectProfile(self):
if self.source.hasClients(SdrClientClass.USER):
logger.debug("source has active users; not touching")
return
if self.schedule is None:
self.currentProfile = None
logger.debug("no active schedule, scheduler standing by for external events.")
return
logger.debug("source seems to be idle, selecting profile for background services")
self.currentProfile = entry = self.schedule.getCurrentEntry()
if entry is None:
logger.debug("schedule did not return a current profile. checking next (future) entry...")
nextEntry = self.schedule.getNextEntry()
if nextEntry is not None:
self.scheduleSelection(nextEntry.getNextActivation())
else:
logger.debug("no next entry available, scheduler standing by for external events.")
return
def _setCurrentEntry(self, entry):
self.currentEntry = entry
if entry is not None:
logger.debug("selected profile %s until %s", entry.getProfile(), entry.getScheduledEnd())
self.scheduleSelection(entry.getScheduledEnd())
@ -294,3 +276,30 @@ class ServiceScheduler(SdrSourceEventClient):
self.source.start()
except KeyError:
pass
# tell the source to re-evaluate its current status
# this should make it shut down if there's no other activity
# TODO this is an improvised solution, should probably be integrated / improved in SdrSourceEventClient
self.source.checkStatus()
def selectProfile(self):
if self.source.hasClients(SdrClientClass.USER):
logger.debug("source has active users; not touching")
return
if self.schedule is None:
self._setCurrentEntry(None)
logger.debug("no active schedule, scheduler standing by for external events.")
return
logger.debug("source seems to be idle, selecting profile for background services")
self._setCurrentEntry(self.schedule.getCurrentEntry())
if self.currentEntry is None:
logger.debug("schedule did not return a current profile. checking next (future) entry...")
nextEntry = self.schedule.getNextEntry()
if nextEntry is not None:
self.scheduleSelection(nextEntry.getNextActivation())
else:
logger.debug("no next entry available, scheduler standing by for external events.")
return

View File

@ -319,6 +319,9 @@ class SdrSource(ABC):
self.clients.remove(c)
self.checkStatus()
def checkStatus(self):
hasUsers = self.hasClients(SdrClientClass.USER)
self.setBusyState(SdrBusyState.BUSY if hasUsers else SdrBusyState.IDLE)