Advertisement
martinezmp3

Plex Communicator Device

May 20th, 2021
914
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 3.14 KB | None | 0 0
  1. /**
  2.  *  Plex Communicator Device
  3.  *
  4.  *  Copyright 2018 Jake Tebbett (jebbett)
  5.  *
  6.  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  7.  *  in compliance with the License. You may obtain a copy of the License at:
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  12.  *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  13.  *  for the specific language governing permissions and limitations under the License.
  14.  *
  15.  * 2018-11-17   2.0     Updated to report playbackType Correctly
  16.  * 2020-05-24   2.1    Updated to add track title
  17.  */
  18.  
  19. metadata {
  20.     definition (name: "Plex Communicator Device", namespace: "jebbett", author: "jebbett") {
  21.         capability "Music Player"
  22.         attribute "playbackType", "string"
  23.         attribute "status", "string"
  24.         attribute "trackDescription", "string"
  25.         //edition of original code from Jake Tebbett (05/18/21)
  26.         attribute "Rating", "string"
  27.         attribute "Season", "string"
  28.         attribute "Episode", "string"
  29.         attribute "Show", "string"
  30.         attribute "Live", "bool"
  31.         command "CustomCommand",["string"]  ///********/05/20/21******* send commands to the server
  32.         //end of edition
  33.     }
  34. }
  35. preferences {
  36.     input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true  ////****** no really need it
  37. }
  38. //addition
  39. def installed() {
  40.     state.XPlexTargetClientIdentifier = device.deviceNetworkId /////*****store the XPlexTargetClientIdentifier  /05/20/21
  41. }
  42.  
  43. // External
  44. def playbackType(type) {
  45.     sendEvent(name: "playbackType", value: type);
  46.     //log.debug "Playback type set as $type"
  47. }
  48. def setPlayStatus(status){
  49.     // Value needs to be playing, paused or stopped
  50.     sendEvent(name: "status", value: status)
  51.     log.debug "Status set to $status"
  52. }
  53. def setTitle(title) {
  54.     sendEvent(name: "trackDescription", value: title);
  55.     //log.debug "Title set as $title"
  56. }
  57. def play() {           
  58.     //sendEvent(name: "status", value: "playing");
  59.     parent.sendCommand (state.XPlexTargetClientIdentifier,"/player/playback/play") //edition 05/20/21
  60. }
  61. def pause() {
  62.     //sendEvent(name: "status", value: "paused");
  63.     parent.sendCommand (state.XPlexTargetClientIdentifier,"/player/playback/pause") //edition 05/20/21
  64. }
  65. def stop() {
  66.     //sendEvent(name: "status", value: "stopped");
  67.     parent.sendCommand (state.XPlexTargetClientIdentifier,"/player/playback/stop") //edition 05/20/21
  68. }
  69. def previousTrack (){
  70.     parent.sendCommand (state.XPlexTargetClientIdentifier,"/player/playback/skipPrevious") //edition 05/20/21
  71. }
  72. def nextTrack (){
  73.     parent.sendCommand (state.XPlexTargetClientIdentifier,"/player/playback/skipNext") //edition 05/20/21
  74. }
  75. def setLevel(volumelevel){
  76.     parent.sendCommand (state.XPlexTargetClientIdentifier,"/player/playback/setParameters?volume=${volumelevel}") //edition 05/20/21
  77. }
  78. def CustomCommand (cmd){
  79.     parent.sendCommand (state.XPlexTargetClientIdentifier,cmd) //edition 05/20/21
  80. }
  81.    
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement