I just made some improvements to the Somfy plugin so that it more gracefully handles startup issues and reporting failures to a user. Previously the startup sequence always showed up as ‘ok’, giving the user a false sense that everything was ok even when he hadn’t yet specified basic parameters.
Now, the code first checks for basic startup parameters, which are stored in UPNP variables, and sets them to a default value if they’re not already specified. You should at least set them an empty string because by setting them to something then the user will see them in the web user interface and be able to easily change them, as opposed to creating them again from scratch:
local lul_ID = luup.variable_get("urn:micasaverde-com:serviceId:SomfyBlinds1","BlindIds",lul_device)
if( lul_ID==nill ) then
lul_ID = "01,02"
luup.variable_set("urn:micasaverde-com:serviceId:SomfyBlinds1","BlindIds",lul_ID,lul_device)
end
Next, since this device uses an IO Port (ie a serial port, or an ethernet port, or a usb connection), we should check that the connection is specified and is active before doing the startup:
if( luup.io.is_connected(lul_device)==false ) then
luup.log('No port for Somfy',1)
luup.task('Choose the Serial Port for the URTSI',2,'Somfy Blind Interface',-1)
return false
end
The is_connected function is just added in firmware 912. If there’s a failure of any kind, we should call luup.task and put in some sort of description with the status code 2 (Error), and then ‘return false’. This way the user sees in the web panel that the module ‘Somfy Blind Interface’ is in an error condition and what the problem is (he didn’t choose the serial port). If we didn’t do the ‘return false’, the user would think the Somfy module was ok since, when the startup function doesn’t return false, the architecture assumes the module is running fine. If we called return false, didn’t call luup.task, then the user see that the module was failing, but would have only a generic “Startup sequence failed” without knowing the explicit reason.