How do Addon script and settings.xml communicate?
#1
I'm trying to build an addon that controls a case fan for raspberry pi 4.

I need to open a .conf file, read line by line, associate lines to values(line1=temp1,line2=speed1,...) then set those values to be controlled by setting type=number in settings.xml.

So at the moment I'm trying to understand how an addon script communicates with the settings.xml file.
I can open the file and set each line as a reference to be used later.
I just don't know where to start to have that work in conjunction with my settings.xml code.

This is the code in settings.xml:
Code:

<setting label="start temp" type="number" id="temp1" default="30"/>
<setting label="start fan speed" type="number" id="speed1" default="25" subsetting="true"/>

The addon.py:

file = 'C:\\Users\\Joe\\AppData\\Roaming\\Kodi\\addons\\script.hellotestwindow\\resources\\test.conf'

Code:

class Main:
    # constructor of Main class

    def __init__(self):
        # Initialization of the Strings
        with open(file) as f:
            lines = [line.rstrip('\n') for line in f]
            self.lines = lines
    
    def set_setting(self):
        ?? ?? ?? ??

if __name__ == '__main__':
    Main().set_setting()


does anyone know how to do this?
Or at least where to start?

Anything about anything would help, I have absolutely no idea what to search.
I did find a kodi docs website, that showed options like:

Code:
XBMCAddon::xbmcplugin::getSetting (int handle, const char *id)
XBMCAddon::xbmcplugin:: setSetting (int handle, const String &id, const String &value)

But I don't know how they work, or if it's even the correct code to use.

Any help would be GREATLY APPRECIATED
thank you
Reply
#2
I think I just got it.

The magic code is(depending on what type of content you're dealing with or doing(setting/getting):
Code:
.getSettingString ​
.setSettingInt
​.getSettingBool
​.setSettingBool ​
.getSettingNumber

Example code for addon.py:
(settemp1 and setspeed1 are the values the user changed(as a string or default as an integer?) in settings.xml)

Code:
__addon_id__ = 'script.hellotestwindow'
__Addon = xbmcaddon.Addon(__addon_id__)

​ ​def getSettingInt(name):
return __Addon.getSettingInt(name) ​ ​

def settings(self):
settemp1 = utils.getSettingInt('temp1')     
setspeed1 = utils.getSettingString('speed1')

Corresponding example settingsxml:

Code:
<setting label="start temp" type="number" id="settemp1" default="30"/>
<setting label="start fan speed" type="number" id="setspeed1" default="25"/>

IF I'M WRONG ON THIS, please let me know =/

I am literally throwing code at this until it works lol

Now all I have to do is take that user input value, and save it into the location.
I think... lol
Reply
#3
Yes, kodi provides xbmcaddon module you can import.  That gives access to the Addon class and for Kodi 20 the Settings class.  Note there is new syntax for settings.xml  see Add-on_settings_conversion (wiki)

scott s.
.
Reply

Logout Mark Read Team Forum Stats Members Help
How do Addon script and settings.xml communicate?0