Still failing to understand Addon Development

  • I finally completed a basic setup of the addon I'm trying to create.

    Example Files for background info:

    Settings.xml:

    Code
    <settings>
    <category label="Dependencies">
    <setting label="30003" type="lsep"/>
    <setting label="30000" type="action" action="RunScript($CWD/resources/scripts/install_pyserial.py)"/>

    script file:

    This is pretty much how everything runs at the moment, because I have no idea how to do this and thought this would be the simplest:

    I have scripts(setfan_100.py, deskpi_installer.sh) that are set as the scripts for the buttons themselves inside the settings page of my addon.

    When a user clicks the button, an action happens(ie install a dependency for the installer, install the installer, set fan speed.)

    And I got all of that to work, with a lot of libreelec forum help.

    I'm just stuck on the last hurdle, making a real addon. lol

    The problem I'm running into is I'm installing a fan service which needs the ability for users to change fan speeds and temp ranges.

    Essentially I need to get 2 sets of 4 values for fan speed and temp ranges. These values are saved into a .conf file (located OUTSIDE the addon in /storage/user/bin/)

    (The installer for this file and the service is here, if you want to check it out to understand how it all works. But I would assume it's pretty basic for this sort of thing.)

    The fan is controlled via serial ttyUSB0. So sending basic code("pwm_050") into /dev/ttyUSB0 will control the 'constant' value of the fan speed.

    Traditionally the fan is configured through a bash configuration tool(read -p, echo $value into file) to allow the user to set custom fan speed and temp ranges.

    After configuration the .conf looks like this:

    30

    25

    35

    50

    40

    75

    45

    100

    How the service works with those inputs:

    if cpu_temp < 30:

    ser.write(b'pwm_000')

    elif cpu_temp > 30 and cpu_temp < 35:

    ser.write(b'pwm_025')

    elif cpu_temp > 35 and cpu_temp < 40:

    ser.write(b'pwm_050')

    elif cpu_temp > 45 and cpu_temp < 50:

    ser.write(b'pwm_075')

    elif cpu_temp > 50:

    ser.write(b'pwm_100')

    So essentially my idea of creating a SUPER BASIC ADDON, that does things in the old skool skript kiddy way. Won't work lol

    So I've been trying to understand how to do things correctly, so I can pass arguments/user inputs into the file from the settings page.

    I know I need to set the extension point in the addon.xml to the main script.

    The script the addon calls is(addon.py):

    # Module: default

    # Author: jojobrogess

    from resources.utils import script

    if __name__ == '__main__':

    script().test()

    That imports a python file(located in script.testwindow/resources/utils.py and starts the class that's called "script")

    which is something like this:

    Python
    import sys
    import xbmc
    import xbmcaddon
    
    class script():
        def __init__(self):

    Which you then use something like this in the settings.xml to call a DEF that's inside the file above:

    Code
    <setting label="start temp" type="number" id="defcode1" default="40"/>

    Runscript() would then be done correctly by doing something like this:

    Code
    <setting label="$ADDON[script.testwindow 30000]" type="action" action="RunScript(script.testwindow,DEF)" option="" />


    But I'm lost on the whole addon.py to utils.py file class:script DEF coding. I don't even know how to type it, that is how far out of my element I am right now.

    Traditionally speaking when I don't understand how something works, I can search up components of the code and slowly piece it together.

    But this is just beyond my understanding.

    I don't understand the syntax/function for the class and def code.

    Or even what that's called. A python function?

    Does anyone have any wiki's or SIMPLE examples for an idiot? lol

    Googling python syntax to understand this better is proving to be difficult

    So I've been trying to use:

    Add-on development - Official Kodi Wiki

    Addon.xml - Official Kodi Wiki

    Add-on settings - Official Kodi Wiki

    HOW-TO:Script addon - Official Kodi Wiki

    As well as opening the kodi addon directory in ST3 so I can scan all my addons for terms to see how others coded.

    But everything seems very specific(or in Kidiwiki case, out of date/old) and I can't seem to understand enough of it to write anything, that works.

    I tried to make a super basic test function, open a notification window, but it doesn't work:

    Code
    <setting label="newtest" type="action" action="RunScript(script.testwindow,test)" option="" />
    <setting label="newtest2" type="action" action="RunScript(script.testwindow,test)"/>

    With every change of code, I get a new error lol and seemingly further from figuring this out.

    I really wish there was more information for the bottom feeders like me who don't really know how to code, so I don't have to come in here and bother people probably doing real stuff lol

    DOES ANYONE HAVE ANY super simple example code? Or anything that could point in the right direction?

  • So I've gotten a little more understanding of what's actually going on inside the addon python file and have been somewhat able to create a "working" file. Right now I can open a file, read/set lines(INSIDE pycharm python)

    But I am failing to understand how the settings.xml and the addon python file communicate.

    This is what I have written so far:

    **Right now I am testing the code on my windows machine, through kodi(since its a billion times easier for me to check logs and change code). I doubt that should change anything in this case, as this part of the code, I don't think, has anything specifically libreelec.

    I just need to open a .conf file, read line by line, use reference code of lines inside settings page of addon so user can change temp/fan speeds for a serial case fan(which is libreelec specific).

    The code in my settings.xml:

    Code
    <setting label="First Tempurature/Speed Threshold" type="lsep"/>
    <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:


    I DO NOT think I'm doing any of this correctly but especially the last part, the DEF open and DEF set_value.

    How do I "link" the lines read out from a file to the settings id?

    I was looking on codedocs and saw this, which looks to be what is needed. But I can't read it.

    And google isn't liking my crazy specific search terms anymore..

    XBMCAddon::xbmcplugin::getSetting (int handle, const char *id)

    XBMCAddon::xbmcplugin::setSetting (int handle, const String &id, const String &value)


    How do these work?

    IS it:

    XBMCADDON = The AddonID?(script.hellotestwindow)

    xbmcplugin = Script name inside addon?(addon.py)

    get/setSetting = The setting I am getting/setting(temp1 speed1...)

    so:

    script.hellotestwindow.'addon.py'.temp1()

    And then the () has the args for the get/setSetting ?

    And is that what is needed for me to associate the readlines from the file as settings id ?

    Or am I doing this all wrong?

    As always, any type of help is greatly appreciated.

  • Okay so I cleaned up my code a lot to streamline it so I can understand it better:

    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:

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

    does anyone know how to do this?

    The values (temp1,speed1,...) represent lines in a file that need to be displayed/changed from within the settings page of an addon.

  • Ahh crap 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 I just have to figure out how to write those user input values into that .conf file.

  • OKAY, so I figured it all somewhat out. I can now do what I was trying to do with this:


    I would assume there is a more dynamic way of doing this, but I don't know how to do that.lol

    Plus ATM when a value is changed within the settings page, the addon needs to be ran after for the settings to be saved within the file.

    Does anyone know of a way for the settings page to "run" the addon?

    The extension point for my addon is xbmc.python.script, should I be using plugin?

    Did I just write my addon incorrectly? and the functions need to be OUTSIDE the class for it to work the way I want? Or something similar.