diff --git a/.gitignore b/.gitignore index cb11dad..2e60b56 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ kodi2mqtt_addon.zip + +.idea/ diff --git a/README.md b/README.md index 4af3ee5..2561320 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ The addon listens to the following topics (prefixed with the configured topic pr a popup notification in Kodi * command/play: Either a simple string which is a filename or URL, or a JSON encoded object which correspondents to the Player.Open() JSON_RPC call +* command/volume: Set the volume to value or or a JSON encoded object which correspondents + to the Application.SetVolume() JSON_RPC call * command/playbackstate: A simple string or numeric with the values: - "0" or "stop" to stop playback - "1" or "resume" or "play" to resume playback (when paused or stopped) diff --git a/service.mqtt/addon.xml b/service.mqtt/addon.xml index 370a461..b5c2056 100644 --- a/service.mqtt/addon.xml +++ b/service.mqtt/addon.xml @@ -1,5 +1,5 @@ - + diff --git a/service.mqtt/changelog.txt b/service.mqtt/changelog.txt index b00bfa5..93c1906 100644 --- a/service.mqtt/changelog.txt +++ b/service.mqtt/changelog.txt @@ -1,3 +1,6 @@ +v0.14 -2019-10-26 - devtown + - added set volume + v0.13 - 2016-05-01 - owagner - change logic for command/playbackstate: - resume/play/1 will now properly resume when pausing, and attempt to diff --git a/service.mqtt/service.py b/service.mqtt/service.py index af4cd2d..1b0ff60 100644 --- a/service.mqtt/service.py +++ b/service.mqtt/service.py @@ -46,6 +46,11 @@ def sendrpc(method,params): mqttlogging("MQTT: JSON-RPC call "+method+" returned "+res) return json.loads(res) +def setvol(data): + params=json.loads('{"volume":' + str(data) + '}') + sendrpc("Application.SetVolume",params) + #res=xbmc.executebuiltin("XBMC.SetVolume("+data+")") + xbmc.log(data) # # Publishes a MQTT message. The topic is built from the configured # topic prefix and the suffix. The message itself is JSON encoded, @@ -186,6 +191,15 @@ def processplay(data): except ValueError: player.play(data) +def processvolume(data): + try: + vol = int(data) + setvol(vol) + except ValueError: + params=json.loads(data) + sendrpc("Application.SetVolume",params) + + def processplaybackstate(data): global playbackstate if data=="0" or data=="stop": @@ -206,6 +220,14 @@ def processplaybackstate(data): elif data=="previous": player.playprevious() +def processsendcomand(data): + try: + cmd=json.loads(data) + res=xbmc.executeJSONRPC(json.dumps(cmd)) + mqttlogging("MQTT: JSON-RPC call "+cmd['method']+" returned "+res) + except ValueError: + mqttlogging("MQTT: JSON-RPC call ValueError") + def processcommand(topic,data): if topic=="notify": processnotify(data) @@ -213,6 +235,10 @@ def processcommand(topic,data): processplay(data) elif topic=="playbackstate": processplaybackstate(data) + elif topic=="api": + processsendcomand(data) + elif topic=="volume": + processvolume(data) else: mqttlogging("MQTT: Unknown command "+topic) @@ -232,6 +258,7 @@ def msghandler(mqc,userdata,msg): def connecthandler(mqc,userdata,rc): mqttlogging("MQTT: Connected to MQTT broker with rc=%d" % (rc)) + mqc.publish(topic+"connected",2,qos=1,retain=True) mqc.subscribe(topic+"command/#",qos=0) def disconnecthandler(mqc,userdata,rc): @@ -276,7 +303,6 @@ def startmqtt(): else: mqttlogging("MQTT: No connection possible, giving up") return(False) - mqc.publish(topic+"connected",2,qos=1,retain=True) mqc.loop_start() return(True)