funktion i LUA scen

Post Reply
jompa68
Proffsmedlem
Posts: 735
Joined: 12 Aug 2012, 08:53
11
Location: Hofors

När man jobbar med med LUA kodning så kan man förenkla genom att anropa en funktion istället för att skriva samma kod flera gånger i en scen.

Kommer lista lite funktioner här:
Skicka push meddelande

Code: Select all

-- function push message to mobile
local activatePush = true; 
local ID_Smartphone = 141;  
pushMessage = function (sendPush)
 	if (activatePush) then
 		fibaro:call(ID_Smartphone, 'sendPush', sendPush); 
 	end
end
anropas så här:

Code: Select all

pushMessage("Test of push message")
Färgad debug text
Man kan ändra färg på debug kod (kanske inte är så flashigt om man är färgblind) ;)

Code: Select all

-- debug function
Debug = function ( color, message ) 
  fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span")); 
end 
anropas så här:

Code: Select all

Debug("red","Test message")
Debug("green","Test message")
Debug("orange","Test message")
Skärmavbild 2014-06-23 kl. 20.55.15.png
Skärmavbild 2014-06-23 kl. 20.55.15.png (13.06 KiB) Viewed 6321 times

Mer färgad debug text

Code: Select all

-- Show debuginfo true/false
local showStandardDebugInfo = true;
local showExtraDebugInfo = true;


-- the functions
ExtraDebug = function (debugMessage) 
  if ( showExtraDebugInfo ) then 
    Debug( "grey", debugMessage); 
  end 
end 

StandardDebug = function (debugMessage) 
 if ( showStandardDebugInfo ) then 
    Debug( "white", debugMessage);    
  end 
end 

anropas så här:

Code: Select all

ExtraDebug( "Test message, grey color" );

StandardDebug( "Test message, white color" );
Skärmavbild 2014-06-24 kl. 10.58.52.png
Skärmavbild 2014-06-24 kl. 10.58.52.png (14.21 KiB) Viewed 6261 times
Skicka epost funktion

Code: Select all

-- function send email
local activateMail = true; 
sendMail = function (subject, sendMail)
 	if (activateMail) then
 		fibaro:call(4, 'sendEmail', subject,  sendMail);
 	end
end
anropas så här:

Code: Select all

sendMail("Subject", "Test of mail message")
User avatar
Bamsefar
Z-Wave Kung
Posts: 1230
Joined: 25 Nov 2013, 15:06
10
Location: Stockholm

ExtraDebug? Ytterligare enfunktion du definierat eller?
Testar Home Assistant på Raspberry Pi4B - nice :mrgreen:
Post Reply