Page 1 of 1

webserver plugin and eg.event.payload

Posted: Thu Apr 19, 2012 6:03 pm
by holle75
Hi there,

i┬┤m sending my href in the format "http://192.168.1.39/index.html?HTTPMasterVolume&11&0" to EG┬┤s webserver.
the purpose is to trigger the Master Volume in a Python Script with

Code: Select all

eg.WinApi.SoundMixer.SetMasterVolume(eg.event.payload)
the result is an error

Code: Select all

Traceback (most recent call last):
Python script "64", line 1, in <module>
eg.WinApi.SoundMixer.SetMasterVolume(eg.event.payload)
File "C:\Programme\EventGhost\eg\WinApi\SoundMixer.py", line 201, in SetMasterVolume
newValue = int((value / 100.0) * (maximum - minimum)) + minimum
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

when i print (eg.event.payload) with

Code: Select all

print (eg.event.payload)
the result in the log is

Code: Select all

[u'11', u'0']
As EG┬┤s webserver supposedly is expecting

Code: Select all

eg.WinApi.SoundMixer.SetMasterVolume(x.0, 0)
and eg.event.payload comes with [u'11', u'0'] this error makes sense to me.

The question is: how could i get rid of the u' in the payload?

Thank you for any hints

best

H.

EDIT:

i could manage to strip down [u'11', u'0'] to 11 with

Code: Select all

str = eg.event.payload
print str
vol = str[0]
print vol
eg.plugins.System.SetMasterVolume((vol), 0)
but still its not working :(

EDIT2:
Ok, i managed it by myself. I had to convert from unicode. i┬┤m shure there is a nicer way but due my lack of knowledge of Python i have to go step by step ;)

Code: Select all

str = eg.event.payload
vol = str[0]
mastervolnew = float(vol)
print "New MasterVolume = ", mastervolnew
eg.plugins.System.SetMasterVolume(mastervolnew, 0)

Re: webserver plugin and eg.event.payload

Posted: Tue Apr 24, 2012 6:27 pm
by cfull1
Looks like you got it. It could combined to this

Code: Select all

eg.plugins.System.SetMasterVolume(float(eg.event.payload[0]), 0)
Didn't realize you had switched to System.SetMasterVolume until after I came up with this ha.

Re: webserver plugin and eg.event.payload

Posted: Tue Apr 24, 2012 6:57 pm
by holle75
Hi cfull1 .... Your single line looks much nicer. I┬┤m still afraid to pack things together.

thank you

best

H.