Re: TellStick Duo
Posted: Sun Feb 16, 2014 4:31 pm
I will test this as soon as possible. Probably in the begining of this week. Thank you!
Code: Select all
eg.plugins.TellStickDuo.Dim(u'ALL_LIGHTS', 50)
Code: Select all
eg.plugins.TellStickDuo.DimPercentage(u'ALL_LIGHTS', True, 50)Code: Select all
print eg.plugins.TellStickDuo.DimPercentage(u'ALL_LIGHTS', True, 0)
dct = eg.plugins.TellStickDuo.DimPercentage(u'ALL_LIGHTS', True, 0)
for i in dct:
print i, dct[i]
Code: Select all
def loadLibrary(dll):
print "Loading library"
try:
dll = windll.LoadLibrary("TelldusCore.dll")
except:
raise eg.Exception('Could not load dll')
dll.tdInit()
return dll
def closeLibrary(dll):
try:
dll.tdClose()
print "Closing library"
except:
pass
dll = None
return dll
from ctypes import(
windll, WINFUNCTYPE, POINTER, string_at,
wstring_at, c_char_p, c_int, c_ubyte, c_void_p
)
#Device methods
TELLSTICK_DIM = 16
dll = None
dll = loadLibrary(dll)
deviceList = {}
numdevices = 0
try:
numDevices = dll.tdGetNumberOfDevices()
except:
numDevices = 0
for i in range(numDevices):
id = dll.tdGetDeviceId(i)
m = dll.tdMethods(
id,
TELLSTICK_DIM
)
if (m):
gn = dll.tdGetName(id)
name = (c_char_p(gn)).value
dll.tdReleaseString(gn)
deviceList[str(id)] = str(name.decode('utf-8'))
print deviceList
closeLibrary(dll)
#This is an alternative way to access the dictionary with id's and the current dim levels
dct = eg.plugins.TellStickDuo.plugin.dimPercentage
print dct
#Here is how to combine the two, using the id to match the name with the level
nameLevels = {}
for i in dct:
print i, dct[i], deviceList[i]
nameLevels[deviceList[i]] = dct[i]
print nameLevels
#To extract only the keys
print nameLevels.keys()
Code: Select all
dimData = { deviceId:device name|currentDimLevel, etc }
Code: Select all
dimData = eg.plugins.TellStickDuo.plugin.dimDeviceData
print dimData
for i in dimData:
print dimData[i] #the dim level and the device name
d = dimData[i].split('|')
level = d[0]
name = d[1]
print 'dim level: ', level
print 'device name: ', name
print 'device id: ', i
Code: Select all
12:54:52 {'106': '13|Front row', '107': '13|Back row'}
12:54:52 13|Front row
12:54:52 dim level: 13
12:54:52 device name: Front row
12:54:52 device id: 106
12:54:52 13|Back row
12:54:52 dim level: 13
12:54:52 device name: Back row
12:54:52 device id: 107
Code: Select all
dimData = eg.plugins.TellStickDuo.plugin.dimDeviceData
print dimData
for i in dimData:
print dimData[i] #the dim level and the device name
d = dimData[i].split('|')
level = d[0]
name = d[1]
print 'dim level: ', level
print 'dim level %: ', int(level)*100/255
print 'device name: ', name
print 'device id: ', i