def handle_send_command(self, message, inner): state = self.get_player_state(self.state.active_player) button = _COMMAND_LOOKUP.get(inner.command) if button: self.state.last_button_pressed = button _LOGGER.debug("Pressed button: %s", self.state.last_button_pressed) elif inner.command == cmd.ChangeRepeatMode: state.repeat = { protobuf.CommandInfo.One: const.RepeatState.Track, protobuf.CommandInfo.All: const.RepeatState.All, }.get(inner.options.repeatMode, const.RepeatState.Off) self.update_state(self.state.active_player) _LOGGER.debug("Change repeat state to %s", state.repeat) elif inner.command == cmd.ChangeShuffleMode: state.shuffle = inner.options.shuffleMode self.update_state(self.state.active_player) _LOGGER.debug("Change shuffle state to %s", state.shuffle) elif inner.command == cmd.SeekToPlaybackPosition: state.position = inner.options.playbackPosition self.update_state(self.state.active_player) _LOGGER.debug("Seek to position: %d", state.position) else: _LOGGER.warning("Unhandled button press: %s", message.inner().command) self.send( messages.command_result(message.identifier, error_code=1234)) return self.send(messages.command_result(message.identifier))
def handle_send_command(self, message, inner): state = self.state.get_player_state(self.state.active_player) button = _COMMAND_LOOKUP.get(inner.command) if button: self.state.last_button_pressed = button _LOGGER.debug("Pressed button: %s", self.state.last_button_pressed) elif inner.command == cmd.ChangeRepeatMode: state.repeat = { protobuf.RepeatMode.Off: const.RepeatState.Off, protobuf.RepeatMode.One: const.RepeatState.Track, protobuf.RepeatMode.All: const.RepeatState.All, }.get(inner.options.repeatMode, const.RepeatState.Off) self.state.update_state(self.state.active_player) _LOGGER.debug("Change repeat state to %s", state.repeat) elif inner.command == cmd.ChangeShuffleMode: state.shuffle = { protobuf.ShuffleMode.Off: const.ShuffleState.Off, protobuf.ShuffleMode.Albums: const.ShuffleState.Albums, protobuf.ShuffleMode.Songs: const.ShuffleState.Songs, }.get(inner.options.shuffleMode, const.ShuffleState.Off) self.state.update_state(self.state.active_player) _LOGGER.debug("Change shuffle state to %s", state.shuffle) elif inner.command == cmd.SeekToPlaybackPosition: state.position = inner.options.playbackPosition self.state.update_state(self.state.active_player) _LOGGER.debug("Seek to position: %d", state.position) elif inner.command == cmd.SkipForward: state.position += int(inner.options.skipInterval) self.state.update_state(self.state.active_player) _LOGGER.debug("Skip forward %ds", inner.options.skipInterval) elif inner.command == cmd.SkipBackward: state.position -= int(inner.options.skipInterval) self.state.update_state(self.state.active_player) _LOGGER.debug("Skip backwards %d", inner.options.skipInterval) elif inner.command == cmd.Unknown: # This special case is used by pyatv for heartbeats self.state.heartbeat_count += 1 _LOGGER.debug("Received heartbeat (total count: %d)", self.state.heartbeat_count) else: _LOGGER.warning("Unhandled button press: %s", message.inner().command) self.send( messages.command_result( message.identifier, send_error=protobuf.SendError.NoCommandHandlers)) return self.state.last_button_action = None self.send(messages.command_result(message.identifier))
def handle_wake_device(self, message, inner): self.send(messages.command_result(message.identifier)) self.state.powered_on = True self._send_device_info(update=True)
def handle_wake_device(self, message, inner): msg = messages.device_information('pyatv', message.identifier, 1) self.send(msg) self.send(messages.command_result(message.identifier))