Continuing the discussion from here: Parent/child app (post #59 - 63)
UPDATE -- Resolved , see post 4 below for the working parent function.
I'm trying to get variable data from a parent app into a child app for the child app's logic to use. For the most part, I have the function below working, except I have a parent variable that is a date. The function returns it as a string. I'm trying to find a way to detect that the string should be a date and cast it/return it as such. Any help would be appreciated (or if you know a better way that is also appreciated).
Parent function:
def returnVar(var) {
def dataType = "String"
def returnValue
if (!(settings."${var}" == null)) { returnValue = settings."${var}" }
if (!(state."${var}" == null)) { returnValue = state."${var}" }
if (!(atomicState."${var}" == null)) { returnValue = atomicState."${var}" }
if (returnValue =~ "dddd-dd-ddTdd:.*") { dataType = "Date" }
if (returnValue == "true") { dataType = "Boolean" }
if (returnValue == "false") { dataType = "Boolean" }
if (returnValue == true) { dataType = "Boolean" }
if (returnValue == false) { dataType = "Boolean" }
LOGDEBUG ("returnVar(${var}), DataType:${dataType}, Value: ${returnValue}")
if (returnValue == null || returnValue == "") {}
try {
returnValue = returnValue."to${dataType}" //becomes .toString , .toBoolean , etc
// I cannot find a .toDate() or similar method to cast to date/datetime class
} catch (e) {
}
return returnValue
}
Example calling from the child app:
def parentSpeechDeviceType = parent.returnVar("speechDeviceType")
// settings.speechDeviceType in the parent app = "capability.musicPlayer" so parentSpeechDeviceType will become a string: "capability.musicPlayer"
The issue I have is with date/time strings being returned and not being able to evaluate them with timeOfDayIsBetween()
timeOfDayIsBetween(parent.returnVar("defaultStartTime"), parent.returnVar("defaultEndTime"), now, location.timeZone)
This ends up throwing the following error:
errorgroovy.lang.MissingMethodException: No signature of method: app1528955256796245835663.timeOfDayIsBetween() is applicable for argument types: (java.lang.String, java.lang.String, java.util.Date, sun.util.calendar.ZoneInfo) values: [2018-06-14T06:00:00.000-0500, 2018-06-14T23:50:00.000-0500, ...]
I think the issue is that I need to somehow get parent.returnVar("defaultStartTime") and parent.returnVar("defaultEndTime") to be returned as a date/datetime data type.