Beispiel #1
0
    def _canProcessFilteredAction(self):
        currentTime = time.time()

        # Make sure we are not in a blackout zone
        if currentTime > self.nextFilteredAction:
            # Reset the time, and make sure we do not process any others
            # for another 2 seconds (This will prevent a large build up
            # as we hope that the sonos system can process this within
            # 2 seconds, otherwise there will be a delay)
            self.nextFilteredAction = currentTime + Settings.getAvoidDuplicateCommands()
            return True
        elif self.nextFilteredAction > 0:
            log("SonosControllerWindow: Ignoring commands until %s" % time.strftime("%H:%M:%S", time.gmtime(self.nextFilteredAction)))

        return False
Beispiel #2
0
    def _canProcessFilteredAction(self):
        currentTime = time.time()

        # Make sure we are not in a blackout zone
        if currentTime > self.nextFilteredAction:
            # Reset the time, and make sure we do not process any others
            # for another 2 seconds (This will prevent a large build up
            # as we hope that the sonos system can process this within
            # 2 seconds, otherwise there will be a delay)
            self.nextFilteredAction = currentTime + Settings.getAvoidDuplicateCommands(
            )
            return True
        elif self.nextFilteredAction > 0:
            log("SonosControllerWindow: Ignoring commands until %s" %
                time.strftime("%H:%M:%S", time.gmtime(
                    self.nextFilteredAction)))

        return False
Beispiel #3
0
    def onAction(self, action):
        # actioncodes from https://github.com/xbmc/xbmc/blob/master/xbmc/guilib/Key.h
        ACTION_PREVIOUS_MENU = 10
        ACTION_NAV_BACK = 92

        # For remote control
        ACTION_PAUSE = 12
        ACTION_STOP = 13
        ACTION_NEXT_ITEM = 14
        ACTION_PREV_ITEM = 15
        # The following 4 are active forward and back
        ACTION_FORWARD = 16
        ACTION_REWIND = 17
        ACTION_PLAYER_FORWARD = 77
        ACTION_PLAYER_REWIND = 78

        ACTION_PLAYER_PLAY = 79
        ACTION_VOLUME_UP = 88
        ACTION_VOLUME_DOWN = 89
        ACTION_MUTE = 91

        # Values Used in the custom keymap
        ACTION_FIRST_PAGE = 159  # Next Track
        ACTION_LAST_PAGE = 160  # Previous Track
        ACTION_PAGE_UP = 5  # Increase Volume
        ACTION_PAGE_DOWN = 6  # Decrease Volume
        ACTION_TOGGLE_WATCHED = 200  # Mute volume

        if (action == ACTION_PREVIOUS_MENU) or (action == ACTION_NAV_BACK):
            log("SonosControllerWindow: Close Action received: %s" % str(action.getId()))
            self.close()
        else:
            # Handle remote control commands
            if((action == ACTION_PLAYER_PLAY) or (action == ACTION_PAUSE)):
                # Get the initial state of the device
                playStatus = self.sonosDevice.get_current_transport_info()

                # Play/pause is a toggle, so pause if playing
                if playStatus is not None:
                    if playStatus['current_transport_state'] == 'PLAYING':
                        self.onClick(SonosControllerWindow.BUTTON_PAUSE)
                    else:
                        self.onClick(SonosControllerWindow.BUTTON_PLAY)
            elif (action == ACTION_STOP):
                self.onClick(SonosControllerWindow.BUTTON_STOP)
            elif (action == ACTION_NEXT_ITEM) or (action == ACTION_FIRST_PAGE):
                self.onClick(SonosControllerWindow.BUTTON_NEXT)
            elif (action == ACTION_PREV_ITEM) or (action == ACTION_LAST_PAGE):
                self.onClick(SonosControllerWindow.BUTTON_PREVIOUS)
            elif (action == ACTION_MUTE) or (action == ACTION_TOGGLE_WATCHED):
                # Check if currently muted
                if self.sonosDevice.mute is False:
                    self.onClick(SonosControllerWindow.BUTTON_NOT_MUTED)
                else:
                    self.onClick(SonosControllerWindow.BUTTON_MUTED)
            elif (action == ACTION_VOLUME_UP) or (action == ACTION_PAGE_UP):
                # Get the current slider position
                volumeSlider = self.getControl(SonosControllerWindow.SLIDER_VOLUME)
                currentSliderPosition = int(volumeSlider.getPercent())
                if currentSliderPosition < 100:
                    # Bump the volume by double the wait time (otherwise we can't skip forward accurately)
                    volumeSlider.setPercent(currentSliderPosition + Settings.getVolumeChangeIncrements())
                    self.onClick(SonosControllerWindow.SLIDER_VOLUME)
            elif (action == ACTION_VOLUME_DOWN) or (action == ACTION_PAGE_DOWN):
                # Get the current slider position
                volumeSlider = self.getControl(SonosControllerWindow.SLIDER_VOLUME)
                currentSliderPosition = int(volumeSlider.getPercent())
                if currentSliderPosition > 0:
                    # Bump the volume down by double the wait time (otherwise we can't skip forward accurately)
                    volumeSlider.setPercent(currentSliderPosition - Settings.getVolumeChangeIncrements())
                    self.onClick(SonosControllerWindow.SLIDER_VOLUME)
            elif((action == ACTION_FORWARD) or (action == ACTION_PLAYER_FORWARD)):
                # Get the current slider position
                seekSlider = self.getControl(SonosControllerWindow.SLIDER_SEEK)
                currentSliderPosition = int(seekSlider.getPercent())
                if currentSliderPosition < 99:
                    # Bump the slider by double the wait time (otherwise we can't skip forward accurately)
                    seekSlider.setPercent(currentSliderPosition + (int(Settings.getAvoidDuplicateCommands()) * 2))
                    self.onClick(SonosControllerWindow.SLIDER_SEEK)
            elif((action == ACTION_REWIND) or (action == ACTION_PLAYER_REWIND)):
                # Get the current slider position
                seekSlider = self.getControl(SonosControllerWindow.SLIDER_SEEK)
                currentSliderPosition = int(seekSlider.getPercent())
                if currentSliderPosition > 0:
                    # Bump the slider down by double the wait time (otherwise we can't skip forward accurately)
                    seekSlider.setPercent(currentSliderPosition - (int(Settings.getAvoidDuplicateCommands()) * 2))
                    self.onClick(SonosControllerWindow.SLIDER_SEEK)
Beispiel #4
0
    def onAction(self, action):
        # actioncodes from https://github.com/xbmc/xbmc/blob/master/xbmc/guilib/Key.h
        ACTION_PREVIOUS_MENU = 10
        ACTION_NAV_BACK = 92

        # For remote control
        ACTION_PAUSE = 12
        ACTION_STOP = 13
        ACTION_NEXT_ITEM = 14
        ACTION_PREV_ITEM = 15
        # The following 4 are active forward and back
        ACTION_FORWARD = 16
        ACTION_REWIND = 17
        ACTION_PLAYER_FORWARD = 77
        ACTION_PLAYER_REWIND = 78

        ACTION_PLAYER_PLAY = 79
        ACTION_VOLUME_UP = 88
        ACTION_VOLUME_DOWN = 89
        ACTION_MUTE = 91

        # Values Used in the custom keymap
        ACTION_FIRST_PAGE = 159  # Next Track
        ACTION_LAST_PAGE = 160  # Previous Track
        ACTION_PAGE_UP = 5  # Increase Volume
        ACTION_PAGE_DOWN = 6  # Decrease Volume
        ACTION_TOGGLE_WATCHED = 200  # Mute volume

        if (action == ACTION_PREVIOUS_MENU) or (action == ACTION_NAV_BACK):
            log("SonosControllerWindow: Close Action received: %s" %
                str(action.getId()))
            self.close()
        else:
            # Handle remote control commands
            if ((action == ACTION_PLAYER_PLAY) or (action == ACTION_PAUSE)):
                # Get the initial state of the device
                playStatus = self.sonosDevice.get_current_transport_info()

                # Play/pause is a toggle, so pause if playing
                if playStatus is not None:
                    if playStatus['current_transport_state'] == 'PLAYING':
                        self.onClick(SonosControllerWindow.BUTTON_PAUSE)
                    else:
                        self.onClick(SonosControllerWindow.BUTTON_PLAY)
            elif (action == ACTION_STOP):
                self.onClick(SonosControllerWindow.BUTTON_STOP)
            elif (action == ACTION_NEXT_ITEM) or (action == ACTION_FIRST_PAGE):
                self.onClick(SonosControllerWindow.BUTTON_NEXT)
            elif (action == ACTION_PREV_ITEM) or (action == ACTION_LAST_PAGE):
                self.onClick(SonosControllerWindow.BUTTON_PREVIOUS)
            elif (action == ACTION_MUTE) or (action == ACTION_TOGGLE_WATCHED):
                # Check if currently muted
                if self.sonosDevice.mute is False:
                    self.onClick(SonosControllerWindow.BUTTON_NOT_MUTED)
                else:
                    self.onClick(SonosControllerWindow.BUTTON_MUTED)
            elif (action == ACTION_VOLUME_UP) or (action == ACTION_PAGE_UP):
                # Get the current slider position
                volumeSlider = self.getControl(
                    SonosControllerWindow.SLIDER_VOLUME)
                currentSliderPosition = int(volumeSlider.getPercent())
                if currentSliderPosition < 100:
                    # Bump the volume by double the wait time (otherwise we can't skip forward accurately)
                    volumeSlider.setPercent(
                        currentSliderPosition +
                        Settings.getVolumeChangeIncrements())
                    self.onClick(SonosControllerWindow.SLIDER_VOLUME)
            elif (action == ACTION_VOLUME_DOWN) or (action
                                                    == ACTION_PAGE_DOWN):
                # Get the current slider position
                volumeSlider = self.getControl(
                    SonosControllerWindow.SLIDER_VOLUME)
                currentSliderPosition = int(volumeSlider.getPercent())
                if currentSliderPosition > 0:
                    # Bump the volume down by double the wait time (otherwise we can't skip forward accurately)
                    volumeSlider.setPercent(
                        currentSliderPosition -
                        Settings.getVolumeChangeIncrements())
                    self.onClick(SonosControllerWindow.SLIDER_VOLUME)
            elif ((action == ACTION_FORWARD)
                  or (action == ACTION_PLAYER_FORWARD)):
                # Get the current slider position
                seekSlider = self.getControl(SonosControllerWindow.SLIDER_SEEK)
                currentSliderPosition = int(seekSlider.getPercent())
                if currentSliderPosition < 99:
                    # Bump the slider by double the wait time (otherwise we can't skip forward accurately)
                    seekSlider.setPercent(currentSliderPosition + (
                        int(Settings.getAvoidDuplicateCommands()) * 2))
                    self.onClick(SonosControllerWindow.SLIDER_SEEK)
            elif ((action == ACTION_REWIND)
                  or (action == ACTION_PLAYER_REWIND)):
                # Get the current slider position
                seekSlider = self.getControl(SonosControllerWindow.SLIDER_SEEK)
                currentSliderPosition = int(seekSlider.getPercent())
                if currentSliderPosition > 0:
                    # Bump the slider down by double the wait time (otherwise we can't skip forward accurately)
                    seekSlider.setPercent(currentSliderPosition - (
                        int(Settings.getAvoidDuplicateCommands()) * 2))
                    self.onClick(SonosControllerWindow.SLIDER_SEEK)