20 Nov 2019 - TVDB Scraper v3.2.0 is now available which reinstates scraping. TVDB are still in the process of fixing a number of bugs so there may still be further breakages. See this post. 2901570 (post)

Communication between service and plugin

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.
i would use window properties..
2524839 (post)
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.
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
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:
        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:
class MyMonitor(xbmc.Monitor):

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

        if sender == addon_id:
           command_info = json.loads(data)
My repository: repository.vlmaksime
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
Thread Rating:
  • 0 Vote(s) - 0 Average

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