コード例 #1
0
    def alarmStateHealthCheck(self):
        """ Function to determine state of alarms on cameras, and also connectivity health of camera """

        # Non-alarm enabled or Generic IP Cameras return this
        if not self.motion_enabled and not self.sound_enabled:
            return False
        
        alarmActive = False  
        success_code, alarmActive, alarm = self.camera.is_alarm_active(self.motion_enabled, self.sound_enabled)

        ### Health Check code for Foscam Camera ###
        if success_code != 0:       

            #Timeout is ~20 seconds before determining camera is not connected  
            for x in range(1,2):
                
                utils.log(2, 'Camera %s :: SERVICE HEALTH CHECK :: Did not receive response 0, received response %d.  Retry # %d in 5 seconds' %(self.camera.number, success_code, x))
                self.monitor.waitForAbort(5)
                success_code, alarmActive, alarm = self.camera.is_alarm_active(self.motion_enabled, self.sound_enabled)      

                if success_code == 0:  
                    break

            #Camera is not connected, so notify the user
            if success_code != 0:

                self.monitor.closeRequest(self.camera.number)
                utils.notify(utils.translation(32222) %self.camera.number)   
                self.monitor.write_testResult(self.camera.number, success_code)

                #Loop to keep retrying the connection ever 60 seconds
                x = 0
                while success_code != 0:
                    if self.monitor.abortRequested() or self.monitor.stopped():
                        return False
                    
                    if x > 60:
                        x = 0
                        utils.log(3, 'Camera %s :: SERVICE HEALTH CHECK  :: Did not receive response 0, received response %d.  Retrying every 60 seconds.' %(self.camera.number, success_code))
                        success_code, alarmActive, alarm = self.camera.is_alarm_active(self.motion_enabled, self.sound_enabled)
                    
                    self.monitor.waitForAbort(1)
                    x += 1

                utils.notify(utils.translation(32223) %self.camera.number)
                self.monitor.write_testResult(self.camera.number, success_code)
                
                #Reset PTZ Camera on Service Start
                self.camera.resetLocation()
                    
            ### End of Health Check code for Foscam HD camera ###


        if alarmActive:
            self.monitor.set_alarmActive(self.camera.number)
            utils.log(2, 'Camera %s :: Alarm detected: (%sed).' %(self.camera.number, alarm))
            return True
    
        self.monitor.clear_alarmActive(self.camera.number)   
        return False
コード例 #2
0
    def run(self, monitor):
        self.monitor = monitor
        self.monitor.reset()
        preview_enabled_cameras = []        
        self.threads = []
        
        for camera_number in "123456":

            utils.log(2, 'Camera %s :: Enabled: %s;  Preview Enabled: %s' %(camera_number, settings.enabled_camera(camera_number), settings.enabled_preview(camera_number)))
            if settings.enabled_camera(camera_number):
                camera = Camera(camera_number)

                if settings.enabled_preview(camera_number):
                    
                    if camera.Connected(self.monitor, useCache=False):

                        previewWindow = threading.Thread(target = camerapreview.CameraPreviewWindow, args = (camera, self.monitor, ))
                        previewWindow.daemon = True
                        previewWindow.start()
                        
                        t = CameraPreviewThread(camera, self.monitor, )
                        t.daemon = True 
                        self.threads.append(t)
                        t.start()

                        utils.log(1, 'Camera %s :: Preview Thread started.' %camera_number)

                    else:
                        utils.log(1, 'Camera %s :: Preview thread did not start because camera is not properly configured.' %camera_number)
                        utils.notify('Error Connecting to Camera %s.' %camera_number)
                
        utils.notify(utils.translation(32224))  #Service Started
        
        xbmc.executebuiltin('Container.Refresh')
        
        while not self.monitor.stopped() and not self.monitor.abortRequested():
            self.monitor.waitForAbort(1)

        if self.monitor.stopped() and not self.monitor.abortRequested():
            utils.notify(utils.translation(32225))  #Service Restarting
            self.restart()

        '''                             
コード例 #3
0
def advanced_menu():
    """ Second Level Menu which provides advanced options """

    for camera_number in "123456":

        if settings.enabled_camera(camera_number):

            list_label = settings.getCameraName(camera_number)

            # List submenus for each enabled camera
            addDirectoryItem(name=list_label + ' ' + utils.translation(32029),
                             isFolder=True,
                             icon=utils.get_icon(camera_number),
                             fanart=utils.get_fanart(camera_number),
                             parameters={
                                 'action': 'advanced_camera',
                                 'camera_number': camera_number
                             })

    # Toggle Preview Ability to be activated by alarms
    addDirectoryItem(name=utils.translation(32217),
                     icon=utils.get_icon('settings'),
                     fanart=utils.get_fanart('default'),
                     parameters={'action': 'toggle_preview'})

    # Add-on Settings
    addDirectoryItem(name=utils.translation(32028),
                     icon=utils.get_icon('settings'),
                     fanart=utils.get_fanart('default'),
                     parameters={'action': 'settings'})

    # Restart the preview service
    addDirectoryItem(name='Restart Preview Service',
                     icon=utils.get_icon('settings'),
                     fanart=utils.get_fanart('default'),
                     parameters={'action': 'restart_service'})

    xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
コード例 #4
0
def advanced_menu():                                                
    """ Second Level Menu which provides advanced options """
    
    for camera_number in "123456":
        
        if settings.enabled_camera(camera_number):
            
            list_label = settings.getCameraName(camera_number)
            
            # List submenus for each enabled camera
            addDirectoryItem(name =  list_label + ' ' + utils.translation(32029),
                             isFolder = True,
                             icon = utils.get_icon(camera_number),
                             fanart = utils.get_fanart(camera_number),
                             parameters = {'action': 'advanced_camera',
                                           'camera_number': camera_number})
    

    # Toggle Preview Ability to be activated by alarms
    addDirectoryItem(name = utils.translation(32217),
                     icon = utils.get_icon('settings'), 
                     fanart = utils.get_fanart('default'),
                     parameters = {'action': 'toggle_preview'})

    # Add-on Settings  
    addDirectoryItem(name = utils.translation(32028),
                     icon = utils.get_icon('settings'), 
                     fanart = utils.get_fanart('default'),
                     parameters = {'action': 'settings'})

    # Restart the preview service
    addDirectoryItem(name = 'Restart Preview Service',
                     icon = utils.get_icon('settings'), 
                     fanart = utils.get_fanart('default'),
                     parameters = {'action': 'restart_service'})
        
    xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
コード例 #5
0
def advanced_camera_menu(camera_number):                                                
    """ Third Level Advanced Menu for additional IP Camera Functions """
    
    #EXTENDED MENU IDEAS
    #FPS Test
    #Force Show preview mjpeg / snapshot
    #Show snapshot

    if settings.getSetting('enabled_preview', camera_number) == 'true':
        
        #Show Preview
        addDirectoryItem(name = utils.translation(32210),
                     icon = utils.get_icon('settings'),
                     fanart = utils.get_fanart(camera_number),
                     parameters = {'action': 'show_preview',
                                   'camera_number': camera_number})
        
        #Disable Preview
        addDirectoryItem(name = utils.translation(32212),
                         icon = utils.get_icon('settings'),
                         fanart = utils.get_fanart(camera_number),
                         parameters = {'action': 'disable_preview',
                                       'camera_number': camera_number})

    else:
        
        #Enable Preview
        addDirectoryItem(name = utils.translation(32211),
                         icon = utils.get_icon('settings'),
                         fanart = utils.get_fanart(camera_number),
                         parameters = {'action': 'enable_preview',
                                       'camera_number': camera_number})

    if settings.getSetting_int('fanart') == 1:
        
        #Update Fanart
        addDirectoryItem(name = utils.translation(32213),
                         icon = utils.get_icon('settings'),
                         fanart = utils.get_fanart(camera_number),
                         parameters = {'action': 'update_fanart',
                                       'camera_number': camera_number})
    
    camera_type = settings.getCameraType(camera_number)
    
    if camera_type < 3:

        #Play Stream no Controls
        addDirectoryItem(name = utils.translation(32214),
                         icon = utils.get_icon('settings'),
                         fanart = utils.get_fanart(camera_number),
                         parameters = {'action': 'single_camera_no_controls',
                                       'camera_number': camera_number})
        
        
        #Camera Settings
        addDirectoryItem(name = utils.translation(32215),
                         icon = utils.get_icon('settings'),
                         fanart = utils.get_fanart(camera_number),
                         parameters = {'action': 'camera_settings',
                                       'camera_number': camera_number})

        #Reboot Camera
        addDirectoryItem(name = utils.translation(32216),
                         icon = utils.get_icon('settings'),
                         fanart = utils.get_fanart(camera_number),
                         parameters = {'action': 'reboot',
                                       'camera_number': camera_number})


    xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
コード例 #6
0
def main_menu():                                                
    """ First Level Menu to access main functions """

    if settings.atLeastOneCamera():

        # All Camera Player
        addDirectoryItem(name = utils.translation(32027),
                         icon = utils.get_icon('default'),
                         fanart = utils.get_fanart('default'),
                         parameters = {'action': 'all_cameras'})

        for camera_number in "123456":
            
            if settings.enabled_camera(camera_number):
                
                camera = Camera(camera_number)
                list_label = settings.getCameraName(camera_number)

                # Build Context Menu
                li = li = xbmcgui.ListItem(list_label)
                context_items = []

                if settings.getSetting('enabled_preview', camera_number) == 'true':
                    #Show Preview
                    context_items.append((utils.translation(32210), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=show_preview&camera_number=%s)' %camera_number))

                    #Disable Preview
                    context_items.append((utils.translation(32212), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=disable_preview&camera_number=%s)' %camera_number))
                else:
                    #Enable Preview
                    context_items.append((utils.translation(32211), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=enable_preview&camera_number=%s)' %camera_number))
                
                camera_type = settings.getCameraType(camera_number)
                if camera_type < 3:
                    #Play Stream no Controls
                    context_items.append((utils.translation(32214), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=single_camera_no_controls&camera_number=%s)' %camera_number))

                    #Camera Settings
                    context_items.append((utils.translation(32215), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=camera_settings&camera_number=%s)' %camera_number))

                # Update Fanart
                if settings.getSetting_int('fanart') == 1:
                    context_items.append((utils.translation(32213), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=update_fanart&camera_number=%s)' %camera_number))
                    
                li.addContextMenuItems(context_items, replaceItems=True)

                # Fanart URL
                new_art_url = None
                if camera.Connected(monitor):
                    new_art_url = camera.getSnapShotUrl()
                else:
                    if camera.Connected(monitor, False):
                        new_art_url = camera.getSnapShotUrl()
                
                # Single Camera Player for enabled cameras
                addDirectoryItem(name = list_label, 
                                 icon = utils.get_icon(camera_number),
                                 fanart = utils.get_fanart(camera_number, new_art_url),
                                 li = li, 
                                 parameters = {'action': 'single_camera',
                                               'camera_number': camera_number})

        # Link to Second Level Advanced Menu
        addDirectoryItem(name = utils.translation(32029),
                         isFolder = True,
                         icon = utils.get_icon('advanced'), 
                         fanart = utils.get_fanart('default'),
                         parameters={'action': 'advanced'})

    else:

        # Add-on Settings if no cameras are configured
        addDirectoryItem(name = utils.translation(32028),
                     icon = utils.get_icon('settings'), 
                     fanart = utils.get_fanart('default'),
                     parameters = {'action': 'settings'})

    xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
    utils.cleanup_images()     
コード例 #7
0
    # Single Camera Stream   
    elif action == 'single_camera': 
        cameraplayer.play(camera_number)
        

    # Single Camera Stream without Controls   
    elif action == 'single_camera_no_controls':
        cameraplayer.play(camera_number, False)


    # Reboot Camera  
    elif action == 'reboot':
        with Camera(camera_number) as camera:
            response = camera.reboot()
            if response[0] == 0:
                utils.dialog_ok(utils.translation(32218))
            else:
                utils.dialog_ok(utils.translation(32219))


    # Camera settings 
    elif action == 'camera_settings':
        window = camerasettings.CameraSettingsWindow(camera_number)
        window.doModal()
        del window
        utils.dialog_ok(utils.translation(32220))


    # Show Preview 
    elif action == 'show_preview':
        if settings.enabled_preview(camera_number):
コード例 #8
0
def advanced_camera_menu(camera_number):
    """ Third Level Advanced Menu for additional IP Camera Functions """

    #EXTENDED MENU IDEAS
    #FPS Test
    #Force Show preview mjpeg / snapshot
    #Show snapshot

    if settings.getSetting('enabled_preview', camera_number) == 'true':

        #Show Preview
        addDirectoryItem(name=utils.translation(32210),
                         icon=utils.get_icon('settings'),
                         fanart=utils.get_fanart(camera_number),
                         parameters={
                             'action': 'show_preview',
                             'camera_number': camera_number
                         })

        #Disable Preview
        addDirectoryItem(name=utils.translation(32212),
                         icon=utils.get_icon('settings'),
                         fanart=utils.get_fanart(camera_number),
                         parameters={
                             'action': 'disable_preview',
                             'camera_number': camera_number
                         })

    else:

        #Enable Preview
        addDirectoryItem(name=utils.translation(32211),
                         icon=utils.get_icon('settings'),
                         fanart=utils.get_fanart(camera_number),
                         parameters={
                             'action': 'enable_preview',
                             'camera_number': camera_number
                         })

    if settings.getSetting_int('fanart') == 1:

        #Update Fanart
        addDirectoryItem(name=utils.translation(32213),
                         icon=utils.get_icon('settings'),
                         fanart=utils.get_fanart(camera_number),
                         parameters={
                             'action': 'update_fanart',
                             'camera_number': camera_number
                         })

    camera_type = settings.getCameraType(camera_number)

    if camera_type < 3:

        #Play Stream no Controls
        addDirectoryItem(name=utils.translation(32214),
                         icon=utils.get_icon('settings'),
                         fanart=utils.get_fanart(camera_number),
                         parameters={
                             'action': 'single_camera_no_controls',
                             'camera_number': camera_number
                         })

        #Camera Settings
        addDirectoryItem(name=utils.translation(32215),
                         icon=utils.get_icon('settings'),
                         fanart=utils.get_fanart(camera_number),
                         parameters={
                             'action': 'camera_settings',
                             'camera_number': camera_number
                         })

        #Reboot Camera
        addDirectoryItem(name=utils.translation(32216),
                         icon=utils.get_icon('settings'),
                         fanart=utils.get_fanart(camera_number),
                         parameters={
                             'action': 'reboot',
                             'camera_number': camera_number
                         })

    xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
コード例 #9
0
def main_menu():
    """ First Level Menu to access main functions """

    if settings.atLeastOneCamera():

        # All Camera Player
        addDirectoryItem(name=utils.translation(32027),
                         icon=utils.get_icon('default'),
                         fanart=utils.get_fanart('default'),
                         parameters={'action': 'all_cameras'})

        for camera_number in "123456":

            if settings.enabled_camera(camera_number):

                camera = Camera(camera_number)
                list_label = settings.getCameraName(camera_number)

                # Build Context Menu
                li = li = xbmcgui.ListItem(list_label)
                context_items = []

                if settings.getSetting('enabled_preview',
                                       camera_number) == 'true':
                    #Show Preview
                    context_items.append((utils.translation(
                        32210
                    ), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=show_preview&camera_number=%s)'
                                          % camera_number))

                    #Disable Preview
                    context_items.append((utils.translation(
                        32212
                    ), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=disable_preview&camera_number=%s)'
                                          % camera_number))
                else:
                    #Enable Preview
                    context_items.append((utils.translation(
                        32211
                    ), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=enable_preview&camera_number=%s)'
                                          % camera_number))

                camera_type = settings.getCameraType(camera_number)
                if camera_type < 3:
                    #Play Stream no Controls
                    context_items.append((utils.translation(
                        32214
                    ), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=single_camera_no_controls&camera_number=%s)'
                                          % camera_number))

                    #Camera Settings
                    context_items.append((utils.translation(
                        32215
                    ), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=camera_settings&camera_number=%s)'
                                          % camera_number))

                # Update Fanart
                if settings.getSetting_int('fanart') == 1:
                    context_items.append((utils.translation(
                        32213
                    ), 'RunPlugin(plugin://plugin.video.surveillanceroom?action=update_fanart&camera_number=%s)'
                                          % camera_number))

                li.addContextMenuItems(context_items, replaceItems=True)

                # Fanart URL
                new_art_url = None
                if camera.Connected(monitor):
                    new_art_url = camera.getSnapShotUrl()
                else:
                    if camera.Connected(monitor, False):
                        new_art_url = camera.getSnapShotUrl()

                # Single Camera Player for enabled cameras
                addDirectoryItem(name=list_label,
                                 icon=utils.get_icon(camera_number),
                                 fanart=utils.get_fanart(
                                     camera_number, new_art_url),
                                 li=li,
                                 parameters={
                                     'action': 'single_camera',
                                     'camera_number': camera_number
                                 })

        # Link to Second Level Advanced Menu
        addDirectoryItem(name=utils.translation(32029),
                         isFolder=True,
                         icon=utils.get_icon('advanced'),
                         fanart=utils.get_fanart('default'),
                         parameters={'action': 'advanced'})

    else:

        # Add-on Settings if no cameras are configured
        addDirectoryItem(name=utils.translation(32028),
                         icon=utils.get_icon('settings'),
                         fanart=utils.get_fanart('default'),
                         parameters={'action': 'settings'})

    xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
    utils.cleanup_images()
コード例 #10
0
        allcameraplayer.play()

    # Single Camera Stream
    elif action == 'single_camera':
        cameraplayer.play(camera_number)

    # Single Camera Stream without Controls
    elif action == 'single_camera_no_controls':
        cameraplayer.play(camera_number, False)

    # Reboot Camera
    elif action == 'reboot':
        with Camera(camera_number) as camera:
            response = camera.reboot()
            if response[0] == 0:
                utils.dialog_ok(utils.translation(32218))
            else:
                utils.dialog_ok(utils.translation(32219))

    # Camera settings
    elif action == 'camera_settings':
        window = camerasettings.CameraSettingsWindow(camera_number)
        window.doModal()
        del window
        utils.dialog_ok(utils.translation(32220))

    # Show Preview
    elif action == 'show_preview':
        if settings.enabled_preview(camera_number):
            if settings.getSetting_int(
                    'cond_manual_toggle', camera_number