openhab/openhab-core

Default statedescription pattern for NumberItem

Closed this issue · 4 comments

In #4175, what's the rationale for choosing %.0f as the default formatting, instead of, say, %.1f?

I can see having a default of no decimal points may be good for DimmerItems, but NumberItems, IMO, should at least show one decimal point, so we go from 3.14159265 to 3.1 so it "hints" at the fact that it's there and it's not just an integer without being excessive.

Making it without a decimal point may not give people, especially new users, ideas that it could hold floating point values. I know this may sound silly if you're already familiar with everything.

It may come to personal preferences, but for temperatures, and for power consumption in kW, having that one decimal point allows me to know the difference, e.g. between 23.5 °C vs 24.4 °C, both of which would've been displayed as 24 °C with no decimal points.

This is of course irrelevant for me specifically. I would override/specify the formatting on all my important display items, even if the defaults are the same as what I want.

First you have to understand in which cases this default pattern will be used, there are only two cases:

  1. you have an item that is not linked to any channel and of course without any pattern defined on the item itself
  2. you have an item linked to a channel but the binding developer made a bad decision and did not define a default pattern for this channel, and of course without any pattern defined on the item itself

Additionally, for the second case (no pattern defined by the channel), I can also tell you that the default %.0f was there since many many years.

So yes, if you link one item to a channel, the channel provider should provide a proper default pattern and this default would be for example "%.1f %unit%" for a temperature. In case the channel does not provide a default pattern, you can of course define one on your item if the default does not match your need.

In practice, this default pattern is mainly for items that the user do not link to any channel.

And to answer to your question, the %.0f was chosen for two reasons:

  1. It was the value requested in the feature request
  2. It made sense to maintain a backward compatibility due to previous default pattern set on channel level.

It was the value requested in the feature request

I have not thought on the number of digits, but have seen this is default value somewhere. The rationale is that some value has to be selected as default.

Thanks for the explanation.