Communication between service and plugin
#1
Hi,

My script primarily runs as a service, waiting for OnAvStarted, etc events to manage Hue lights. I'm looking for a way to provide users with easy manual control / shortcuts to force those same events to happen.

So far I've added a plug-in extension to create a menu of commands and those can easily be added to favourites so it seems like a good way to make shortcuts - but I'm open to other ideas.

What I'm wondering is what is the best way to pass the command from the plugin script to the running service script. I'm a python & kodi newbie so although I can figure out ways to do it, what would you guys recommend as best practice?

I don't want to import the relevant parts of the service since initializing the service and connection to the Hue hub would take too long. Considering there's only 6 commands with no data or parameters, an sqllite command queue in addon_data seems like overkill. I suppose I could write a text/data file but that seems sketchy

I'm probably not the first with this need - is there a best practice or suggestions? Considering the original need is just to create shortcuts to trigger service actions, the ideas I've come up with seem overengineered for the need.
Reply
#2
i would use window properties..
https://forum.kodi.tv/showthread.php?tid...pid2524839
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#3
Thanks for pointing me to that thread, looks like it will do what I need easily from first quick look. Never would have thought to look at xbmcgui for this Smile
Reply
#4
I'm using 'JSONRPC.NotifyAll' method in script to send command to service and onNotification() method of Monitor class to get command in service.
Script example:
python:
        params = {'sender': addon_id,
                  'message': message,
                  'data': {'command': 'command_name',
                               'command_params': {'foo': 'bar'}
                               },
                  }

        command = json.dumps({'jsonrpc': '2.0',
                              'method': 'JSONRPC.NotifyAll',
                              'params': params,
                              'id': 1,
                              })
        result = xbmc.executeJSONRPC(command)

Service example:
python:
class MyMonitor(xbmc.Monitor):

    def onNotification(self, sender, method, data):

        if sender == addon_id:
           command_info = json.loads(data)
My addons: Gismeteo
Reply
#5
Ah! I saw those methods but thought they were for GUI notifications. I ended up using simplecache but it's good to know about these other options
Reply

Logout Mark Read Team Forum Stats Members Help
Communication between service and plugin0