OK, I see that you are digging in your heels on this one.
I'm not trying to replace tiles - I am trying to communicate information to the user or programmer. There is no other means for either persona to see what is going on inside a device except for attributes (end-users can't access dataValues in Dashboards or Rules).
Imagine a simple Hubitat Dashboard (or Rule Engine Rule) that displays the event_name
that is running, and it also wants to display the event_endDate
beside it. How else would I be able to get this information into the Dashboard, if not through an attribute? And while I could send a space " ", the result would not be a valid date if another App (or Rule) was trying to use that information.
There is a reason why null
(undefined) exists in Groovy, and why null
is a valid value for a String (and an Integer, and a BigDecimal, and a Boolean, and ...). There is a also reason that Hubitat will return null
when asked for the currentValue()
of an attribute that hasn't been initialized yet - it isn't true
or false
- it's null
(aka undefined). There's probably even a reason that Hubitat's Device page shows the word "null" for such values, albeit momentarily (and incorrectly, I guess, because the underlying value has not been actually changed).
Frankly, I don't get why the push-back.
Hubitat clearly understands when an attribute is null
, because it will return null
when asked for the currentValue of an uninitialized attribute. It is is also clear that at least SOME code (device display page) understands how to display null
values. Somewhere, the code is indeed letting "null" into the device (perhaps only into some cache, I guess), but that code isn't overriding the attribute value when it goes to unload the cache (I'm just guessing here).
And yes, while I can code around your chosen implementation, it requires code to do excess work on Hubitat than should be necessary - I really should only have to test if the returned value is null or not:
Hubitat code
def event_endDate = theDevice.currentValue("event_endDate", true) // force reading the cache
if (event_endDate) // verify the response isn't null because it hasn't been initialized yet
{
if (event_endDate != 'null') // check if it has been set to literal `null`
{
// Handle the actual end-date
}
else
{
// There is no event running
}
}
else
{
// The attribute hasn't been initialized yet
}
verses SmartThings code
def event_endDate = theDevice.currentValue("event_endDate", true) // force reading the cache
if (event_endDate) // verify the response isn't null because it hasn't been initialized yet
{
// Handle the actual end-date
}
else
{
// There is no event running
}