class AlarmClock(object): """Main alarm clock application class.""" def __init__(self): self.addon = xbmcaddon.Addon() self.crontab = CronTab(xbmc) def apply_settings(self): """Gets the current configuration and updates the scheduler.""" self.addon = xbmcaddon.Addon() self.crontab.jobs = self._get_alarms() def start(self): """Starts the alarm clock, ie. activates the defined alarms.""" self.crontab.start() def stop(self): """Stops the alarm clock.""" self.crontab.stop() def _get_alarms(self): """Get a list of the cron jobs for the enabled alarms.""" jobs = [] for i in range(1, 6): if self.addon.getSetting("alarm%d" % i) == "true": jobs.extend(self._get_jobs(i)) xbmc.log("events fetched: %s" % str(jobs), xbmc.LOGDEBUG) return jobs def _get_jobs(self, number): """Initialize jobs(s) for alarm number. If the alarm has a duration enabled, both the start and the stop job are returned in the list.""" days_of_week = int(self.addon.getSetting("day%d" % number)) if days_of_week == 7: days_of_week = range(5) if days_of_week == 8: days_of_week = range(7) action = self.addon.getSetting("action%d" % number) if action == "0": file_name = self.addon.getSetting("file%d" % number) else: file_name = self.addon.getSetting("text%d" % number) jobs = [Job(self._start_playing, int(self.addon.getSetting("minute%d" % number)), int(self.addon.getSetting("hour%d" % number)), dow=days_of_week, args=[file_name, self.addon.getSetting("volume%d" % number)])] if self.addon.getSetting("turnOff%d" % number) == "true": jobs.append(Job(self._stop_playing, int(self.addon.getSetting("minute%d" % number)) + (int(self.addon.getSetting("duration%d" % number)) % 60), int(self.addon.getSetting("hour%d" % number)) + (int(self.addon.getSetting("duration%d" % number)) / 60), dow=days_of_week)) return jobs def _start_playing(self, item, volume): """Starts playing the given item at the supplied volume.""" try: xbmc.executebuiltin('CECActivateSource') # pylint: disable=broad-except except Exception: xbmc.log("CECActivateSource not supported", xbmc.LOGDEBUG) xbmc.executebuiltin('SetVolume(%s)' % volume) xbmc.Player().play(item) def _stop_playing(self): """Stops whatever is playing at the moment""" xbmc.Player().stop()
class AlarmClock(object): """Main alarm clock application class.""" def __init__(self): self.addon = xbmcaddon.Addon() self.crontab = CronTab(xbmc) def apply_settings(self): """Gets the current configuration and updates the scheduler.""" self.addon = xbmcaddon.Addon() self.crontab.jobs = self._get_alarms() def start(self): """Starts the alarm clock, ie. activates the defined alarms.""" self.crontab.start() def stop(self): """Stops the alarm clock.""" self.crontab.stop() def _get_alarms(self): """Get a list of the cron jobs for the enabled alarms.""" jobs = [] for i in range(1, 6): if self.addon.getSetting("alarm%d" % i) == "true": jobs.extend(self._get_jobs(i)) xbmc.log("events fetched: %s" % str(jobs), xbmc.LOGDEBUG) return jobs def _get_jobs(self, number): """Initialize jobs(s) for alarm number. If the alarm has a duration enabled, both the start and the stop job are returned in the list.""" days_of_week = int(self.addon.getSetting("day%d" % number)) if days_of_week == 7: days_of_week = list(range(5)) if days_of_week == 8: days_of_week = list(range(7)) action = self.addon.getSetting("action%d" % number) if action == "0": file_name = self.addon.getSetting("file%d" % number) else: file_name = self.addon.getSetting("text%d" % number) jobs = [ Job(self._start_playing, int(self.addon.getSetting("minute%d" % number)), int(self.addon.getSetting("hour%d" % number)), dow=days_of_week, args=[file_name, self.addon.getSetting("volume%d" % number)]) ] if self.addon.getSetting("turnOff%d" % number) == "true": jobs.append( Job(self._stop_playing, int(self.addon.getSetting("minute%d" % number)) + (int(self.addon.getSetting("duration%d" % number)) % 60), int(self.addon.getSetting("hour%d" % number)) + (int(self.addon.getSetting("duration%d" % number)) / 60), dow=days_of_week)) return jobs def _start_playing(self, item, volume): """Starts playing the given item at the supplied volume.""" try: xbmc.executebuiltin('CECActivateSource') # pylint: disable=broad-except except Exception: xbmc.log("CECActivateSource not supported", xbmc.LOGDEBUG) xbmc.executebuiltin('SetVolume(%s)' % volume) xbmc.Player().play(item) def _stop_playing(self): """Stops whatever is playing at the moment""" xbmc.Player().stop()
class AlarmClock: """Main alarm clock application class.""" def __init__(self): self.addon = xbmcaddon.Addon() self.crontab = CronTab(xbmc) def validtime(self, programestarttime): """make sure its in the future, if Start time is in the future then set to true""" now = datetime.datetime.now() hr, mins = programestarttime.split(":") starttime = now.replace(hour=int(hr), minute=int(mins), second=1, microsecond=0) return starttime > now def applysettings(self, contextenabled, new_programmename, new_programmetime, new_programmedate, new_channelname): """Gets the current configuration and updates the scheduler.""" xbmc.log("PVRReminder: Getting settings, triggered by user: "******"advancement")) self.crontab.jobs = self._getalarms(contextenabled, new_programmename, new_programmetime, reminder_advancement, new_programmedate, new_channelname) self.stop() self.crontab.switch() self.crontab.start() def start(self): """Starts the alarm clock, ie. activates the defined alarms.""" xbmc.log("PVRReminder: Starting current alarm...", xbmc.LOGDEBUG) self.crontab.start() def stop(self): """Stops the alarm clock.""" xbmc.log("PVRReminder: Stopping current alarm...", xbmc.LOGDEBUG) self.crontab.stop() def _getalarms(self, contextenabled, new_programmename, new_programmetime, reminder_advancement, new_programmedate, new_channelname): """Get a list of the cron jobs for the enabled alarms.""" jobs = [] if contextenabled == "true": new_programmetime = advancedtimer(self, reminder_advancement, new_programmetime) jobs.extend(self._getjobs(1, contextenabled, new_programmename, new_programmetime, new_programmedate, new_channelname)) xbmc.log("PVRReminder: setting New alarm from user input: %s" % str(new_programmename), xbmc.LOGDEBUG) return jobs else: for reminder in roots.findall('reminder'): enabled = reminder.find('enabled').text if enabled == "true": reminderid = reminder.get('id') new_programmetime = reminder.find('starttime').text new_programmename = reminder.find('programmename').text new_programmetime = advancedtimer(self, reminder_advancement, new_programmetime) jobs.extend(self._getjobs(reminderid, contextenabled, new_programmename, new_programmetime, new_programmedate, new_channelname)) xbmc.log("PVRReminder: setting old alarm from file", xbmc.LOGDEBUG) else: xbmc.log("PVRReminder: Going to have to stop alarm as there is nothing to remind", xbmc.LOGDEBUG) AlarmClock.stop(self) return jobs def _getjobs(self, reminderid, contextenabled, new_programmename, new_programmetime, new_programmedate, new_channelname): xbmc.log("PVRReminder: Getting info from file, programme Name: " + str(new_programmetime), xbmc.LOGDEBUG) if AlarmClock.validtime(self, new_programmetime): hr, mins = new_programmetime.split(":") filetoplay = new_programmename jobs = [Job(self._play, int(mins), int(hr), args=[filetoplay, reminderid, new_channelname])] xbmc.log("PVRReminder: Time is valid, setting jobs: %s" % str(new_programmetime), xbmc.LOGDEBUG) else: xbmc.log("PVRReminder: Setting old reminder to false as its in the past ", xbmc.LOGDEBUG) for enabled in roots.iter('enabled'): enabled.text = "false" trees.write(data) xbmc.log("PVRReminder: Reminder set in the past, going to purge reminder", xbmc.LOGDEBUG) jobs = [] return jobs def _play(self, filetoplay, reminderid, new_channelname): remindme(filetoplay,new_channelname) for enabled in roots.iter('enabled'): enabled.text = "false" trees.write(data) AlarmClock.stop(self) xbmc.log("PVRReminder: Reminder sent, going to purge reminder", xbmc.LOGDEBUG)
class AlarmClock: """Main alarm clock application class.""" def __init__(self): self.addon = xbmcaddon.Addon() self.crontab = CronTab(xbmc) def applySettings(self): """Gets the current configuration and updates the scheduler.""" self.addon = xbmcaddon.Addon() self.crontab.jobs = self._getAlarms() def start(self): """Starts the alarm clock, ie. activates the defined alarms.""" self.crontab.start() def stop(self): """Stops the alarm clock.""" self.crontab.stop() def _getAlarms(self): """Get a list of the cron jobs for the enabled alarms.""" jobs = [] for i in range(1,6): if self.addon.getSetting("alarm%d" % i) == "true": jobs.extend(self._getJobs(i)) xbmc.log("events fetched: %s" % str(jobs), xbmc.LOGDEBUG) return jobs def _getJobs(self, number): """Initialize jobs(s) for alarm number. If the alarm has a duration enabled, both the start and the stop job are returned in the list.""" daysOfWeek = int(self.addon.getSetting("day%d" % number)) if daysOfWeek == 7: daysOfWeek = range(5) if daysOfWeek == 8: daysOfWeek = range(7) action = self.addon.getSetting("action%d" % number) if action == "0": file = self.addon.getSetting("file%d" % number) else: file = self.addon.getSetting("text%d" % number) jobs = [Job(self._play, int(self.addon.getSetting("minute%d" % number)), int(self.addon.getSetting("hour%d" % number)), dow=daysOfWeek, args=[file, self.addon.getSetting("volume%d" % number)])] if self.addon.getSetting("turnOff%d" % number) == "true": jobs.append(Job(self._stopPlaying, int(self.addon.getSetting("minute%d" % number)) + (int(self.addon.getSetting("duration%d" % number)) % 60), int(self.addon.getSetting("hour%d" % number)) + (int(self.addon.getSetting("duration%d" % number)) / 60), dow=daysOfWeek)) return jobs def _play(self, item, volume): xbmc.executebuiltin('SetVolume(%s)' % volume) xbmc.Player().play(item) def _stopPlaying(self): xbmc.Player().stop()
class AlarmClock: """Main alarm clock application class.""" def __init__(self): self.addon = xbmcaddon.Addon() self.crontab = CronTab(xbmc) def applySettings(self): """Gets the current configuration and updates the scheduler.""" self.addon = xbmcaddon.Addon() self.crontab.jobs = self._getAlarms() def start(self): """Starts the alarm clock, ie. activates the defined alarms.""" self.crontab.start() def stop(self): """Stops the alarm clock.""" self.crontab.stop() def _getAlarms(self): """Get a list of the cron jobs for the enabled alarms.""" jobs = [] for i in range(1, 6): if self.addon.getSetting("alarm%d" % i) == "true": jobs.extend(self._getJobs(i)) xbmc.log("events fetched: %s" % str(jobs), xbmc.LOGDEBUG) return jobs def _getJobs(self, number): """Initialize jobs(s) for alarm number. If the alarm has a duration enabled, both the start and the stop job are returned in the list.""" daysOfWeek = int(self.addon.getSetting("day%d" % number)) if daysOfWeek == 7: daysOfWeek = range(5) if daysOfWeek == 8: daysOfWeek = range(7) action = self.addon.getSetting("action%d" % number) if action == "0": file = self.addon.getSetting("file%d" % number) else: file = self.addon.getSetting("text%d" % number) jobs = [ Job(self._play, int(self.addon.getSetting("minute%d" % number)), int(self.addon.getSetting("hour%d" % number)), dow=daysOfWeek, args=[file, self.addon.getSetting("volume%d" % number)]) ] if self.addon.getSetting("turnOff%d" % number) == "true": jobs.append( Job(self._stopPlaying, int(self.addon.getSetting("minute%d" % number)) + (int(self.addon.getSetting("duration%d" % number)) % 60), int(self.addon.getSetting("hour%d" % number)) + (int(self.addon.getSetting("duration%d" % number)) / 60), dow=daysOfWeek)) return jobs def _play(self, item, volume): xbmc.executebuiltin('SetVolume(%s)' % volume) xbmc.Player().play(item) def _stopPlaying(self): xbmc.Player().stop()