Does anyone know how to programmatically retrieve the state presentation from the rules?
In the .items file, you could define something like this:
Number Livingroom_Temperature "Temperature [%.1f °C]" // e.g. "23.5 °C"
When displayed in sitemap, it shows “Temperature 23.5 °C”. I am trying to get that value in a .rules file, but invoking item.getLabel() only returns “Temperature”. I am hoping not to have to define the formatting again in the .rules file.
you can use Livingroom_Temperature.state.toString
I’m pretty sure you have to define the formatting again in the .rules file.
So item.state.toString doesn’t work.
At this point, I agree with Rick. I don’t think it’s possible. There is nothing to indicate that the formatting information even makes it to the GenericItem class. The only relevant method there is getLabel. There must be another mechanism to store the formatting info and used it in the sitemap.
This is unfortunate as the information needs to be duplicated again. My use case is to send an email alert with the same formatted labels as seen on the sitemap.
Adding text to an email alert content is pretty straight forward. Although I understand your frustrations.
Have a look at the Working with Groups Design Pattern. Specifically note the stringbuilder parts.
I recently used it to help format some low battery email notifications in the same way and it works fine.
Yup I had it working by doing the formatting directly. I just hate to have to dup the resources when it’s already defined in the .items file.