Giter VIP home page Giter VIP logo

Comments (9)

cmvac avatar cmvac commented on July 21, 2024

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.

from demagorgon.repository.

humdingerb avatar humdingerb commented on July 21, 2024

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.

from demagorgon.repository.

humdingerb avatar humdingerb commented on July 21, 2024

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?

from demagorgon.repository.

humdingerb avatar humdingerb commented on July 21, 2024

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)

from demagorgon.repository.

cmvac avatar cmvac commented on July 21, 2024

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?

from demagorgon.repository.

humdingerb avatar humdingerb commented on July 21, 2024

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

from demagorgon.repository.

cmvac avatar cmvac commented on July 21, 2024

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

from demagorgon.repository.

humdingerb avatar humdingerb commented on July 21, 2024

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...

from demagorgon.repository.

humdingerb avatar humdingerb commented on July 21, 2024

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

from demagorgon.repository.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.