From c963718900ef565d0529b1cd9085531b0cf1cf7e Mon Sep 17 00:00:00 2001
From: Oliver Wagner <owagner@tellerulam.com>
Date: Sun, 1 May 2016 12:52:08 +0200
Subject: [PATCH] v0.13 - 2016-05-01 - owagner   - change logic for
 command/playbackstate:      - resume/play/1 will now properly resume when
 pausing, and attempt to        start play when playback has endeded. Fixes
 #17      - pause/2 will now only pause if the player is actually playing.    
    It can no longer be used to toggle pause mode.      - toggle (new) will
 now toggle pause mode, similarily to how "pause"        did before

Also updated README.md, which was lagging behind describing new settings
---
 README.md                  | 10 +++++++---
 service.mqtt/addon.xml     |  4 ++--
 service.mqtt/changelog.txt |  9 +++++++++
 service.mqtt/service.py    | 16 ++++++++++++----
 4 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md
index a38914d..4af3ee5 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ See https://github.com/mqtt-smarthome for a rationale and architectural overview
 
 Dependencies
 ------------
-* Kodi 14 Helix (or newer)
+* Kodi 14 Helix (or newer). Tested with 16.1.
 * Eclipse Paho for Python - http://www.eclipse.org/paho/clients/python/
   (used for MQTT communication)
 
@@ -27,11 +27,14 @@ Dependencies
 
 Settings
 --------
-The addon has three settings:
+The addon has multiple settings:
 
 * the MQTT broker's host name or IP address (defaults to 127.0.0.1)
 * the MQTT broker's port. This defaults to 1883, which is the MQTT standard port for unencrypted connections.
 * the topic prefix which to use in all published and subscribed topics. Defaults to "kodi/".
+* MQTT authentication and TLS settings
+* update frequency intervals
+* keyword filtering on content details, to prevent certain kind of content to be e.g. displayed in a SmartHome visualization
 
 
 Topics
@@ -64,8 +67,9 @@ The addon listens to the following topics (prefixed with the configured topic pr
   to the Player.Open() JSON_RPC call
 * command/playbackstate: A simple string or numeric with the values:
   - "0" or "stop" to stop playback
-  - "1" or "resume" to resume playback (when paused)
+  - "1" or "resume" or "play" to resume playback (when paused or stopped)
   - "2" or "pause" to stop playback (when playing)
+  - "toggle" to toggle between play and pause
   - "next" to play the next track
   - "previous" to play the previous track
 
diff --git a/service.mqtt/addon.xml b/service.mqtt/addon.xml
index 3a3e01a..370a461 100644
--- a/service.mqtt/addon.xml
+++ b/service.mqtt/addon.xml
@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<addon id="service.mqtt" name="MQTT Adapter" version="0.12" provider-name="owagner">
+<addon id="service.mqtt" name="MQTT Adapter" version="0.13" provider-name="owagner">
   <requires>
     <import addon="xbmc.python" version="2.19.0"/>
   </requires>
   <extension point="xbmc.service" library="service.py" start="login" />
   <extension point="xbmc.addon.metadata">
     <summary lang="en">MQTT Adapter, adhering to mqtt-smarthome specification</summary>
-    <description lang="en">The addon is an adapter to a MQTT broker. It will publish information about what is playing, and provides remote control capability. It adheres to the mqtt-smarthome specification. </description>
+    <description lang="en">The addon is an adapter to an MQTT broker. It will publish information about what is playing, and provides remote control capability. It adheres to the mqtt-smarthome specification. </description>
     <disclaimer lang="en"></disclaimer>
     <platform>all</platform>
     <license>MIT</license>
diff --git a/service.mqtt/changelog.txt b/service.mqtt/changelog.txt
index e5a21c9..b00bfa5 100644
--- a/service.mqtt/changelog.txt
+++ b/service.mqtt/changelog.txt
@@ -1,3 +1,12 @@
+v0.13 - 2016-05-01 - owagner
+  - change logic for command/playbackstate:
+     - resume/play/1 will now properly resume when pausing, and attempt to
+       start play when playback has endeded. Fixes #17
+     - pause/2 will now only pause if the player is actually playing.
+       It can no longer be used to toggle pause mode.
+     - toggle (new) will now toggle pause mode, similarily to how "pause"
+       did before
+
 v0.12 - 2016-02-022 - markferry
   - fix non-JSON case for handling command/notify
 
diff --git a/service.mqtt/service.py b/service.mqtt/service.py
index 0a80b90..af4cd2d 100644
--- a/service.mqtt/service.py
+++ b/service.mqtt/service.py
@@ -25,6 +25,7 @@ def load_settings():
 
 activeplayerid=-1
 activeplayertype=""
+playbackstate=0
 lasttitle=""
 lastdetail={}
 
@@ -66,7 +67,8 @@ def publish(suffix,val,more):
 # the state is "playing"
 #
 def setplaystate(state,detail):
-    global activeplayerid,activeplayertype
+    global activeplayerid,activeplayertype,playbackstate
+    playbackstate=state
     if state==1:
         res=sendrpc("Player.GetActivePlayers",{})
         activeplayerid=res["result"][0]["playerid"]
@@ -185,13 +187,19 @@ def processplay(data):
         player.play(data)
 
 def processplaybackstate(data):
+    global playbackstate
     if data=="0" or data=="stop":
         player.stop()
-    elif data=="1" or data=="resume":
-        if not player.isPlaying():
+    elif data=="1" or data=="resume" or data=="play":
+        if playbackstate==2:
             player.pause()
+        elif playbackstate!=1:
+            player.play()
     elif data=="2" or data=="pause":
-        if player.isPlaying():
+    	if playbackstate==1:
+            player.pause()
+    elif data=="toggle":
+    	if playbackstate==1 or playbackstate==2:
             player.pause()
     elif data=="next":
         player.playnext()
-- 
GitLab