Astro binding Local_Sun_Duration is now in seconds after upgrade to OH 4.0.3

I have noticed that the Daylight duration in the Astro binding has changed from minutes to seconds.
Is it supposed to be in seconds or minutes?

I noticed it when I looked at my graph (which wasn’t working anyway)

I deleted the item and recreated it and it is still in seconds.

If it is in seconds then I will delete my rrd graph and start again.

OK I figured it out…
The unit of minute must have been changed to seconds in the metadata.
I changed the unit to min.

All good again I think but the graph is corrupted but that’s OK I have a backup of it.

Just to elaborate what’s going on.

I think the add-on delivers state updates for that Channel in minutes. However, it doesn’t really matter what units the add-on delivers. The unit metadata on the Item is going to dictate what unit the state of the Item actually uses. If that unit differs from what the add-on delivers, the state is converted to the Item’s unit.

If you do not set the unit metadata, the system default for that Item type is used. What the default is differs whether you are using SI or Imperial for most but in the case of Number:Time, it’s seconds for everyone.

So even if the add-on delivers minutes, without that unit metadata, the Item’s state will be converted to seconds.

I recommend that everyone who is using Units of Measurement, to always define the unit metadata to avoid surprises like these. This is doubly for those who have upgraded from OH 3 because in those cases users might be relying on a default behavior that has changed in OH 3.

Furthermore, in your rules, use asUnit when working with the state of an Item that has units. That way not only do you know for sure what unit the value will be in but your code will also document what units are being use so future you has less work to figure out the code.