Пример #1
0
    def set_rules_enable():
        enabled = request.args.get('val') == "true"
        Logger().write(LogVerbosity.Debug,
                       "Setting rules enabled to " + str(enabled))
        RuleManager().set_enabled(enabled)

        return "OK"
Пример #2
0
 def init_singletons():
     Stats()
     VLCPlayer()
     NextEpisodeManager()
     WiFiController()
     MediaManager()
     Updater()
     ThreadManager()
     PresenceManager()
     RuleManager()
Пример #3
0
    def save_rule():
        rule_id = int(request.args.get('id'))
        name = request.args.get('name')
        active = request.args.get('active') == "true"

        actions = []
        actions_length = int(request.args.get('actions'))
        for i in range(actions_length):
            action_type = int(request.args.get('action' + str(i) + "_type"))
            action_param1 = request.args.get('action' + str(i) + "_param1")
            action_param2 = request.args.get('action' + str(i) + "_param2")
            action_param3 = request.args.get('action' + str(i) + "_param3")
            action_param4 = request.args.get('action' + str(i) + "_param4")
            action_param5 = request.args.get('action' + str(i) + "_param5")
            actions.append((action_type, action_param1, action_param2,
                            action_param3, action_param4, action_param5))

        conditions = []
        conditions_length = int(request.args.get('conditions'))
        for i in range(conditions_length):
            condition_type = int(
                request.args.get('condition' + str(i) + "_type"))
            condition_param1 = request.args.get('condition' + str(i) +
                                                "_param1")
            condition_param2 = request.args.get('condition' + str(i) +
                                                "_param2")
            condition_param3 = request.args.get('condition' + str(i) +
                                                "_param3")
            condition_param4 = request.args.get('condition' + str(i) +
                                                "_param4")
            condition_param5 = request.args.get('condition' + str(i) +
                                                "_param5")
            conditions.append(
                (condition_type, condition_param1, condition_param2,
                 condition_param3, condition_param4, condition_param5))

        RuleManager().update_rule(rule_id, active, name, actions, conditions)
        return "OK"
Пример #4
0
 def remove_rule():
     rule_id = int(request.args.get('id'))
     RuleManager().remove_rule(rule_id)
     return "OK"
Пример #5
0
    def get_rule():
        rule_id = int(request.args.get('id'))
        Logger().write(LogVerbosity.Debug, "Getting rule " + str(rule_id))

        return to_JSON(RuleManager().get_rule(rule_id))
Пример #6
0
 def get_rules():
     Logger().write(LogVerbosity.Debug, "Getting rules")
     return to_JSON(RuleManager().get_rules())
Пример #7
0
 def get_actions_and_conditions():
     Logger().write(LogVerbosity.Debug, "Getting rules")
     return to_JSON(RuleManager().get_actions_and_conditions())
Пример #8
0
    def __init__(self):
        Logger().start(Settings.get_int("log_level"))
        sys.excepthook = self.handle_exception

        Logger().write(LogVerbosity.Info, "Starting")
        self.running = True

        self.version = datetime.fromtimestamp(
            self.get_latest_change()).strftime("%Y-%m-%d %H:%M:%S")
        self.is_slave = Settings.get_bool("slave")
        self.pi = sys.platform == "linux" or sys.platform == "linux2"

        Logger().write(
            LogVerbosity.Info, "Python version " + str(sys.version_info[0]) +
            "." + str(sys.version_info[1]) + "." + str(sys.version_info[2]))
        Logger().write(LogVerbosity.Info,
                       "MediaPlayer build [" + self.version + "]")
        Logger().write(LogVerbosity.Info, "Slave: " + str(self.is_slave))
        if self.is_slave:
            Logger().write(
                LogVerbosity.Info,
                "Master ip: " + str(Settings.get_string("master_ip")))
        Logger().write(LogVerbosity.Info, "Pi: " + str(self.pi))
        Logger().write(LogVerbosity.Info,
                       "UI: " + str(Settings.get_bool("UI")))

        Logger().write(LogVerbosity.Debug, "Initializing database")
        Database().init_database()

        Logger().write(LogVerbosity.Debug, "Initializing singletons")
        self.init_singletons()

        Logger().write(LogVerbosity.Debug, "Initializing sounds and folders")
        self.init_sound()
        self.init_folders()

        Logger().write(LogVerbosity.Debug, "Initializing API")
        APIController().start()

        Logger().write(LogVerbosity.Debug, "Initializing WiFi controller")
        WiFiController().check_wifi()

        Logger().write(LogVerbosity.Debug, "Initializing stats")
        Stats().start()
        Stats().set('start_time', current_time())

        Logger().write(LogVerbosity.Debug, "Initializing presence manager")
        PresenceManager().start()

        Logger().write(LogVerbosity.Debug, "Initializing rule manager")
        RuleManager().start()

        Logger().write(LogVerbosity.Debug, "Initializing TV manager")
        TVManager().start()

        if not self.is_slave:
            Logger().write(LogVerbosity.Debug, "Initializing TradeFriManager")
            TradfriManager().init()

            Logger().write(LogVerbosity.Debug,
                           "Initializing master file server")
            self.file_listener = StreamListener("MasterFileServer", 50015)
            self.file_listener.start_listening()

        Logger().write(LogVerbosity.Important, "Started")
        if Settings.get_bool("UI"):
            from UI.TV.GUI import App
            self.gui = App.initialize()
        else:
            while self.running:
                time.sleep(5)