Visu JavaScript reference #
Visu functions #
Visu.on(name, callback)
#
Visu.on(name, id, callback)
#
Visu.off(name, callback)
#
Visu.off(name, id, callback)
#
Adds or removes an event listener.
Widget events #
widget-show- executed when a widget with the given ID is shownwidget-ready- executed when a widget with the given ID is ready (rendered)widget-hide- executed when a widget with a given ID is hidden
Arguments:
name- event name stringid- widget ID (optional) numbercallback- executed when event is triggered function
Callback arguments ({ id, widget }):
id- widget ID numberwidget- widget view instance object
Other events #
active-plan-change - executed when a new plan is shown
Callback arguments ({ newId, oldId }):
newId- new/current plan ID numberoldId- old/previous plan ID number
Visu.showPlan(id)
#
Shows plan with a given id (number).
Visu.showPin(args)
#
Shows PIN code input modal window.
args object structure:
onOk- executed when PIN code check succeeds functiononCancel- executed when Cancel or ESC is pressed functiononCheck(pin)- executed when PIN code must be checked, should return result as a Boolean function, can be asynclength- PIN code length, when a user inputs the given amount of characteronCheck(pin)is executed number
Visu.setScreensaver(state)
#
Shows/hides screensaver depending on the state Boolean
Screensaver must be enabled in General settings.
Visu.$t(key)
#
Translates the given key or returns key as is if a translation is not found.
Visu.addLocaleData(data)
#
Adds new translations into the dictionary.
Widget functions #
The following functions are meant to be use inside of a callback that is attached using Visu.on('widget-ready', ...)
widget.listen(groupaddress, callback)
#
Listens to the given group address value changes. callback is also executed immediately with the current group address value.
Listener is removed automatically when the widget is no longer present.
Callback arguments:
value- current value mixedobject- object reference object
widget.getEl()
#
Returns widget HTML element reference, if present.
widget.getCompactModeEl()
#
Returns widget compact mode HTML element reference, if present.
localbus library #
localbus.listen(type, callback)
#
Listen to events of type, callback function is executed when a relevant event happens.
type can be one of:
-
alerts- new alert is sent.
Callback arguments:source- alert source stringalert- alert text string
-
groupinit- group address object is initialized.
Callback arguments:groupaddress- group address stringvalue- current value mixedobject- object reference object
-
groupread- group read is executed for any group address.
Callback arguments:event- group event object
event.valuefield is available for known group addresses
-
groupresponse- group response is executed for any group address.
Callback arguments:event- group event object
event.valuefield is available for known group addresses
-
groupwrite- group write is executed for any group address.
Callback arguments:event- group event object
-
state- localbus connection state changed.
Callback arguments:connected- current localbus connection state Boolean
localbus.listen(type, arg, callback)
#
type can be one of:
-
object- group write or response is executed for the givenarg(group address).
Callback arguments:value- current value mixedobject- object reference object
-
storage- storage value change for the givenarg(storage key, '*' wildcard allowed).
Callback arguments without wildcard:value- new value mixed
Callback arguments with wildcard:
key- storage key stringvalue- new value mixed
localbus.unlisten(type, callback)
#
localbus.unlisten(type, arg, callback)
#
Similar to localbus.listen, but removes a listener function.
localbus.write(groupaddress, value)
#
Sends write request to the given group address. Group address must have a known data type.
localbus.update(groupaddress, value)
#
Similar to localbus.write, but does not send new value to TP bus.
localbus.read(groupaddress)
#
Sends read request to the given group address.
localbus.getvalue(groupaddress)
#
Returns current value for the given group address or undefined if object is not found.