OnkyoISCP plugin

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
User avatar
kgschlosser
Site Admin
Posts: 5498
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: OnkyoISCP plugin

Post by kgschlosser » Sat May 06, 2017 3:20 pm

wasn't sure if it needed to have the whole command converted to hex. My AVR uses hex but you convert string commands to hex and bit shift the beginning and end of it with a checksum . Mine isn't an onkyo but a lot of them seem to have goofy things like that. so i wasn't sure if it would be helpful or not or just informational
If you like the work I have been doing then feel free to Image

justahotbag2
Experienced User
Posts: 68
Joined: Fri Jan 27, 2017 8:16 pm
Location: New York, NY

Re: OnkyoISCP plugin

Post by justahotbag2 » Sat May 06, 2017 3:54 pm

kgschlosser... clearly you must be a good dancer, I see you all over the site. :) I barely have any idea what you just tap danced out, but I hope to understand one day soon. However, you bring up commands, and I'm wondering if a one line python command is in any way, leaner than a two line script, which is the only way I can seem to get the conversion, the first drops the (hex) payload into a variable and the second converts and prints. I still have yet to get this to display with the snarl plugin, but I will. Also I remember reading somewhere; does using a capital letter automatically make it a global variable? How long are variables held in memory, 'till reboot? Thanks to whomever answers.

WoLpH
Experienced User
Posts: 96
Joined: Mon Dec 10, 2012 3:57 am

Re: OnkyoISCP plugin

Post by WoLpH » Sat May 06, 2017 4:16 pm

Variables are global is they are declared outside of functions/classes/etc.
If you want to use global variables inside of a function you can use the global statement. Without it you can read global variables but not write them.

The name of the variable has no influence. The exception to this is the use of variables within a class that are prefixed with 2 underscores, those are private. Personable I recommend against their usage since it usually just complicates things with little benefit.
Author of the book Mastering Python. Got Python questions? Perhaps I can help :)

User avatar
kgschlosser
Site Admin
Posts: 5498
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: OnkyoISCP plugin

Post by kgschlosser » Sat May 06, 2017 5:52 pm

ok when setting a global variable in EG use eg.globals and use whatever name makes you happy. For the sake of stating how eventghost sets variables. it is usually lowercase variable name if single word. if 2 words lowercase first letter upper case second no spaces or underscores. the things that have a capital first letter are either an uninitialized class or a method/function.

Now in the case of constant variables. variables that have data that never changes. it is all uppercase if one word. and all uppercase separated by an _ if 2 words

this is going to be a little tricky to explain.

there is a global container for all of python
and there is a global container called eg.globals

they are not the same.
when you use global variable_name it creates a variable in the python global container


the reason I state to use eg.globals is because if you set a global in a PythonScript using the command global variable_name it goes no further then that PythonScript.

this happens because when a script gets run dynamically there is an option to specify if you want to use the python container or some other container for the global container and i believe in the case of the PythonScript the other container is used so using the global command it will place that variable in that other container. which after the script terminates vanishes.

now the reason why you can access eg.globals even tho the container is not the python globals is because the module "eg" has been added to the builtin functions of the python. hence the reason why i tell you to use that. because after the script terminates you can access the information in it.

so as an example for the variable names

Code: Select all


someVariable = 'Hi'

def SomeFunction():
    pass

AnotherFunction = SomeFunction

class Test:
    def DoTest(self):
        pass

test = Test()

test.DoTest()

CONSTANT = "constant"
ANOTHER_CONSTANT = "another constant"
if you wanted to make any of them globals you would add eg.globals. in front of it.. except the function/class you do this after you have coded the function/class

Code: Select all


def SomeFunction():
    pass

eg.globals.SomeFunction = SomeFunction

class SomeClass:
    def SomeMethod(self):
        pass

eg.globals.SomeClass = SomeClass

again in the case of using global in a PythonScript I would have to recheck the code to make sure.
K

**EDIT**

sorry don't know where was brain was.. Let me clarify the python global container. i used an incorrect statement.. the python container is not "all" of python. it is for that module or in the case of PythonScripts only for that script.

if I am wrong on this (which I probably am) please someone provide the correct information.
If you like the work I have been doing then feel free to Image

justahotbag2
Experienced User
Posts: 68
Joined: Fri Jan 27, 2017 8:16 pm
Location: New York, NY

Re: OnkyoISCP plugin

Post by justahotbag2 » Sun May 07, 2017 3:20 pm

Wooh! Ask, and you shall receive. WoLpH thanks very concise. :) / kgschlosser :shock: you've yank me from the hallway into 101, challenge accepted. :)

WoLpH
Experienced User
Posts: 96
Joined: Mon Dec 10, 2012 3:57 am

Re: OnkyoISCP plugin

Post by WoLpH » Sun May 07, 2017 3:54 pm

I typed that one from my phone, so here's a version with a bit of code to illustrate:

Code: Select all

some_global = 123

# This works:
def some_function():
    print('some global: ', some_global)

# This doesn't because you're trying to use a non-existing local variable called some_global
def some_not_working_function():
    some_global += 10

# This does work
def some_working_function_with_globals():
    global some_global
    some_global += 10
Author of the book Mastering Python. Got Python questions? Perhaps I can help :)

User avatar
kgschlosser
Site Admin
Posts: 5498
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: OnkyoISCP plugin

Post by kgschlosser » Mon May 08, 2017 2:28 am

I just want to make sure there is crystal clarification on this. because not everyone knows python and actually what a global is.. they think of eg.globals.

they are not the same!!.

maybe Wolf can assess my understanding of how it works. but this is how i interpreted what i have read

A global is a variable/function/class that can be declared or created at the base level.. meaning not inside of a def or a class. now you can read these variables from anywhere in the code doesn't matter if you are inside of a def or a class but you are not able to write to it.. unless you put global and the name of the variable on the line before where you are trying to write new information. Tho i have never tested if a global is available throughout EG, i do not believe it is, That is why there was a container made to house this information eg.globals. personally when scripting i just use eg.globals and save the actual global variables for constants
If you like the work I have been doing then feel free to Image

WoLpH
Experienced User
Posts: 96
Joined: Mon Dec 10, 2012 3:57 am

Re: OnkyoISCP plugin

Post by WoLpH » Mon May 08, 2017 7:12 am

Yes indeed. When it comes to EventGhost listen to the amazing answers by kgschlosser :)

Thanks for your awesome work!
Author of the book Mastering Python. Got Python questions? Perhaps I can help :)

User avatar
kgschlosser
Site Admin
Posts: 5498
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: OnkyoISCP plugin

Post by kgschlosser » Mon May 08, 2017 2:12 pm

don't thank me. this is a community effort. I am a small piece. And.. I am very much still learning python and what it can do. Tho I really do need to chat with someone that knows about kernel mode drivers, well drivers in general and the Microsoft signing process.

But if there is something you want to know about the EventGhost API then ask away. I think I have gone through almost all of the core code so I am pretty good at answering questions about EG specific things. but Python in general... I am learning every day.
If you like the work I have been doing then feel free to Image

justahotbag2
Experienced User
Posts: 68
Joined: Fri Jan 27, 2017 8:16 pm
Location: New York, NY

Re: OnkyoISCP plugin

Post by justahotbag2 » Mon May 22, 2017 5:26 pm

kgschlosser wrote:don't thank me. this is a community effort..
I'll thank you, if I want! and I will...

But staying on Topic
Does anyone around here know how to separate out the "double post" this plugin puts out for the vol?
Is it a Regex solution? would that even work?

It spits out this
OnkyoISCP.MVL '32'
&
OnkyoISCP.MVL32
one after another, so my tiny script reacts twice, also double posting to snarl.

WoLpH
Experienced User
Posts: 96
Joined: Mon Dec 10, 2012 3:57 am

Re: OnkyoISCP plugin

Post by WoLpH » Mon May 22, 2017 10:12 pm

The reason for that is that you might wish your code to respond to any volume change (i.e. MVL) or simply to a specific volume only (i.e. MVL32). It's probably a design decision made by my predecessor a long time ago so I'm a bit worried about changing it (it could break people's scripts) but I probably could.

Having that said, the MVL event shouldn't trigger the MVL32 event and vice versa so I'm not entirely sure why you're getting this.
Author of the book Mastering Python. Got Python questions? Perhaps I can help :)

justahotbag2
Experienced User
Posts: 68
Joined: Fri Jan 27, 2017 8:16 pm
Location: New York, NY

Re: OnkyoISCP plugin

Post by justahotbag2 » Tue May 23, 2017 6:56 pm

You'd think they would be different 'events', and only one having a payload, yes?
But alas, using MVL alone, responds twice picking both up with payloads, perhaps that shouldn't be happening, and wouldn't break anyone's scripts, looking for a specific volume level. Of course, I also don't know what I'm talking about. So reading what I just typed, actually just wasted your time, and I'm sorry for that.

Can you tell me if some kind of Regex formula is likely to solve this? Apparently MVL '**' is not it. :oops:

WoLpH
Experienced User
Posts: 96
Joined: Mon Dec 10, 2012 3:57 am

Re: OnkyoISCP plugin

Post by WoLpH » Tue May 23, 2017 10:02 pm

Yes, that's exactly what it's supposed to do.
I've actually done a little test and that's what happens for me:
Image

As you can see, it's only triggering the volume changed event when it's actually changing (I pressed the button twice in the screenshot above).
Author of the book Mastering Python. Got Python questions? Perhaps I can help :)

justahotbag2
Experienced User
Posts: 68
Joined: Fri Jan 27, 2017 8:16 pm
Location: New York, NY

Re: OnkyoISCP plugin

Post by justahotbag2 » Wed May 24, 2017 4:23 pm

You are correct Sir, and I am not. Apparently I did not know how to use the Snarl Plugin as well as I thought I did, another set back in courage. But alas, I have "fixed" it by trimming out the OSD I had in place for years 'till I recently got this more useful display, plus I now have the small additional benefit of it acting like a confirmation, that the receiver actually responded, as opposed to a conformation that I pressed the button. So, apparently I (...or my EG tree) might be one ant-step smarter than yesterday. Thanks buddy, sometimes you can help someone by exposing how dumb they are. i.e. "see you're problem here is, that you're stupid."

I also just happened to notice, that you are now the lead programmer on this plugin, I thought you were just some random happy & helpful drunk, the type that tells you that your car starter is bad, by the sound of it. That said, this plugin has brought so much "cool" factor to my life, i.e. in conjunction with the android app I have my receiver turn itself down the instant I answer a phone call (I have my fingers crossed that that little trick, is going to get me laid one day; at least get the string off one hip) now with that said, you feel like a friend of mine and so I'd like to call you WoLpHie...

No?.. No Bueno?..
How about in the privacy of my mind?.. Even worse?..

User avatar
kgschlosser
Site Admin
Posts: 5498
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: OnkyoISCP plugin

Post by kgschlosser » Wed May 24, 2017 5:20 pm

only one reply to that WOW
If you like the work I have been doing then feel free to Image

Post Reply