openLuup : set_failure

It seems that in openLuup, “luup.set_failure” is not implemented.

luup.set_failure( 1, {deviceId} )

In Vera UI7 :

  • CommFailure = 1
  • CommFailureTime = os.time()
  • device status = 2 => used by ALTUI to set the device header in red
  • something else (a flag ?) => alert “Can’t Detect Device” in UI7 and device actions do not work anymore (Communication failure)

In openLuup :
Nothing

luup.set_failure( 0, {deviceId} )

In Vera UI7 :

  • CommFailure = 0
  • CommFailureTime = 0
  • device status = -1
  • something else (a flag ?) => alert “Can’t Detect Device” disapears in UI7 and device actions work again

In openLuup :
Nothing

Which version are you using? The development branch has that implemented (possibly correctly!)

All the current master branch does is write a log entry.

I used Release 7.0

Wow ! There are a lot of changes in the development branch (e.g. update from Github for plugins)

luup.set_failure is now implemented… but I think there’s a bug.
luup.set_failure(1,id) => for communication failure => device status = 2
luup.set_failure(2,id) => for authentification failure => device status = 2

Device status seems to be always set to ‘2’ when there is an error (in Vera).
But openLuup takes the parameter of set_failure as the device status.

Anyway, my goal was to show a communication problem in the UI, but as set_failure blocks the device actions, the user can not do something to fix the problem (like new user/password) without reloading the luup engine.

Red warning in UI7 is bound to an hidden flag, set with set_failure.
Set variable “CommFailure” or device status attribute is not enough.

I have to use a special icon in case of communication problem.
And use the device status to highlight the problem, at least in ALTUI.

Yes, it’s not up to the speed of development of AltUI, but I try my best. This will shortly become release 8.0

luup.set_failure is now implemented... but I think there's a bug. luup.set_failure(1,id) => for communication failure => device status = 2 luup.set_failure(2,id) => for authentification failure => device status = 2

Device status seems to be always set to ‘2’ when there is an error (in Vera).
But openLuup takes the parameter of set_failure as the device status.

Hmm. Seems like there’s more experimenting to do here.

Anyway, my goal was to show a communication problem in the UI, but as set_failure blocks the device actions, the user can not do something to fix the problem (like new user/password) without reloading the luup engine.

Red warning in UI7 is bound to an hidden flag, set with set_failure.
Set variable “CommFailure” or device status attribute is not enough.

I don’t touch the CommFailure flag, and there’s clearly nothing I can do about a hidden flag. But in previous experiments, I was able to turn the device panel banner green / blue / and red with various status values.

I have to use a special icon in case of communication problem. And use the device status to highlight the problem, at least in ALTUI.

Yes, I ran into the same problem wanting to implement a flag to show that an openLuup version update was available. (The development version can now update from itself from GitHub, as well as AltUI, but don’t try it because you will revert to a version which doesn’t have that functionality!)

Hi, this is related to the device status in the development branch. I modified this code in VeraBrigde to copy the status, so now ALTUI shows the openLuup device banner blue, green or red when remote vera device does.

-- updates existing device variables with new values
-- this devices table is from the "status" request
local function UpdateVariables(devices)
  for _, dev in pairs (devices) do
    dev.id = tonumber (dev.id)
    local i = local_by_remote_id(dev.id)
    if i and luup.devices[i] then
      local d = luup.devices[i]
      d:status_set(dev.status)  -- copy device status
                                -- TODO set d.tooltip from dev.tooltip ?
      if (type (dev.states) == "table") then
        for _, v in ipairs (dev.states) do
          local value = luup.variable_get (v.service, v.variable, i)
          if v.value ~= value then
  --          print ("update", dev.id, i, v.variable)    -- TODO: TEST ONLY
            luup.variable_set (v.service, v.variable, v.value, i)
          end
        end
      end
    end  
  end
end

I just ran a quick test to confirm that calling luup.set_failure for vera devices with 0, 1, or 2 sets the device status to 2 (turns the banner red). Parameter values 1 and 2 also set the CommFailure variable to 1. The parameter does not appear to be the same as device status.

It seems that the only way to reset the status back is to post user data modification for that device. That’s how ALTUI does it:

http://vera_ip/port_49451/upnp/control/hag
SOAPACTION:"urn:schemas-micasaverde-org:service:HomeAutomationGateway:1#ModifyUserData"
... device user data here ...

I also did not find any info on how to retrieve what was specified in set_failure parameter…

be careful, the behavior is not the same according to the value
luup.set_failure 1,2 => device status = 2
luup.set_failure 0 => device status = -1

@vosmont

No, I think this is OK since it is just copying the status from the remote Vera, not using set_failure.

@explorer

Yes, I had already done similar myself in the middle of refactoring the bridge.

@explorer, @vosmont

Just to expand on my previous comment on your last posts…

I’m very grateful for your experimentation and insights here, confirming the behaviour of set_failure. I need to adjust my code accordingly. Now @amg0 has resolved the upnp/control/hag user_data modification requests for openLuup, we are filling in some of the user interface functionality. Editing Startup Lua will be, I hope, a useful start. The WSAPI CGI framework is there for anyone to extend it further.

Thanks again.

@akbooer, you’re welcome ! ;D

The credit goes to you for releasing openLuup.
It really helps me to develop and test my plugins.

@all, be careful with set_failure : it means that a critical failure has occured.
The device’s actions work no more in that case.

In my case, I can’t use it because I want that the user is able of correcting the problem without restart of the luup engine.

My assumption is that functionality resumes if the plugin itself changes the failure status once again. In which case, an HTTP handler could be used to respond to a request and reset things appropriately. Just a thought.

Yes it could be done like that. For the moment I use HTTP handler just for retrieving computed informations.
It could be used instead of upnp actions (but there can be only one handler for instances of a plugin)

@akbooer,

it seems that set_failure in openLuup doesn’t set the variables “CommFailure” and “CommFailureTime”

No, it doesn’t. Do you need it to do that?

The Vera sets these variables when set_failure is called.

set_failure 1,2
=> CommFailure = 1,2 and CommFailureTime = os.time()

set_failure 0
=> CommFailure = 0 and CommFailureTime = 0

I don’t know if the Vera change these variables even if the values haven’t changed (to not call a watcher if no need)

Are these with serviceId urn:micasaverde-com:serviceId:HaDevice1?

So they’re only applicable to HaDevices?

I suppose. Perhaps a check is done before, to know if these variables exist ?

Fixed with latest development branch update.

Thanks :slight_smile:

Hello,

there’s a bug with set_failure : it is not possible to set a failure on another device than the plugin.

In “luup.lua”, it should be:

    variable_set (HaSID, "CommFailure", status, devNo)     -- 2016.05.17
    variable_set (HaSID, "CommFailureTime", time, devNo)

Many thanks - hot fix applied to development branch.