I finally completed a basic setup of the addon I'm trying to create.
Example Files for background info:
Settings.xml:
<settings>
<category label="Dependencies">
<setting label="30003" type="lsep"/>
<setting label="30000" type="action" action="RunScript($CWD/resources/scripts/install_pyserial.py)"/>
script file:
import os
import xbmc
import xbmcaddon
__addon__ = xbmcaddon.Addon('script.hellotestwindow')
__addonname__ = __addon__.getAddonInfo('name')
__icon__ = __addon__.getAddonInfo('icon')
line1 = "Pyserial Installer Has Started\n"
line2 = "Please continue on..."
time = 5000 #in miliseconds
os.system('cp /storage/.kodi/addons/script.hellotestwindow/resources/lib/pyserial_installer.sh /storage/')
os.system('sh /storage/pyserial_installer.sh')
xbmc.executebuiltin('Notification(%s, %s, %d, %s)'%(__addonname__,line1+line2, time, __icon__))
Display More
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:
Which you then use something like this in the settings.xml to call a DEF that's inside the file above:
Runscript() would then be done correctly by doing something like this:
<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:
import sys
import xbmc
import xbmcaddon
class script():
def __init__(self):
def test(self):
__addon__ = xbmcaddon.Addon('script.testwindow')
__addonname__ = __addon__.getAddonInfo('name')
__icon__ = __addon__.getAddonInfo('icon')
line1 = "TEST NOTIFICATION WORKED"
time = 5000 #in miliseconds
self.xbmc.executebuiltin('Notification(%s, %s, %d, %s)'%(__addonname__,line1, time, __icon__))
Display More
<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?