Example #1
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)
Example #2
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)
Example #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)
Example #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)
Example #5
0
    def apply_basic_settings(self):        
        self.check_interval = utils.get_int_setting('check_interval')

        user = utils.get_setting('username')
        password = utils.get_setting('password')
        host = utils.get_setting('host')
        port = utils.get_int_setting('port')

        if not host:
            utils.log_normal("No host specified")
            return False

        invalid = utils.invalid_user_char(user)
        if invalid:
            utils.log_error("Invalid character in user name: " + invalid)
            return False

        invalid = utils.invalid_password_char(password)
        if invalid:
            utils.log_error("Invalid character in password: " + invalid)
            return False

        self.camera = foscam.Camera(host, port, user, password)
        success, msg = self.camera.test()
        if not success:
            utils.log_error(msg)
            return False

        return True
Example #6
0
    def apply_basic_settings(self):
        self.check_interval = utils.get_int_setting('check_interval')

        user = utils.get_setting('username')
        password = utils.get_setting('password')
        host = utils.get_setting('host')
        port = utils.get_int_setting('port')

        if not host:
            utils.log_normal("No host specified")
            return False

        invalid = utils.invalid_user_char(user)
        if invalid:
            utils.log_error("Invalid character in user name: " + invalid)
            return False

        invalid = utils.invalid_password_char(password)
        if invalid:
            utils.log_error("Invalid character in password: " + invalid)
            return False

        self.camera = foscam.Camera(host, port, user, password)
        success, msg = self.camera.test()
        if not success:
            utils.log_error(msg)
            return False

        return True
Example #7
0
    def init_settings(self):
        utils.log_normal("Initialising settings from the camera")

        response = self.camera.get_motion_detect_config()
        utils.set_setting('motion_sensitivity', str(response['sensitivity']))
        utils.set_setting('motion_trigger_interval', str(response['triggerInterval']))
        
        response = self.camera.get_sound_detect_config()
        utils.set_setting('sound_sensitivity', str(response['sensitivity']))
        utils.set_setting('sound_trigger_interval', str(response['triggerInterval']))
Example #8
0
    def start(self):
        utils.log_normal("Starting main view")
        self.playVideo()
        self.setupUi()

        mirror, flip = camera.get_mirror_and_flip()

        self.mirror_button.setSelected(mirror)
        self.flip_button.setSelected(flip)

        self.doModal()
Example #9
0
    def start(self):
        utils.log_normal("Starting main view")
        self.playVideo()
        self.setupUi()

        mirror, flip = camera.get_mirror_and_flip()

        self.mirror_button.setSelected(mirror)
        self.flip_button.setSelected(flip)

        self.doModal()
Example #10
0
    def init_settings(self):
        utils.log_normal("Initialising settings from the camera")

        response = self.camera.get_motion_detect_config()
        utils.set_setting('motion_sensitivity', str(response['sensitivity']))
        utils.set_setting('motion_trigger_interval',
                          str(response['triggerInterval']))

        response = self.camera.get_sound_detect_config()
        utils.set_setting('sound_sensitivity', str(response['sensitivity']))
        utils.set_setting('sound_trigger_interval',
                          str(response['triggerInterval']))
 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)
Example #12
0
    def apply_basic_settings(self):        
        self.check_interval = utils.get_int_setting('check_interval')

        user = utils.get_setting('username')
        password = utils.get_setting('password')
        host = utils.get_setting('host')
        port = utils.get_int_setting('port')

        if not host:
            utils.log_normal("No host specified")
            return False

        self.camera = foscam.Camera(host, port, user, password)
        success, msg = self.camera.test()
        if not success:
            utils.log_error(msg)
            return False

        return True
    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
Example #14
0
 def stop(self):
     utils.log_normal("Closing main view")
     self.player.stop()
     self.close()
     self.player.maybe_resume_previous()
Example #15
0
 def stop(self):
     utils.log_normal("Closing main view")
     self.player.stop()
     self.close()
     self.player.maybe_resume_previous()
Example #16
0
 def settings_changed(self):
     utils.log_normal("Applying settings")
     self.configured = self.apply_basic_settings()
     if self.configured:
         self.apply_other_settings()
Example #17
0
 def settings_changed(self):
     utils.log_normal("Applying settings")
     self.configured = self.apply_basic_settings()
     if self.configured:
         self.apply_other_settings()