Aller au contenu
Lazer

Exploration des variables, fonctions, et objets disponibles en LUA sur HC3

Recommended Posts

Voici 2 petits scripts LUA pour explorer les objets accessibles dans les QuickApps et les Scènes sur HC3.

Quand on développe, il est toujours intéressant de découvrir des variables et fonctions non documentées, ou voir quelles fonctions sont disponibles dans les QuickApps ou dans les Scènes car il y a pas mal de différences.

Cela permettra aussi de suivre les ajouts de fonctions par Fibaro au fur et à mesure des nouveaux firmwares.

 

Les résultats donnés dans ce post sont été obtenus avec le firmware 5.031.33

 

QuickApps

 

Créer un QA avec un seul bouton pour lancer l'exécution du code :

function QuickApp:browse(racine, tableau)
	local variables, functions, objects = {}, {}, {}
	for k, v in pairs(tableau) do
		if type(v) == "table" then
			if v ~= _G then
				local variables2, functions2, objects2 = self:browse(racine .. k .. ".", v)
				for i = 1, #variables2 do variables[#variables+1] = variables2[i] end
				for i = 1, #functions2 do functions[#functions+1] = functions2[i] end
				for i = 1, #objects2 do objects[#objects+1] = objects2[i] end
			end
		elseif type(v) == "function" then
			functions[#functions+1] = racine .. k .. '()'
		elseif type(v) == "string" then
			variables[#variables+1] = racine .. k .. ' = "' .. v .. '"'
		elseif type(v) == "number" then
			variables[#variables+1] = racine .. k .. ' = ' .. tostring(v)
		elseif type(v) == "integer" then
			variables[#variables+1] = racine .. k .. ' = ' .. tostring(v)
		elseif type(v) == "boolean" then
			variables[#variables+1] = racine .. k .. ' = ' .. tostring(v)
		else
			objects[#objects+1] = racine .. k .. " => " .. type(v)
		end
	end
	table.sort(variables)
	table.sort(functions)
	table.sort(objects)
	return variables, functions, objects
end

function QuickApp:onButtonClic(event)
	self:trace("")
	local variables, functions, objects = self:browse("", _G)
	self:trace("Variables :")
	for _, v in ipairs(variables) do self:debug(v) end
	self:trace("Fonctions :")
	for _, v in ipairs(functions) do self:debug(v) end
	self:trace("Objets :")
	for _, v in ipairs(objects) do self:debug(v) end
	self:debug("Terminé")
end

function QuickApp:onInit()
end

 

Résultat :

 

  • Variables :

_VERSION = "Lua 5.3"
__TAG = "QuickApp152"
json._COPYRIGHT = "Copyright (c) 2007-2017 Thomas Harning Jr. "
json._DESCRIPTION = "LuaJSON : customizable JSON decoder/encoder"
json._VERSION = "1.3.4"
json.decode.simple.array.allowEmptyElement = false
json.decode.simple.array.trailingComma = true
json.decode.simple.calls.allowEmptyElement = false
json.decode.simple.calls.allowUndefined = false
json.decode.simple.calls.trailingComma = true
json.decode.simple.number.exp = true
json.decode.simple.number.frac = true
json.decode.simple.number.hex = false
json.decode.simple.number.inf = true
json.decode.simple.number.nan = true
json.decode.simple.object.allowEmptyElement = false
json.decode.simple.object.identifier = true
json.decode.simple.object.number = true
json.decode.simple.object.trailingComma = true
json.decode.simple.others.allowUndefined = true
json.decode.simple.others.null = false
json.decode.simple.others.undefined = false
json.decode.simple.strings.additionalEscapes = false
json.decode.simple.strings.badChars = ""
json.decode.simple.strings.strict_quotes = false
json.decode.strict.array.allowEmptyElement = false
json.decode.strict.array.trailingComma = false
json.decode.strict.calls.allowEmptyElement = false
json.decode.strict.calls.allowUndefined = false
json.decode.strict.calls.trailingComma = true
json.decode.strict.initialObject = true
json.decode.strict.nothrow = false
json.decode.strict.number.exp = true
json.decode.strict.number.frac = true
json.decode.strict.number.hex = false
json.decode.strict.number.inf = false
json.decode.strict.number.nan = false
json.decode.strict.object.allowEmptyElement = false
json.decode.strict.object.identifier = false
json.decode.strict.object.number = false
json.decode.strict.object.trailingComma = false
json.decode.strict.others.allowUndefined = false
json.decode.strict.strings.additionalEscapes = false
json.decode.strict.strings.badChars = " "
json.decode.strict.strings.strict_quotes = true
json.decode.strict.unicodeWhitespace = true
json.decode.util.DecimalLpegVersion = 1.0
json.encode.default.number.inf = true
json.encode.default.number.nan = true
json.encode.default.others.allowUndefined = true
json.encode.default.strings.encodeSet = "\"/%z-"
json.encode.default.strings.xEncode = false
json.encode.strict.initialObject = true
json.encode.strict.number.inf = false
json.encode.strict.number.nan = false
json.encode.strict.others.allowUndefined = false
json.encode.strict.strings.encodeSet = "\"/%z-"
json.encode.strict.strings.xEncode = false
logger.DEBUG = 1
logger.ERROR = 4
logger.FATAL = 5
logger.INFO = 2
logger.TRACE = 0
logger.WARNING = 3
math.huge = inf
math.maxinteger = 9223372036854775807
math.mininteger = -9223372036854775808
math.pi = 3.1415926535898
plugin.mainDeviceId = 152
utf8.charpattern = "[-�-�][�-�]*"

 

  • Fonctions :

__assert_type()
__fibaroSleep()
__fibaroUseAsyncHandler()
__fibaro_add_debug_message()
__fibaro_get_device()
__fibaro_get_device_property()
__fibaro_get_devices()
__fibaro_get_global_variable()
__fibaro_get_room()
__fibaro_get_scene()
__print()
__ternary()
api.delete()
api.get()
api.post()
api.put()
assert()
bit32.arshift()
bit32.band()
bit32.bnot()
bit32.bor()
bit32.btest()
bit32.bxor()
bit32.extract()
bit32.lrotate()
bit32.lshift()
bit32.replace()
bit32.rrotate()
bit32.rshift()
class()
clearInterval()
clearTimeout()
collectgarbage()
configure()
error()
fibaro.__houseAlarm()
fibaro.alarm()
fibaro.alert()
fibaro.call()
fibaro.callGroupAction()
fibaro.clearTimeout()
fibaro.debug()
fibaro.emitCustomEvent()
fibaro.error()
fibaro.get()
fibaro.getDevicesID()
fibaro.getGlobalVariable()
fibaro.getIds()
fibaro.getName()
fibaro.getRoomID()
fibaro.getRoomName()
fibaro.getRoomNameByDeviceID()
fibaro.getSectionID()
fibaro.getType()
fibaro.getValue()
fibaro.profile()
fibaro.scene()
fibaro.setGlobalVariable()
fibaro.setTimeout()
fibaro.sleep()
fibaro.trace()
fibaro.useAsyncHandler()
fibaro.wakeUpDeadDevice()
fibaro.warning()
getHierarchy()
ipairs()
json.array()
json.decode.decode()
json.decode.getDecoder()
json.decode.simple.object.setObjectKey()
json.decode.simple.strings.decodeUnicode()
json.decode.strict.object.setObjectKey()
json.decode.strict.others.null()
json.decode.strict.others.undefined()
json.decode.strict.strings.decodeUnicode()
json.decode.util.denied()
json.decode.util.get_invalid_character_info()
json.decode.util.setObjectKeyForceNumber()
json.decode.util.unexpected()
json.encode.default.array.isArray()
json.encode.default.others.null()
json.encode.default.others.undefined()
json.encode.encode()
json.encode.getEncoder()
json.encode.strict.array.isArray()
json.encode.strict.others.null()
json.encode.strict.others.undefined()
json.null()
json.util.InitArray()
json.util.IsArray()
json.util.buildCall()
json.util.clone()
json.util.decodeCall()
json.util.doOptionMerge()
json.util.isCall()
json.util.merge()
json.util.null()
json.util.printValue()
json.util.undefined()
logger.debug()
logger.error()
logger.fatal()
logger.getLevel()
logger.info()
logger.log()
logger.setLevel()
logger.trace()
logger.warning()
math.abs()
math.acos()
math.asin()
math.atan()
math.atan2()
math.ceil()
math.cos()
math.cosh()
math.deg()
math.exp()
math.floor()
math.fmod()
math.frexp()
math.ldexp()
math.log()
math.log10()
math.max()
math.min()
math.modf()
math.pow()
math.rad()
math.random()
math.randomseed()
math.sin()
math.sinh()
math.sqrt()
math.tan()
math.tanh()
math.tointeger()
math.type()
math.ult()
next()
onAction()
onUIEvent()
os.clock()
os.date()
os.difftime()
os.exit()
os.time()
pairs()
pcall()
plugin.createChildDevice()
plugin.deleteDevice()
plugin.getChildDevices()
plugin.getDevice()
plugin.getProperty()
plugin.restart()
print()
property()
rawlen()
select()
setInterval()
setTimeout()
string.byte()
string.char()
string.dump()
string.find()
string.format()
string.gmatch()
string.gsub()
string.len()
string.lower()
string.match()
string.pack()
string.packsize()
string.rep()
string.reverse()
string.split()
string.starts()
string.sub()
string.unpack()
string.upper()
super()
table.concat()
table.insert()
table.move()
table.pack()
table.remove()
table.sort()
table.unpack()
tonumber()
tostring()
type()
unpack()
utf8.char()
utf8.codepoint()
utf8.codes()
utf8.len()
utf8.offset()
xpcall()

 

  • Objets :

Device => userdata
Hierarchy => userdata
QuickApp => userdata
QuickAppBase => userdata
QuickAppChild => userdata
core.EventTarget => userdata
json.decode.simple.strings.escapeCheck => userdata
json.decode.strict.strings.escapeCheck => userdata
json.decode.util.ascii_ignored => userdata
json.decode.util.ascii_space => userdata
json.decode.util.comment => userdata
json.decode.util.comments.c => userdata
json.decode.util.comments.cpp => userdata
json.decode.util.hex => userdata
json.decode.util.hexpair => userdata
json.decode.util.identifier => userdata
json.decode.util.unicode_ignored => userdata
json.decode.util.unicode_space => userdata
mqtt.Client => userdata
mqtt.ConnectReturnCode => userdata
mqtt.QoS => userdata
net.HTTPClient => userdata
net.TCPSocket => userdata
quickApp => userdata

 

 

Scènes

 

Créer une scène LUA en exécution manuelle avec ce code :

local function browse(racine, tableau)
	local variables, functions, objects = {}, {}, {}
	for k, v in pairs(tableau) do
		if type(v) == "table" then
			if v ~= _G and v ~= _ENV and v ~= __index and k ~= "__index" then
				local variables2, functions2, objects2 = browse(racine .. k .. ".", v)
				for i = 1, #variables2 do variables[#variables+1] = variables2[i] end
				for i = 1, #functions2 do functions[#functions+1] = functions2[i] end
				for i = 1, #objects2 do objects[#objects+1] = objects2[i] end
			end
		elseif type(v) == "function" then
			functions[#functions+1] = racine .. k .. '()'
		elseif type(v) == "string" then
			variables[#variables+1] = racine .. k .. ' = "' .. v .. '"'
		elseif type(v) == "number" then
			variables[#variables+1] = racine .. k .. ' = ' .. tostring(v)
		elseif type(v) == "integer" then
			variables[#variables+1] = racine .. k .. ' = ' .. tostring(v)
		elseif type(v) == "boolean" then
			variables[#variables+1] = racine .. k .. ' = ' .. tostring(v)
		else
			objects[#objects+1] = racine .. k .. " => " .. type(v)
		end
	end
	table.sort(variables)
	table.sort(functions)
	table.sort(objects)
	return variables, functions, objects
end

fibaro.trace(tag, "")
local variables, functions, objects = browse("", _ENV)
fibaro.trace(tag, "Variables :")
for _, v in ipairs(variables) do fibaro.debug(tag, v) end
fibaro.trace(tag, "Fonctions :")
for _, v in ipairs(functions) do fibaro.debug(tag, v) end
fibaro.trace(tag, "Objets :")
for _, v in ipairs(objects) do fibaro.debug(tag, v) end
fibaro.debug(tag, "Terminé")

 

Résultat :

 

  • Variables :

fibaro.version = "1.0.0"
json._version = "0.1.0"
math.huge = inf
math.maxinteger = 9223372036854775807
math.mininteger = -9223372036854775808
math.pi = 3.1415926535898
sceneId = 10
sourceTrigger.id = 2
sourceTrigger.property = "execute"
sourceTrigger.type = "user"
tag = "Scene10"

 

  • Fonctions :

api.delete()
api.get()
api.post()
api.put()
assert()
error()
fibaro.alarm()
fibaro.alert()
fibaro.call()
fibaro.callGroupAction()
fibaro.debug()
fibaro.emitCustomEvent()
fibaro.error()
fibaro.get()
fibaro.getAllDeviceIds()
fibaro.getDevicesID()
fibaro.getGlobalVariable()
fibaro.getIds()
fibaro.getName()
fibaro.getRoomID()
fibaro.getRoomName()
fibaro.getRoomNameByDeviceID()
fibaro.getSectionID()
fibaro.getType()
fibaro.getValue()
fibaro.homeCenter.climate.setClimateZoneToManualMode()
fibaro.homeCenter.climate.setClimateZoneToScheduleMode()
fibaro.homeCenter.climate.setClimateZoneToVacationMode()
fibaro.homeCenter.notificationService.publish()
fibaro.homeCenter.notificationService.remove()
fibaro.homeCenter.notificationService.update()
fibaro.homeCenter.popupService.publish()
fibaro.homeCenter.systemService.reboot()
fibaro.homeCenter.systemService.suspend()
fibaro.profile()
fibaro.scene()
fibaro.setGlobalVariable()
fibaro.setTimeout()
fibaro.sleep()
fibaro.trace()
fibaro.wakeUpDeadDevice()
fibaro.warning()
ipairs()
json.decode()
json.encode()
math.abs()
math.acos()
math.asin()
math.atan()
math.atan2()
math.ceil()
math.cos()
math.cosh()
math.deg()
math.exp()
math.floor()
math.fmod()
math.frexp()
math.ldexp()
math.log()
math.log10()
math.max()
math.min()
math.modf()
math.pow()
math.rad()
math.random()
math.randomseed()
math.sin()
math.sinh()
math.sqrt()
math.tan()
math.tanh()
math.tointeger()
math.type()
math.ult()
net.HTTPClient.new()
net.HTTPClient.request()
next()
os.date()
os.time()
pairs()
pcall()
print()
select()
string.byte()
string.char()
string.dump()
string.find()
string.format()
string.gmatch()
string.gsub()
string.len()
string.lower()
string.match()
string.pack()
string.packsize()
string.rep()
string.reverse()
string.sub()
string.unpack()
string.upper()
table.concat()
table.insert()
table.move()
table.pack()
table.remove()
table.sort()
table.unpack()
tonumber()
tostring()
type()

 

 

  • Like 5

Partager ce message


Lien à poster
Partager sur d’autres sites

J'ai fait le test pour les QA en version 5.061.36, et la seule chose en plus est dans les objets :

 

net.UDPSocket => userdata
net.WebSocketClient => userdata
net.WebSocketClientTls => userdata

 

et je pense que ça date d'avant cette mise à jour...

Partager ce message


Lien à poster
Partager sur d’autres sites

En effet UDP et WebSockets ont été ajoutés dans des précédents firmwares.

Partager ce message


Lien à poster
Partager sur d’autres sites

Bonjour,

Très intéressante scène, merci.

Par contre, comment peut-on trouver la syntaxe pour utiliser une fonction comme : fibaro.profile() ?

 

Partager ce message


Lien à poster
Partager sur d’autres sites

Dans la doc de Fibaro, les fonctions sont documentées soit dans la section relative aux QuickApps, ou bien dans celle relative aux Scènes :

Et pour les fonctions qui ne sont pas documentées, alors c'est au petit bonheur la chance !

  • Haha 1

Partager ce message


Lien à poster
Partager sur d’autres sites

×