Exemple #1
0
 def setSleepTimer(self, val):
     from PowerTimer import PowerTimerEntry
     sleeptime = 15
     data = (int(time() + 60), int(time() + 120))
     self.addSleepTimer(
         PowerTimerEntry(checkOldTimers=True,
                         *data,
                         timerType=val,
                         autosleepdelay=sleeptime))
Exemple #2
0
 def addCurrentTimer(self):
     data = (int(time() + 60), int(time() + 120))
     self.addTimer(PowerTimerEntry(checkOldTimers=True, *data))
def setPowerTimer(session, request):
    id = 0
    if "id" in list(request.args.keys()):
        id = int(request.args["id"][0])
    timertype = 0
    if "timertype" in list(
            request.args.keys()) and request.args["timertype"][0] in [
                "0", "1", "2", "3", "4", "5", "6", "7", "8"
            ]:
        timertype = int(request.args["timertype"][0])
    begin = int(time() + 60)
    if "begin" in list(request.args.keys()):
        begin = int(request.args["begin"][0])
    end = int(time() + 120)
    if "end" in list(request.args.keys()):
        end = int(request.args["end"][0])
    disabled = 0
    if "disabled" in list(request.args.keys()):
        disabled = int(request.args["disabled"][0])
    repeated = False
    if "repeated" in list(request.args.keys()):
        repeated = request.args["repeated"][0] == "1"
    afterevent = 0
    if "afterevent" in list(
            request.args.keys()) and request.args["afterevent"][0] in [
                "0", "1", "2", "3", "4"
            ]:
        afterevent = int(request.args["afterevent"][0])
    autosleepinstandbyonly = "no"
    if "autosleepinstandbyonly" in list(request.args.keys()):
        autosleepinstandbyonly = request.args["autosleepinstandbyonly"][0]
    autosleepdelay = "0"
    if "autosleepdelay" in list(request.args.keys()):
        autosleepdelay = int(request.args["autosleepdelay"][0])
    autosleeprepeat = "once"
    if "autosleeprepeat" in list(request.args.keys()):
        autosleeprepeat = request.args["autosleeprepeat"][0]

    # find
    entry = None
    pos = 0
    if id > 0:
        timer_list = session.nav.PowerTimer.timer_list
        processed_timers = session.nav.PowerTimer.processed_timers
        for timer in timer_list + processed_timers:
            pos += 1
            if pos == 1:
                entry = timer

    # create new Timer
    if entry is None:
        from PowerTimer import PowerTimerEntry
        entry = PowerTimerEntry(begin, end, disabled, afterevent, timertype)
    else:
        entry.begin = begin
        entry.end = end
        entry.timertype = timertype
        entry.afterevent = afterevent
        entry.disabled = disabled

    #  TODO: repeated
    entry.repeated = int(repeated)
    entry.autosleepinstandbyonly = autosleepinstandbyonly
    entry.autosleepdelay = autosleepdelay
    entry.autosleeprepeat = autosleeprepeat

    #  TODO: Test !!!

    return {"result": True, "message": "TODO"}
def setSleepTimer(session, time, action, enabled):
    if action not in ["shutdown", "standby"]:
        action = "standby"

    if hasattr(session.nav, "SleepTimer"):
        try:
            ret = getSleepTimer(session)
            from Screens.Standby import inStandby
            if inStandby is not None:
                ret["message"] = _(
                    "ERROR: Cannot set SleepTimer while device is in Standby-Mode"
                )
                return ret
            if enabled is False:
                session.nav.SleepTimer.clear()
                ret = getSleepTimer(session)
                ret["message"] = _("Sleeptimer has been disabled")
                return ret
            config.SleepTimer.action.value = action
            config.SleepTimer.action.save()
            session.nav.SleepTimer.setSleepTime(time)
            ret = getSleepTimer(session)
            ret["message"] = _("Sleeptimer set to %d minutes") % time
            return ret
        except Exception:
            return {"result": False, "message": _("SleepTimer error")}
    elif InfoBar.instance is not None and hasattr(InfoBar.instance,
                                                  'sleepTimer'):
        try:
            if time == None:
                time = 60
            # TODO test OpenPLI and similar
            info = getInfo()
            cfgaction = None
            if hasattr(config.usage, 'sleepTimerAction'):
                cfgaction = config.usage.sleepTimerAction
            if hasattr(config.usage, 'sleep_timer_action'):
                cfgaction = config.usage.sleep_timer_action
            if cfgaction:
                if action == "shutdown":
                    cfgaction.value = "deepstandby"
                else:
                    cfgaction.value = action
                cfgaction.save()
            active = enabled
            time = int(time)
            cfgtimer = None
            if hasattr(config.usage, 'sleepTimer'):
                cfgtimer = config.usage.sleepTimer
                if cfgtimer.value == '0':
                    if info["imagedistro"] in ('openatv'):
                        for val in range(15, 241, 15):
                            if time == val:
                                break
                            if time < val:
                                time = int(abs(val / 60))
                                break
            elif hasattr(config.usage, 'sleep_timer'):
                cfgtimer = config.usage.sleep_timer
                if cfgtimer.value == '0':
                    # find the closest value
                    if info["imagedistro"] in ('openatv'):
                        times = time * 60
                        for val in list(range(900, 14401, 900)):
                            if times == val:
                                break
                            if times < val:
                                time = int(abs(val / 60))
                                break
            if cfgtimer:
                if active:
                    cfgtimer.value = str(time * 60)
                else:
                    cfgtimer.value = '0'
                cfgtimer.save()
                if enabled:
                    InfoBar.instance.setSleepTimer(time * 60, False)
                else:
                    InfoBar.instance.setSleepTimer(0, False)
            return {
                "enabled":
                active,
                "minutes":
                time,
                "action":
                action,
                "message":
                _("Sleeptimer is enabled")
                if active else _("Sleeptimer is disabled")
            }
        except Exception as e:
            print(e)
            return {"result": False, "message": _("SleepTimer error")}
    else:
        # use powertimer
        # todo activate powertimer
        try:
            done = False
            timer_list = session.nav.PowerTimer.timer_list
            begin = int(time() + 60)
            end = int(time() + 120)
            for timer in timer_list:
                timertype = str(timer.timerType)
                if timertype == "2" and action == "standby":
                    if enabled:
                        timer.disabled = False
                        timer.autosleepdelay = int(time)
                        timer.begin = begin
                        timer.end = end
                    else:
                        timer.disabled = True
                    done = True
                    break
                if timertype == "3" and action == "shutdown":
                    if enabled:
                        timer.disabled = False
                        timer.autosleepdelay = int(time)
                        timer.begin = begin
                        timer.end = end
                    else:
                        timer.disabled = True
                    done = True
                    break
                if timertype == "3" and action == "standby":
                    if enabled:
                        timer.disabled = False
                        timer.autosleepdelay = int(time)
                        timer.timerType = 2
                        timer.begin = begin
                        timer.end = end
                    else:
                        timer.disabled = True
                    done = True
                    break
                if timertype == "2" and action == "shutdown":
                    if enabled:
                        timer.disabled = False
                        timer.autosleepdelay = int(time)
                        timer.timerType = 3
                        timer.begin = begin
                        timer.end = end
                    else:
                        timer.disabled = True
                    done = True
                    break

            if done:
                return {
                    "result":
                    True,
                    "message":
                    _("Sleeptimer set to %d minutes") %
                    time if enabled else _("Sleeptimer has been disabled")
                }
            if enabled:
                begin = int(time() + 60)
                end = int(time() + 120)
                timertype = 2
                if action == "shutdown":
                    timertype = 3
                from PowerTimer import PowerTimerEntry
                entry = PowerTimerEntry(begin, end, False, 0, timertype)
                entry.repeated = 0
                entry.autosleepdelay = time
                return {
                    "result": True,
                    "message": _("Sleeptimer set to %d minutes") % time
                }
            else:
                return {
                    "result": True,
                    "message": _("Sleeptimer has been disabled")
                }
        except Exception:
            return {"result": False, "message": _("SleepTimer error")}
Exemple #5
0
def setSleepTimer(session, time, action, enabled):
    if action not in ["shutdown", "standby"]:
        action = "standby"

    if hasattr(session.nav, "SleepTimer"):
        try:
            ret = getSleepTimer(session)
            from Screens.Standby import inStandby
            if inStandby is not None:
                ret["message"] = _(
                    "ERROR: Cannot set SleepTimer while device is in Standby-Mode"
                )
                return ret
            if enabled is False:
                session.nav.SleepTimer.clear()
                ret = getSleepTimer(session)
                ret["message"] = _("Sleeptimer has been disabled")
                return ret
            config.SleepTimer.action.value = action
            config.SleepTimer.action.save()
            session.nav.SleepTimer.setSleepTime(time)
            ret = getSleepTimer(session)
            ret["message"] = _("Sleeptimer set to %d minutes") % time
            return ret
        except Exception:
            return {"result": False, "message": _("SleepTimer error")}
    else:
        # use powertimer
        # todo activate powertimer
        try:
            done = False
            timer_list = session.nav.PowerTimer.timer_list
            begin = int(time() + 60)
            end = int(time() + 120)
            for timer in timer_list:
                timertype = str(timer.timerType)
                if timertype == "2" and action == "standby":
                    if enabled:
                        timer.disabled = False
                        timer.autosleepdelay = int(time)
                        timer.begin = begin
                        timer.end = end
                    else:
                        timer.disabled = True
                    done = True
                    break
                if timertype == "3" and action == "shutdown":
                    if enabled:
                        timer.disabled = False
                        timer.autosleepdelay = int(time)
                        timer.begin = begin
                        timer.end = end
                    else:
                        timer.disabled = True
                    done = True
                    break
                if timertype == "3" and action == "standby":
                    if enabled:
                        timer.disabled = False
                        timer.autosleepdelay = int(time)
                        timer.timerType = 2
                        timer.begin = begin
                        timer.end = end
                    else:
                        timer.disabled = True
                    done = True
                    break
                if timertype == "2" and action == "shutdown":
                    if enabled:
                        timer.disabled = False
                        timer.autosleepdelay = int(time)
                        timer.timerType = 3
                        timer.begin = begin
                        timer.end = end
                    else:
                        timer.disabled = True
                    done = True
                    break

            if done:
                return {
                    "result":
                    True,
                    "message":
                    _("Sleeptimer set to %d minutes") %
                    time if enabled else _("Sleeptimer has been disabled")
                }
            if enabled:
                begin = int(time() + 60)
                end = int(time() + 120)
                timertype = 2
                if action == "shutdown":
                    timertype = 3
                from PowerTimer import PowerTimerEntry
                entry = PowerTimerEntry(begin, end, False, 0, timertype)
                entry.repeated = 0
                entry.autosleepdelay = time
                return {
                    "result": True,
                    "message": _("Sleeptimer set to %d minutes") % time
                }
            else:
                return {
                    "result": True,
                    "message": _("Sleeptimer has been disabled")
                }
        except Exception:
            return {"result": False, "message": _("SleepTimer error")}
Exemple #6
0
def setSleepTimer(session, time, action, enabled):
	if action not in ["shutdown", "standby"]:
		action = "standby"

	if hasattr(session.nav, "SleepTimer"):
		try:
			ret = getSleepTimer(session)
			from Screens.Standby import inStandby
			if inStandby is not None:
				ret["message"] = _("ERROR: Cannot set SleepTimer while device is in Standby-Mode")
				return ret
			if enabled is False:
				session.nav.SleepTimer.clear()
				ret = getSleepTimer(session)
				ret["message"] = _("Sleeptimer has been disabled")
				return ret
			config.SleepTimer.action.value = action
			config.SleepTimer.action.save()
			session.nav.SleepTimer.setSleepTime(time)
			ret = getSleepTimer(session)
			ret["message"] = _("Sleeptimer set to %d minutes") % time
			return ret
		except Exception:
			return {
				"result": False,
				"message": _("SleepTimer error")
			}
	elif InfoBar.instance is not None and hasattr(InfoBar.instance, 'sleepTimer'):
		try:
			# TODO test OpenPLI and similar
			info = getInfo()
			if info["imagedistro"] not in ('openpli', 'satdreamgr', 'openvision'):
				if action == "shutdown":
					config.usage.sleep_timer_action.value = "deepstandby"
				else:
					config.usage.sleep_timer_action.value = action
				config.usage.sleep_timer_action.save()
			active = enabled
			if enabled:
				InfoBar.instance.setSleepTimer(time * 60)
			else:
				InfoBar.instance.setSleepTimer(0)
				config.usage.sleep_timer.value = str(time * 60)
				config.usage.sleep_timer.save()
			return {
				"enabled": active,
				"minutes": time,
				"action": action,
				"message": _("Sleeptimer is enabled") if active else _("Sleeptimer is disabled")
			}
		except Exception:
			return {
				"result": False,
				"message": _("SleepTimer error")
			}
	else:
		# use powertimer
		# todo activate powertimer
		try:
			done = False
			timer_list = session.nav.PowerTimer.timer_list
			begin = int(time() + 60)
			end = int(time() + 120)
			for timer in timer_list:
				timertype = str(timer.timerType)
				if timertype == "2" and action == "standby":
					if enabled:
						timer.disabled = False
						timer.autosleepdelay = int(time)
						timer.begin = begin
						timer.end = end
					else:
						timer.disabled = True
					done = True
					break
				if timertype == "3" and action == "shutdown":
					if enabled:
						timer.disabled = False
						timer.autosleepdelay = int(time)
						timer.begin = begin
						timer.end = end
					else:
						timer.disabled = True
					done = True
					break
				if timertype == "3" and action == "standby":
					if enabled:
						timer.disabled = False
						timer.autosleepdelay = int(time)
						timer.timerType = 2
						timer.begin = begin
						timer.end = end
					else:
						timer.disabled = True
					done = True
					break
				if timertype == "2" and action == "shutdown":
					if enabled:
						timer.disabled = False
						timer.autosleepdelay = int(time)
						timer.timerType = 3
						timer.begin = begin
						timer.end = end
					else:
						timer.disabled = True
					done = True
					break

			if done:
				return {
					"result": True,
					"message": _("Sleeptimer set to %d minutes") % time if enabled else _("Sleeptimer has been disabled")
				}
			if enabled:
				begin = int(time() + 60)
				end = int(time() + 120)
				timertype = 2
				if action == "shutdown":
					timertype = 3
				from PowerTimer import PowerTimerEntry
				entry = PowerTimerEntry(begin, end, False, 0, timertype)
				entry.repeated = 0
				entry.autosleepdelay = time
				return {
					"result": True,
					"message": _("Sleeptimer set to %d minutes") % time
				}
			else:
				return {
					"result": True,
					"message": _("Sleeptimer has been disabled")
				}
		except Exception:
			return {
				"result": False,
				"message": _("SleepTimer error")
			}