Difference between revisions of "Common Methods Object"

From Hubitat Documentation
Jump to: navigation, search
m (Cschwer moved page Common Methods to Common Methods Object)
m (Added runInMillis)
Line 1: Line 1:
 
These methods can be used in both Apps and Drivers
 
These methods can be used in both Apps and Drivers
  
== <code>getLocation</code> ==
+
==<code>getLocation</code>==
  
 
'''Signature:'''
 
'''Signature:'''
 
  Location getLocation()
 
  Location getLocation()
  
== <code>getTemperatureScale</code> ==
+
==<code>getTemperatureScale</code>==
  
 
Gets the current temperature scale set for the hub.
 
Gets the current temperature scale set for the hub.
Line 19: Line 19:
 
'''Returns:'''
 
'''Returns:'''
  
: "F" or "C" based on the setting in the hub.
+
:"F" or "C" based on the setting in the hub.
  
== <code>now</code> ==
+
==<code>now</code>==
  
 
'''Signature:'''
 
'''Signature:'''
 
  long now()
 
  long now()
  
== <code>timeOfDayIsBetween</code> ==
+
==<code>timeOfDayIsBetween</code>==
  
 
Check if a date is between two dates.
 
Check if a date is between two dates.
Line 36: Line 36:
 
'''Parameters:'''
 
'''Parameters:'''
  
: start - The date to start comparison against.
+
:start - The date to start comparison against.
: stop - The date to stop comparison against.
+
:stop - The date to stop comparison against.
: value - The date to compare
+
:value - The date to compare
: timezone - (Optional) The timezone to use for the comparison
+
:timezone - (Optional) The timezone to use for the comparison
  
  
 
'''Returns:'''
 
'''Returns:'''
: true if the value date is between the start and stop dates, otherwise returns false.
 
  
 +
:true if the value date is between the start and stop dates, otherwise returns false.
  
== <code>unschedule</code> ==
+
 
 +
==<code>unschedule</code>==
  
 
Remove any scheduled tasks.  If method is called without paramters, all schedules will be removed.
 
Remove any scheduled tasks.  If method is called without paramters, all schedules will be removed.
Line 56: Line 57:
 
'''Parameters:'''
 
'''Parameters:'''
  
: handlerMethod - Only remove schedules for this handlerMethod
+
:handlerMethod - Only remove schedules for this handlerMethod
  
  
 
+
==<code>asynchttpGet</code>==
== <code>asynchttpGet</code> ==
 
  
 
Send an http GET request and return control to the calling code.  Any response from the call will be passed to the callback method.
 
Send an http GET request and return control to the calling code.  Any response from the call will be passed to the callback method.
Line 69: Line 69:
 
'''Parameters:'''
 
'''Parameters:'''
  
: callbackMethod - The name of a callback method to send the response to.  Can be null if the response can be ignored.
+
:callbackMethod - The name of a callback method to send the response to.  Can be null if the response can be ignored.
: params - the parameters to use to build the http GET call.
+
:params - the parameters to use to build the http GET call.
: data - optional data to be passed to the callback method.
+
:data - optional data to be passed to the callback method.
 +
 
 +
==<code>runInMillis</code>==
 +
'''Signature:'''
 +
void runInMillis(Long delayInMilliSeconds, String handlerMethod, Map options = null)
 +
 
 +
'''Parameters:'''
 +
 
 +
:delayInMilliseconds - How long to wait until the handler should be called, don't expect that it will be called in exactly that time.
 +
:handlerMethod - the name of a handler method in your driver or app. The method name should not contain parentheses.
 +
:options - a Map of optional parameters. If you specify <code>[data: 'Some value']</code> then <code>'Some value'</code> will be passed to your handler method. You can pass lists, maps etc. as a data parameter.<!-- Does the overwrite parameter apply to runInMillis as with runIn? -->
  
== <code>Additional to be documented</code> ==
+
'''Example:'''
 +
<pre>
 +
  private processQueue(Map queue) {
 +
    if (isQueueEmpty(queue)) {
 +
        sendEvent name: 'lifxdiscovery', value: 'complete'
 +
        return
 +
    }
 +
    def data = getNext(queue)
 +
    sendPacket data.ipAddress, data.packet
 +
    runInMillis(queue.delay, 'processQueue', [data: queue])
 +
  }
 +
 
 +
  runInMillis(50, 'processQueue', [data: queue])
 +
</pre>
 +
 
 +
==<code>Additional to be documented</code>==
  
 
'''Signature:'''
 
'''Signature:'''
Line 102: Line 127:
 
  void runEvery3Hours(String handlerMethod, Map options = null)
 
  void runEvery3Hours(String handlerMethod, Map options = null)
 
  void runIn(Long delayInSeconds, String handlerMethod, Map options = null)
 
  void runIn(Long delayInSeconds, String handlerMethod, Map options = null)
void runInMillis(Long delayInMilliSeconds, String handlerMethod, Map options = null)
 
 
  void runOnce(Date dateTime, String handlerMethod, Map options = null)
 
  void runOnce(Date dateTime, String handlerMethod, Map options = null)
 
  void runOnce(String dateTime, String handlerMethod, Map options = null)
 
  void runOnce(String dateTime, String handlerMethod, Map options = null)

Revision as of 00:56, 3 March 2019

These methods can be used in both Apps and Drivers

getLocation

Signature:

Location getLocation()

getTemperatureScale

Gets the current temperature scale set for the hub.

Signature:

String getTemperatureScale()

Parameters:

none

Returns:

"F" or "C" based on the setting in the hub.

now

Signature:

long now()

timeOfDayIsBetween

Check if a date is between two dates.


Signature:

boolean timeOfDayIsBetween(Date start, Date stop, Date value[, TimeZone timeZone])

Parameters:

start - The date to start comparison against.
stop - The date to stop comparison against.
value - The date to compare
timezone - (Optional) The timezone to use for the comparison


Returns:

true if the value date is between the start and stop dates, otherwise returns false.


unschedule

Remove any scheduled tasks. If method is called without paramters, all schedules will be removed.

Signature:

void unschedule()
void unschedule(handlerMethod)

Parameters:

handlerMethod - Only remove schedules for this handlerMethod


asynchttpGet

Send an http GET request and return control to the calling code. Any response from the call will be passed to the callback method.

Signature:

void asynchttpGet(callbackMethod, Map params, Map data = null)

Parameters:

callbackMethod - The name of a callback method to send the response to. Can be null if the response can be ignored.
params - the parameters to use to build the http GET call.
data - optional data to be passed to the callback method.

runInMillis

Signature:

void runInMillis(Long delayInMilliSeconds, String handlerMethod, Map options = null)

Parameters:

delayInMilliseconds - How long to wait until the handler should be called, don't expect that it will be called in exactly that time.
handlerMethod - the name of a handler method in your driver or app. The method name should not contain parentheses.
options - a Map of optional parameters. If you specify [data: 'Some value'] then 'Some value' will be passed to your handler method. You can pass lists, maps etc. as a data parameter.

Example:

  private processQueue(Map queue) {
    if (isQueueEmpty(queue)) {
        sendEvent name: 'lifxdiscovery', value: 'complete'
        return
    }
    def data = getNext(queue)
    sendPacket data.ipAddress, data.packet
    runInMillis(queue.delay, 'processQueue', [data: queue])
  }
  
  runInMillis(50, 'processQueue', [data: queue])

Additional to be documented

Signature:

BigDecimal celsiusToFahrenheit(BigDecimal val)
BigDecimal fahrenheitToCelsius(BigDecimal val)
void httpGet(String uri, Closure closure)
void httpGet(Map params, Closure closure)
void httpPost(String uri, String body, Closure closure)
void httpPost(Map params, Closure closure)
void httpPutJson(String uri, String body, Closure closure)
void httpPutJson(String uri, Map body, Closure closure)
void httpPutJson(Map params, Closure closure)
void httpPut(String uri, String body, Closure closure)
void httpPut(Map params, Closure closure)
void httpDelete(Map params, Closure closure)
String getMACFromIP(String ipAddr)
String convertTemperatureIfNeeded(BigDecimal value, String scale, Integer precision)
Object parseJson(String stringToParse)
GPathResult parseXML(String stringToParse)
Map parseLanMessage(String stringToParse)
void pauseExecution(Long millisecs)
void runEvery1Minute(String handlerMethod, Map options = null)
void runEvery5Minutes(String handlerMethod, Map options = null)
void runEvery10Minutes(String handlerMethod, Map options = null)
void runEvery15Minutes(String handlerMethod, Map options = null)
void runEvery30Minutes(String handlerMethod, Map options = null)
void runEvery1Hour(String handlerMethod, Map options = null)
void runEvery3Hours(String handlerMethod, Map options = null)
void runIn(Long delayInSeconds, String handlerMethod, Map options = null)
void runOnce(Date dateTime, String handlerMethod, Map options = null)
void runOnce(String dateTime, String handlerMethod, Map options = null)
void schedule(Date dateTime, String handlerMethod, Map options = null)
void schedule(String expression, String handlerMethod, Map options = null)
void asynchttpGet(String callbackMethod = null, Map params, Map data = null)
void asynchttpPost(String callbackMethod = null, Map params, Map data = null)
void asynchttpPut(String callbackMethod = null, Map params, Map data = null)
void asynchttpDelete(String callbackMethod = null, Map params, Map data = null)
void asynchttpPatch(String callbackMethod = null, Map params, Map data = null)
void asynchttpHead(String callbackMethod = null, Map params, Map data = null)
Map textToSpeech(String stringToBeSynthesized, String voice = null)
String encrypt(String value)
String decrypt(String value)
void sendLocationEvent(Map properties)
void httpPostJson(String uri, String body, Closure closure)
void httpPostJson(String uri, Map body, Closure closure)
void httpPostJson(Map params, Closure closure)
Date timeToday(String timeString, TimeZone timeZone = null)
Date toDateTime(String dateTimeString)