cmvac / demagorgon.repository

Demagorgon Kodi Addons Repository
GNU General Public License v2.0
6 stars 4 forks source link

HyperionOn + HyperionOff = ToggleHyperion #2

Open humdingerb opened 6 years ago

humdingerb commented 6 years ago

It would be nice to have one addon "ToggleHyperion" instead of one for on, one for off. You could check with "ps | grep hyperiond". If there's only one line printed, hyperion is off.

cmvac commented 6 years ago

I am taking care of that while planning for version 2.0 of the Toggle addon. Still have to find out a couple of things, including how to do the same with the effects.

It would also be cool to have a colour selection tool, but that would have to wait for version 3.0, I think.

I wish this would gain more traction with the Hyperion community, maybe someone could help me fill in the holes.

humdingerb commented 6 years ago

I have no experience with Python, but am interested in my new ambilight. :) I'll have to use it for a bit to see what itches I have to scratch first. Quick toggling is my number one.

humdingerb commented 6 years ago

I had a look at the toggling, and trawling the net to learn the basics of python syntax and looked for examples. I'm almost there, but it's still not working:

import xbmcaddon
import xbmcgui
import os
import commands

output = commands.getoutput('ps | grep -c hyperiond')

if (output == 1):
        cmd     = "/storage/hyperion/bin/hyperiond.sh /storage/.config/hyperion.config.json </dev/null >/dev/null 2>&1 &"
        line    = "Lights On"
else:
        cmd     = "killall hyperiond"
        line    = "Lights Off"

os.system(cmd)
xbmc.executebuiltin('Notification(Hyperion,%s,2000)' % line)

The problem is: it always says the output == 2 . Even if in the shell the "ps | grep" command definitely says "1" when hyperiond isn't running, and "3" when it is! Consequently, the "else" block of the condition gets always executed... Any ideas?

humdingerb commented 6 years ago

Now it's working. My "if" condition was bad... Also, removing grep from the equasion with "grep -v grep". Feel free to adopt, adept and improve, and use.

import xbmcaddon
import xbmcgui
import os
import commands

output = commands.getoutput('ps | grep -v grep | grep -c hyperiond')

if output[0] == "0":
        cmd     = "/storage/hyperion/bin/hyperiond.sh /storage/.config/hyperion.config.json </dev/null >/dev/null 2>&1 &"
        line    = "Lights On"
else:
        cmd     = "killall hyperiond"
        line    = "Lights Off"

os.system(cmd)
xbmc.executebuiltin('Notification(Hyperion,%s,2000)' % line)
cmvac commented 6 years ago

Humdingerb, thanks for your help! It works with LibreELEC and OpenELEC with that code, but in Raspbian we get the same error.

ps | grep -v grep | grep -c hyperiond

--> it is always displaying 0, so the LEDs turns on, but never off.

Any idea on how to get this to work on Raspbian?

humdingerb commented 6 years ago

I only run Kodi through LibreElec, but I ssh'ed into raspbian quickly, and it seems like the "ps" has to be amended with "-A" to show all processes. Try: ps -A | grep -v grep | grep -c hyperiond

cmvac commented 6 years ago

I tried to implement that line but it still not working. It does not turn on/off. I am trying to fuse all of these addons into one, but have a lot of reading to do, and there is not a lot of information about it as well.

The idea would be On/Off, another menu for toggle, and also effects and colors. But first I am trying to put On/Off/Toggle into one. Maybe you can help, seems like you know more about this than me :P

humdingerb commented 6 years ago

FWIW, my toggle plugin works like a charm (on LibreElec), download and compare here: https://0x0.st/sAA3.zip

So you want to combine 3 addons, On / Off / Toggle into one? I guess that one addon should put up an alert with 3 buttons then. I know nothing of that yet, but will have to read up on it, too. I can try looking into it this weekend. Can't be that difficult...

humdingerb commented 6 years ago

A bit more difficult than I thought... :) I'm not really sure what class should be used. xbmcgui.Window? xbmcgui.WindowDialog? xbmcgui.Dialog? Could I use a text dialog and just add three buttons...?

Anyway, I got it somewhat running, though the GUI isn't quite right: It's not really a window as expected, WindowDialog doesn't look much better, the three buttons and the label don't look too nice either. You have to fiddle around with the x/y/width/height parameters of the buttons.

Anyway, maybe it can get you going. I probably won't look into it much further for now, as I don't really see the use of having a on/off/toggle plugin, if the simple "toggle" is perfectly sufficient (to me).

I uploaded the plugin at https://0x0.st/sAfM.zip

This is the code so far:

import xbmcaddon
import xbmcgui
import os
import commands

#Pretty much exactly as described at https://kodi.wiki/view/HOW-TO:Write_python_scripts#Window

class MyClass(xbmcgui.WindowDialog):
  def __init__(self):
    self.strActionInfo = xbmcgui.ControlLabel(100, 120, 200, 30, '', 'font13', '0xFFFF00FF')
    self.addControl(self.strActionInfo)
    self.strActionInfo.setLabel('Hyperion Control')
    self.button0 = xbmcgui.ControlButton(250, 100, 180, 30, "Toggle On/Off")
    self.addControl(self.button0)
    self.button1 = xbmcgui.ControlButton(450, 100, 180, 30, "On")
    self.addControl(self.button1)
    self.button2 = xbmcgui.ControlButton(650, 100, 180, 30, "Off")
    self.addControl(self.button2)
    self.setFocus(self.button0)

    self.button0.controlRight(self.button1)
    self.button0.controlLeft(self.button2)
    self.button1.controlRight(self.button2)
    self.button1.controlLeft(self.button0)
    self.button2.controlRight(self.button0)
    self.button2.controlLeft(self.button1)

  def onControl(self, control):
    if control == self.button0:
      output = commands.getoutput('ps -A | grep -v grep | grep -c hyperiond')                           
      if output[0] == "0":
        cmd     = "/storage/hyperion/bin/hyperiond.sh /storage/.config/hyperion.config.json </dev/null >/dev/null 2>&1 &"
        line    = "Lights On"
      else:
        cmd     = "killall hyperiond"
        line    = "Lights Off"
    if control == self.button1:
      cmd     = "/storage/hyperion/bin/hyperiond.sh /storage/.config/hyperion.config.json </dev/null >/dev/null 2>&1 &"
      line    = "Lights On"
    if control == self.button2:
      cmd     = "killall hyperiond"
      line    = "Lights Off"
    os.system(cmd)
    xbmc.executebuiltin('Notification(Hyperion,%s,2000)' % line)

mydisplay = MyClass()
mydisplay .doModal()
del mydisplay