Skip to content

Commit

Permalink
fix AttributeError: 'NoneType' object has no attribute 'getTVstate'
Browse files Browse the repository at this point in the history
  • Loading branch information
formiano committed Dec 11, 2018
1 parent 7af536d commit 58c5f52
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 51 deletions.
23 changes: 16 additions & 7 deletions Navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def __init__(self, wakeupData=None):
self.currentlyPlayingServiceOrGroup = None
self.currentlyPlayingService = None

Screens.Standby.TVstate()
self.skipWakeup = False
self.RecordTimer = None
self.isRecordTimerImageStandard = False
for p in plugins.getPlugins(PluginDescriptor.WHERE_RECORDTIMER):
Expand Down Expand Up @@ -115,6 +117,8 @@ def __init__(self, wakeupData=None):
return

if hasFakeTime and self.wakeuptime > 0: # check for NTP-time sync, if no sync, wait for transponder time
if Screens.Standby.TVinStandby.getTVstandby('waitfortimesync') and not wasTimerWakeup:
Screens.Standby.TVinStandby.setTVstate('power')
self.savedOldTime = now
self.timesynctimer = eTimer()
self.timesynctimer.callback.append(self.TimeSynctimer)
Expand Down Expand Up @@ -162,9 +166,14 @@ def wakeupCheck(self, runCheck = True):
if not self.forcerecord:
print "[NAVIGATION] timer starts at %s" % ctime(self.timertime)
#check for standby
if not self.getstandby and ((self.wakeuptyp < 3 and self.timertime - now > 60 + stbytimer) or (not config.recording.switchTVon.value and self.wakeuptyp == 0)):
cec = ((self.wakeuptyp == 0 and (Screens.Standby.TVinStandby.getTVstandby('zapandrecordtimer'))) or
(self.wakeuptyp == 1 and (Screens.Standby.TVinStandby.getTVstandby('zaptimer'))) or
(self.wakeuptyp == 2 and (Screens.Standby.TVinStandby.getTVstandby('wakeuppowertimer'))))
if self.getstandby != 1 and ((self.wakeuptyp < 3 and self.timertime - now > 60 + stbytimer) or cec):
self.getstandby = 1
print "[NAVIGATION] more than 60 seconds to wakeup or not TV turn on - go in standby"
txt = ""
if cec: txt = "... or special hdmi-cec settings"
print "[NAVIGATION] more than 60 seconds to wakeup%s - go in standby now" %txt
print "="*100
#go in standby
if self.getstandby == 1:
Expand Down Expand Up @@ -192,7 +201,7 @@ def wakeupCheck(self, runCheck = True):
self.getstandby = 0

#workaround for normal operation if no time sync after e2 start - box is in standby
if self.getstandby != 1:
if self.getstandby != 1 and not self.skipWakeup:
self.gotopower()

def wasTimerWakeup(self):
Expand Down Expand Up @@ -222,6 +231,8 @@ def TimeSynctimer(self):
self.wakeupCheck()

def gotopower(self):
if not Screens.Standby.TVinStandby.getTVstate('on'):
Screens.Standby.TVinStandby.setTVstate('power')
if Screens.Standby.inStandby:
print '[NAVIGATION] now entering normal operation'
Screens.Standby.inStandby.Power()
Expand All @@ -243,10 +254,8 @@ def dispatchEvent(self, i):
def dispatchRecordEvent(self, rec_service, event):
# print "record_event", rec_service, event
for x in self.record_event:
try:
x(rec_service, event)
except:
pass
x(rec_service, event)


def playService(self, ref, checkParentalControl=True, forceRestart=False, adjust=True):
oldref = self.currentlyPlayingServiceOrGroup
Expand Down
97 changes: 63 additions & 34 deletions lib/python/Screens/Standby.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,66 @@
inStandby = None
TVinStandby = None

def setTVstate(value): #for recordings without waking up tv
global TVinStandby
import Components.HdmiCec
if value == 'reset' or config.recording.switchTVon.value or not Components.HdmiCec.hdmi_cec.instance:
TVinStandby = None
elif inStandby:
#print '[Standby] box in standby - skip setTVstate'
TVinStandby = None
if os.path.exists("/tmp/powerup_without_waking_tv.txt"):
f = open("/tmp/powerup_without_waking_tv.txt", "w")
if value == 'on':
print '[Standby] leave next standby -> wake up TV'
f.write('False')
elif value == 'off':
print '[Standby] leave next standby -> skip wake up TV'
TVinStandby = True
f.write('True')
f.close()
elif TVinStandby and value == 'on':
print '[Standby] wake up TV'
TVinStandby = False
Components.HdmiCec.hdmi_cec.instance.wakeupMessages()
elif (not TVinStandby and TVinStandby is not None) and value == 'off':
print '[Standby] standby TV'
TVinStandby = True
Components.HdmiCec.hdmi_cec.instance.standbyMessages()
else:
TVinStandby = None
class TVstate:
def __init__(self):
global TVinStandby
if TVinStandby is not None:
print "[Standby] only one TVstate instance is allowed!"
TVinStandby = self

try:
import Components.HdmiCec
self.hdmicec_instance = Components.HdmiCec.hdmi_cec.instance
self.hdmicec_ok = self.hdmicec_instance and config.hdmicec.enabled.value
except:
self.hdmicec_ok = False

if not self.hdmicec_ok:
print '[Standby] HDMI-CEC is not enabled or unavailable !!!'

def skipHdmiCecNow(self, value):
if self.hdmicec_ok:
if value is True or value is False:
self.hdmicec_instance.tv_skip_messages = value
elif 'zaptimer' in value:
self.hdmicec_instance.tv_skip_messages = config.hdmicec.control_tv_wakeup.value and not config.hdmicec.tv_wakeup_zaptimer.value and inStandby
elif 'zapandrecordtimer' in value:
self.hdmicec_instance.tv_skip_messages = config.hdmicec.control_tv_wakeup.value and not config.hdmicec.tv_wakeup_zapandrecordtimer.value and inStandby
elif 'wakeuppowertimer' in value:
self.hdmicec_instance.tv_skip_messages = config.hdmicec.control_tv_wakeup.value and not config.hdmicec.tv_wakeup_wakeuppowertimer.value and inStandby

def getTVstandby(self, value):
if self.hdmicec_ok:
if 'zaptimer' in value:
return config.hdmicec.control_tv_wakeup.value and not config.hdmicec.tv_wakeup_zaptimer.value
elif 'zapandrecordtimer' in value:
return config.hdmicec.control_tv_wakeup.value and not config.hdmicec.tv_wakeup_zapandrecordtimer.value
elif 'wakeuppowertimer' in value:
return config.hdmicec.control_tv_wakeup.value and not config.hdmicec.tv_wakeup_wakeuppowertimer.value
elif 'waitfortimesync' in value:
return config.hdmicec.control_tv_wakeup.value and not (config.hdmicec.deepstandby_waitfortimesync.value and config.workaround.deeprecord.value)
return False

def getTVstate(self, value):
if self.hdmicec_ok:
if not config.hdmicec.check_tv_state.value or self.hdmicec_instance.sendMessagesIsActive():
return False
elif value == 'on':
return value in self.hdmicec_instance.tv_powerstate and config.hdmicec.control_tv_standby.value
elif value == 'standby':
return value in self.hdmicec_instance.tv_powerstate and config.hdmicec.control_tv_wakeup.value
elif value == 'active':
return 'on' in self.hdmicec_instance.tv_powerstate and self.hdmicec_instance.activesource
elif value == 'notactive':
return 'standby' in self.hdmicec_instance.tv_powerstate or not self.hdmicec_instance.activesource
return False

def setTVstate(self, value):
if self.hdmicec_ok:
if value == 'on' or (value == 'power' and config.hdmicec.handle_deepstandby_events.value and not self.hdmicec_instance.handleTimer.isActive()):
self.hdmicec_instance.wakeupMessages()
elif value == 'standby':
self.hdmicec_instance.standbyMessages()

def setLCDModeMinitTV(value):
try:
Expand All @@ -58,7 +90,7 @@ def setLCDModeMinitTV(value):
class Standby2(Screen):
def Power(self):
print "[Standby] leave standby"

if os.path.exists("/usr/script/StandbyLeave.sh"):
Console().ePopen("/usr/script/StandbyLeave.sh &")

Expand Down Expand Up @@ -92,11 +124,8 @@ def Power_break(self):

def TVoff(self):
print "[Standby] TVoff"
try:
config.hdmicec.control_tv_standby_skipnow.setValue(False)
config.hdmicec.TVoffCounter.value += 1
except:
pass
TVinStandby.skipHdmiCecNow(False)
TVinStandby.setTVstate('standby')
def setMute(self):
if eDVBVolumecontrol.getInstance().isMuted():
self.wasMuted = 1
Expand Down
16 changes: 6 additions & 10 deletions mytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ def powerlong(self):
self.doAction(action = config.usage.on_long_powerpress.value)

def doAction(self, action):
if Screens.Standby.TVinStandby:
Screens.Standby.setTVstate('on')
if Screens.Standby.TVinStandby.getTVstate('standby'):
Screens.Standby.TVinStandby.setTVstate('on')
return
self.standbyblocked = 1
if action == "shutdown":
Expand All @@ -419,16 +419,11 @@ def doAction(self, action):
menu_screen.setTitle(_("Standby / restart"))
return
elif action == "standby":
try:
config.hdmicec.control_tv_standby_skipnow.setValue(False)
except:
pass # no HdmiCec
Screens.Standby.TVinStandby.skipHdmiCecNow(False)
self.standby()
elif action == "standby_noTVshutdown":
try:
config.hdmicec.control_tv_standby_skipnow.setValue(True)
except:
pass # no HdmiCec
Screens.Standby.TVinStandby.skipHdmiCecNow(True)
self.standby()
self.standby()
elif action == "powertimerStandby":
val = 3
Expand All @@ -451,6 +446,7 @@ def gotoStandby(self, ret):

def standby(self):
if not Screens.Standby.inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND and self.session.in_exec:
self.session.nav.skipWakeup = True
self.session.open(Screens.Standby.Standby)

def openSleepTimer(self):
Expand Down

0 comments on commit 58c5f52

Please sign in to comment.