Now, date changes should only be announced at midnight.
This commit is contained in:
parent
cd34b02835
commit
63124f4f68
@ -1,5 +1,4 @@
|
|||||||
#!/bin/python
|
#!/bin/python
|
||||||
import time
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Fenrir TTY screen reader
|
# Fenrir TTY screen reader
|
||||||
@ -12,63 +11,75 @@ import datetime
|
|||||||
class command():
|
class command():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
self.lastTime = datetime.datetime.now()
|
self.lastTime = datetime.datetime.now()
|
||||||
self.lastDateString = ''
|
self.lastDateString = ''
|
||||||
self.lastTimeString = ''
|
self.lastTimeString = ''
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def getDescription(self):
|
def getDescription(self):
|
||||||
return 'No Description found'
|
return 'No Description found'
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if not self.env['runtime']['settingsManager'].getSettingAsBool('time', 'enabled'):
|
if not self.env['runtime']['settingsManager'].getSettingAsBool('time', 'enabled'):
|
||||||
return
|
return
|
||||||
onMinutes = self.env['runtime']['settingsManager'].getSetting('time', 'onMinutes')
|
|
||||||
|
onMinutes = self.env['runtime']['settingsManager'].getSetting('time', 'onMinutes')
|
||||||
delaySec = self.env['runtime']['settingsManager'].getSettingAsInt('time', 'delaySec')
|
delaySec = self.env['runtime']['settingsManager'].getSettingAsInt('time', 'delaySec')
|
||||||
|
|
||||||
# no need
|
# no need
|
||||||
if onMinutes == '' and delaySec <= 0:
|
if onMinutes == '' and delaySec <= 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
onMinutes = onMinutes.split(',')
|
onMinutes = onMinutes.split(',')
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
|
|
||||||
# ignore onMinutes if there is a delaySec
|
# ignore onMinutes if there is a delaySec
|
||||||
if delaySec > 0:
|
if delaySec > 0:
|
||||||
if int((now-self.lastTime).total_seconds()) < delaySec:
|
if int((now - self.lastTime).total_seconds()) < delaySec:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
# shoul announce?
|
# should announce?
|
||||||
if not str(now.minute).zfill(2) in onMinutes:
|
if not str(now.minute).zfill(2) in onMinutes:
|
||||||
return
|
return
|
||||||
# already announced?
|
# already announced?
|
||||||
if now.hour == self.lastTime.hour:
|
if now.hour == self.lastTime.hour:
|
||||||
if now.minute == self.lastTime.minute:
|
if now.minute == self.lastTime.minute:
|
||||||
return
|
return
|
||||||
|
|
||||||
dateFormat = self.env['runtime']['settingsManager'].getSetting('general', 'dateFormat')
|
dateFormat = self.env['runtime']['settingsManager'].getSetting('general', 'dateFormat')
|
||||||
dateString = datetime.datetime.strftime(now, dateFormat)
|
dateString = datetime.datetime.strftime(now, dateFormat)
|
||||||
|
|
||||||
presentDate = self.env['runtime']['settingsManager'].getSettingAsBool('time', 'presentDate') and \
|
presentDate = self.env['runtime']['settingsManager'].getSettingAsBool('time', 'presentDate') and \
|
||||||
self.lastDateString != dateString
|
self.lastDateString != dateString
|
||||||
presentTime = self.env['runtime']['settingsManager'].getSettingAsBool('time', 'presentTime')
|
presentTime = self.env['runtime']['settingsManager'].getSettingAsBool('time', 'presentTime')
|
||||||
|
|
||||||
# no changed value to announce
|
# no changed value to announce
|
||||||
if not (presentDate or presentTime):
|
if not (presentDate or presentTime):
|
||||||
return
|
return
|
||||||
|
|
||||||
timeFormat = self.env['runtime']['settingsManager'].getSetting('general', 'timeFormat')
|
timeFormat = self.env['runtime']['settingsManager'].getSetting('general', 'timeFormat')
|
||||||
timeString = datetime.datetime.strftime(now, timeFormat)
|
timeString = datetime.datetime.strftime(now, timeFormat)
|
||||||
|
|
||||||
if self.env['runtime']['settingsManager'].getSettingAsBool('time', 'interrupt'):
|
if self.env['runtime']['settingsManager'].getSettingAsBool('time', 'interrupt'):
|
||||||
self.env['runtime']['outputManager'].interruptOutput()
|
self.env['runtime']['outputManager'].interruptOutput()
|
||||||
if self.env['runtime']['settingsManager'].getSettingAsBool('time', 'announce'):
|
if self.env['runtime']['settingsManager'].getSettingAsBool('time', 'announce'):
|
||||||
self.env['runtime']['outputManager'].playSoundIcon('announce')
|
self.env['runtime']['outputManager'].playSoundIcon('announce')
|
||||||
|
|
||||||
if presentTime:
|
if presentTime:
|
||||||
# present the time
|
# present the time
|
||||||
self.env['runtime']['outputManager'].presentText(_("It's {0}").format(timeString.replace(':00', " O'clock ").lstrip('0')), soundIcon='', interrupt=False)
|
self.env['runtime']['outputManager'].presentText(_("It's {0}").format(timeString.replace(':00', " O'clock ").lstrip('0')), soundIcon='', interrupt=False)
|
||||||
# and date if changes
|
# Check if it's 12:00 AM
|
||||||
if presentDate:
|
if now.hour == 0 and now.minute == 0:
|
||||||
self.env['runtime']['outputManager'].presentText(dateString , soundIcon='', interrupt=False)
|
# present the date
|
||||||
self.lastDateString = dateString
|
self.env['runtime']['outputManager'].presentText(dateString, soundIcon='', interrupt=False)
|
||||||
|
|
||||||
self.lastTime = datetime.datetime.now()
|
self.lastTime = datetime.datetime.now()
|
||||||
self.lastTimeString = timeString
|
self.lastTimeString = timeString
|
||||||
|
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user