def apply_basic_settings(self):
        global SCENES
        scenenames = SCENES.keys()
        labels = map(lambda x:x.lower(),scenenames)
        # Get the bridges
        self.bridge = LimitlessBridge(__addon__.getSetting("b0_host"),__addon__.getSetting("b0_port"))

        # Get the scenes
        #labels     =["normal","dimmed","reading","movie","tv","music"]
        #scenenames = ["Normal","Dimmed","Reading","Movie","TV","Music"]
        for label,scenename in zip (labels,scenenames):
            scene = LimitlessScene(scenename,0,False)
            for i in ("0","1","2","3","4"):
                enabled=utils.get_bool_setting("b0_l"+i+"_"+label+"_enable")
                if enabled:
                    color       = utils.get_setting("b0_l"+i+"_"+label+"_color")
                    brightness  = utils.get_setting("b0_l"+i+"_"+label+"_brightness")
                    light       = LimitlessLight(self.bridge,'rgbw',i,True,color,brightness)
                    utils.log_verbose("Settings: label: " + label + " scenename: " + scenename + " lights: " + str(light))
                    scene.addLight(light)
            SCENES[scenename] = scene
        for activity in ACTIVITIES.keys():
            # map activity to scenes
            activity_scene = utils.get_setting("activity_"+activity)
            ACTIVITIES[activity] = activity_scene
        utils.log_verbose("Enabled: " + utils.get_setting("activity_enable"))
        return True
    def onPlayBackStarted(self):
        if utils.get_bool_setting("activity_enable") == False:
            return
        service = self.service
        # in the future we can either use a call-back pattern (if I can figure that out in python)
        # for multiple bridges that would allow the service logic (or a bridge-manager object) to fire events to all bridges
        playingFile = self.getPlayingFile()

        # Can't use "content" to determien the content as it shows to be unreliable (as of Jarvis b4)
        # content     = xbmc.getInfoLabel('Container.Content')
        content = determineContent(playingFile)
        utils.log_verbose("content: " + content + " file: " + playingFile)
        #for l in infolabels:
        #    ld = xbmc.getInfoLabel(l)
        #    if ld != "":
        #        utils.log_verbose(l + ": " + ld)
        
        if self.isPlaying :
            utils.log_verbose(content + ": " + playingFile)
            # activity references a scene or none

            if (content):
                if (content == "movie"):
                    return service.bridge.applyScene(getSceneByActivity("movie"))
                elif (content == "tv"):
                    return service.bridge.applyScene(getSceneByActivity("tv"))
                elif (content == "music"):
                    return service.bridge.applyScene(getSceneByActivity("music"))
                else:
                    return service.bridge.applyScene(getSceneByActivity("video"))
            else:
                return service.bridge.applyScene(getSceneByActivity("video"))
예제 #3
0
    def alarm_check(self):
        if self.motion_enable or self.sound_enable:
            player = xbmc.Player()
            if (player.isPlaying()
                and player.getPlayingFile() in (self.camera.video_url,
                                                self.camera.mjpeg_url)):
                return

            self.alarm_active = False
            
            dev_state = self.camera.get_device_state()
            if dev_state:
                for alarm, enabled in (('motionDetect', self.motion_enable),
                                       ('sound', self.sound_enable)):
                    if enabled:
                        param = "{0}Alarm".format(alarm)
                        alarm_status = dev_state[param]
                        utils.log_verbose("{0:s} = {1:d}".format(param, alarm_status))
                        if alarm_status == 2:
                            self.alarm_active = True
                            utils.log_normal("Alarm detected")
                            break

            if self.alarm_active:
                mjpeg_stream = self.camera.get_mjpeg_stream()
                preview = gui.CameraPreview(self.duration, self.path,
                                            self.scaling, self.position,
                                            mjpeg_stream)
                preview.show()
                self.duration_shown = preview.start()
                del(preview)
예제 #4
0
    def __init__(self):
        utils.log_normal("Starting service")
        self.alarm_active = False
        self.duration_shown = 0
        
        self.configured = self.apply_basic_settings()
        if self.configured:
            self.init_settings()
            self.apply_other_settings()

        self.monitor = utils.Monitor(updated_settings_callback=self.settings_changed)
        
        self.path = os.path.join(xbmc.translatePath(utils.addon_info('profile')), "snapshots")
        try:
            os.makedirs(self.path)
        except:
            pass

        while not xbmc.abortRequested:
            if self.configured:
                self.alarm_check()

            if self.alarm_active:
                sleep = foscam.ALARM_DURATION - self.duration_shown + self.trigger_interval
            else:
                sleep = self.check_interval
            utils.log_verbose("Sleeping for {0} seconds".format(sleep))

            for i in range(sleep):
                if not xbmc.abortRequested:
                    xbmc.sleep(1000)
예제 #5
0
    def alarm_check(self):
        if self.motion_enable or self.sound_enable:
            player = xbmc.Player()
            if (player.isPlaying() and player.getPlayingFile()
                    in (self.camera.video_url, self.camera.mjpeg_url)):
                return

            self.alarm_active = False

            dev_state = self.camera.get_device_state()
            if dev_state:
                for alarm, enabled in (('motionDetect', self.motion_enable),
                                       ('sound', self.sound_enable)):
                    if enabled:
                        param = "{0}Alarm".format(alarm)
                        alarm_status = dev_state[param]
                        utils.log_verbose("{0:s} = {1:d}".format(
                            param, alarm_status))
                        if alarm_status == 2:
                            self.alarm_active = True
                            utils.log_normal("Alarm detected")
                            break

            if self.alarm_active:
                mjpeg_stream = self.camera.get_mjpeg_stream()
                preview = gui.CameraPreview(self.duration, self.path,
                                            self.scaling, self.position,
                                            mjpeg_stream)
                preview.show()
                self.duration_shown = preview.start()
                del (preview)
예제 #6
0
    def __init__(self):
        utils.log_normal("Starting service")
        self.alarm_active = False
        self.duration_shown = 0

        self.configured = self.apply_basic_settings()
        if self.configured:
            self.init_settings()
            self.apply_other_settings()

        self.monitor = utils.Monitor(
            updated_settings_callback=self.settings_changed)

        self.path = os.path.join(
            xbmc.translatePath(utils.addon_info('profile')), "snapshots")
        try:
            os.makedirs(self.path)
        except:
            pass

        while not xbmc.abortRequested:
            if self.configured:
                self.alarm_check()

            if self.alarm_active:
                sleep = foscam.ALARM_DURATION - self.duration_shown + self.trigger_interval
            else:
                sleep = self.check_interval
            utils.log_verbose("Sleeping for {0} seconds".format(sleep))

            for i in range(sleep):
                if not xbmc.abortRequested:
                    xbmc.sleep(1000)
 def __init__(self,scenename):
     utils.log_normal("Applying Scene: " + scenename)
     self.bridge = LimitlessBridge(addon.getSetting("b0_host"),addon.getSetting("b0_port"))
     scene = LimitlessScene(scenename,0,False)
     for i in ("0","1","2","3","4"):
         lowerscenename = scenename.lower()
         enabled=utils.get_bool_setting("b0_l"+i+"_"+lowerscenename+"_enable")
         if enabled:
             color       = utils.get_setting("b0_l"+i+"_"+lowerscenename+"_color")
             brightness  = utils.get_setting("b0_l"+i+"_"+lowerscenename+"_brightness")
             light       = LimitlessLight(self.bridge,'rgbw',i,True,color,brightness)
             utils.log_verbose("Settings: label: " + lowerscenename + " scenename: " + scenename + " lights: " + str(light))
             scene.addLight(light)
     self.bridge.applyScene(scene)
    def __init__(self):
        utils.log_normal("Starting service")

        monitor = utils.Monitor(updateCallback=self.settings_changed)
        self.configured = self.apply_basic_settings()
        if self.configured:            
            self.bridge.run()
            utils.log_verbose("Bridge ip: " + self.bridge.ipaddress + " port: " + self.bridge.port)

            myplayer = CustomPlayer();
            myplayer.setService(self)
            myplayer.onStartup()

        while not monitor.abortRequested():
            # Sleep/wait for abort for 10 seconds
            if monitor.waitForAbort(4):
                # Abort was requested while waiting. We should exit
                myplayer.onShutdown()
                self.bridge.stop()
                break
 def settings_changed(self):
     utils.log_verbose("Applying settings")
     self.configured = self.apply_basic_settings()