-
-
Notifications
You must be signed in to change notification settings - Fork 429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
default UoM missing #3121
Comments
It gets challenging though for But my understanding is the units defined in the State Description Pattern will be applied when the value is restoredOnStartup so that could be a work around for the time being. And that might ultimately be the right solution over all. Is it better to leave the Item without units or to apply a potentially erroneous one? If the value stored in the database is kW, your rule is going to be off by a thousand when the value is restored from MapDB and because it doesn't have units, W is applied. I'm not sure that isn't even worse than getting an error and having the rule exit, especially since these rules are making decisions based on the results of the calculations. Personally, were it me, I'd see a complete overhaul of UoM and come to a wholistic design that addresses how it's used everywhere. About the only place where UoM provides a good end user experience is the UI. In rules and in persistence it falls short. |
Dimensionless is probably the only one where we do not need this. Remember it's a dimensionless value, literally.
No it isn't, at least not in a number of situations, possibly depending on startup order .
I agree it would be better to overhaul UoM, but short of that yes the base unit is applicable in most case so that's better than having to fix it in every code use location. |
I'm pretty sure that will muck up MainUI charting which doesn't have the facility to convert between UoM. Since all it gets from persistence is a raw number it depends on the State Description to supply the units. If the numbers in the database do not match the units in the State Description the cart will not be labeled correctly. I really think we are dancing around the issue though. Persistence should support saving the units somehow. I'm not sure how/if that would work for rrd4j but the other databases should be able to manage it. I just hate to see another half measure of a patch applied to the use of UoM which only sort of addresses the problem half way. We'd be trading an explicit error that needs to be fixed in rules to a silent error that happens some of the time for no obvious (to most users) reason. I can already see "my rule works except when I reload my .items file and then the math doesn't come out right" postings to the forum. |
Would it really be a half way solution? I don't think so. Sure we would get quite some posts, but essentially even if you're right with the assumption that it affects charting, that is a one-time event and as such a breaking change that cannot be avoided anyway, no matter what any other solution would look like and I see much more work and impact for any such. |
I like this idea as it would work in rrd4j as well as the other DBs and it shouldn't impact any of the add-ons themselves. There still needs to be some sort of special handling for Dimensionless I think because I'm not sure it make sense to convert decibels to a percentage (for example). Charting is going to need a bunch of changes to accommodate something like this and I can imagine the persistence actions will need to be overhauled as well. But this fixes the problem where Items end up with values that are orders of magnitude off of their "real" value because a default unit was blindly applied. But if I were king, I would do the mandatory unit approach. If I have a Number:Temperature, I shouldn't be able to update that to a value without a Temperature unit. Likewise, if I have just a plain Number, I shouldn't be able to update that to a value with any units. This causes all sorts of problems and confusion. I'd also make it so that doing math with numbers that have and do not have units more seamless. I've been working on something to help with that in JS Scripting but it would be even better if it were supported across all of OH. I'm experimenting with automatically adding units to a plain number using the units of the other operand of the calculation. That may not make sense all the time but it should most of the time and one can specify the units on their "plain number" to handle the rest. |
So the problem is the missing unit when a rule is triggered via an |
No. It's whenever the item is accessed from rules DSL code (JS and others too, probably) and item was never assigned any unit before (like it is the state when restoreOnStartup was applied). |
Ugh, that now would be a breaking change to result in a lot of "update broke my rules" posts I guess. |
Currently the only implementation of So it boils down to a limited set of dimensions which have a default unit. I think it leads to very ugly code if we just extend that and we should think about a better way of providing the set to the Edit: the mandatory approach is not necessary and would, as @mstormi points out, break tons of existing installations. |
You'll run into trouble if you change the state description if you use the state description to determine the unit. While this is unlikely for temperatures (I don't think that someone switches e.g. from °C to °F), it might happen for other dimensions like data amount (I'm thinking of internet traffic in MB, GB, TB) or volume (water consumption in l or m^3). Yes, that is the case now, but IMO it's not ideal. |
Granted I don't know the code but it would only need to be a single table of definitions, one for each UoM type, just the table is now larger than the current one. But it's static, defined as per physics behind, no need for anybody to change (unless you want to make that available as a feature to users). |
I thought of a .properties file inside the bundle, not externally. But that idea is even better, it allows the user to override the settings (e.g. use mbar instead of hPa for pressure or cm instead of m for length). The distribution could then provide a default and install that in the user directory. |
I'm not really arguing to implement this. But we already get a lot of posts about people struggling because all of a sudden they have a I don't see how enforcing the Number types would be any worse than that. What's the point of of having the different Number types if plain old |
We must be careful not to mix different issues:
|
👍
That would make me happy too (I should have thought of that). It's that surprise when a |
👍 Remember conversion into the base unit before persisting should be part of a comprehensive fix, as |
I think the conversion to base unit before persisting is a big breaking change and essentially makes "old" persisted data useless, because you can't convert it. This is not something that should happen in a minor release, where mostly new features are expected and only minor breaking changes should occur. The stripped units and the base units are more feature/bugfix than breaking. They are only breaking if you relied on the undocumented "we keep units even for dimensionless items". I still have no good idea how to implement unit overrides in a way that they can be configured via UI. We should not again deliver features that can't be configured from UI and later find out that we have to change everything again because it's needed for UI. |
We don't need full override capabilities just defaults to apply if no unit is given, do we ? Which is what #3143 does. Or do you mean that a On conversion to base unit, I agree it's a breaker albeit not that big. |
I'm not fine with editing files. It's breaking for every item where the unit was set in the state description to something different than what we now set as default. Since we did not provide defaults for most dimensions my guess would be that the state description was used quite often. |
Frankly, your post completely confused me.
I'm talking about changing default units per physical dimension. The base unit to use if no unit is given.
I don't understand. Adding or changing state description metadata won't change the value. Neither will changing the (just introduced) physical default unit. Where do you think that breaks anything ? Say we have a Number:Power item, with #3143 merged that now will have a default unit W. |
I'm not against having it user-configurable. I'm against a solution that can only be achieved by editing files. Because the same argument applies to nearly all settings on the right side of the settings page. I believe changing the timezone or the API security settings is also not something you would do every day. I overlooked a
However, this is a different discussion. I would suggest to open a new issue for "always persist base unit". I'm willing to implement that (and it's not very difficult to do so) if a majority of the maintainers agrees that we should take this breaking change. |
so by "It" you refer to implmeneting the conversion to base unit ? |
I wouldn't want to apply dogmatics at this stage. If it was "Beifang" to expose a capability that exists anyway (as you implement it with a mapping file, you can easily expose that to users, too), I would do it.
Opened #3167 |
There's operational states when an UoM item (say Number:Power) has a value but no unit such as after mapdb restoreOnStartup (as persistence generally does not store the unit).
This state might go unnoticed until e.g. the item is cast to the proper type in rulesDSL. rulesDSL refuses to cast and the rule crashes. Sad but correctly so because it does not know which unit to apply (in the Number:Power example whether to apply W or kW or mW).
We need a default unit to apply whenever a UoM item is updated and does not have a unit yet. It is imho not acceptable to leave that problem to the rule writer (incredibly hard to catch and work around everywhere it could surface).
The default unit to apply can be derived from the UoM (when there's none it is reasonable to assume the base unit i.e. W in the example).
The text was updated successfully, but these errors were encountered: