-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[mongodb] Fix quantity type storage, introduce new types #15617
Conversation
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/issue-with-storage-quanity-date-with-units-in-mongodb/149714/1 |
ac6bb25
to
d0b161a
Compare
Signed-off-by: konradzawadka <[email protected]>
21b3c11
to
47a3518
Compare
@jlaur do you see chance for fix, is the fix valid? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution, and welcome as a contributor. 🙂
I have provided some initial feedback. Unfortunately I don't know anything about MongoDB, and I'm a bit hesitant to introduce major changes in persistence services, especially those I'm not familiar with.
In the linked community thread you mention that "7.3 °C" is stored rather than "7.3". Can you show the schema for a Number:Dimension
item, and also explain why you would rather store it without unit? If "7.3 °C" is stored, what will happen when unit is changed to °F to the item and the values are queried? Will values (or could it) be converted into the new configured unit, or what will actually happen?
How are migrations and backwards compatibility handled with this PR, i.e. users already having stored "7.3 °C" and now going forward storing values without unit?
|
||
import javax.measure.Unit; | ||
|
||
import org.apache.commons.lang3.StringUtils; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid this import. See #7722 for details.
...ence.mongodb/src/main/java/org/openhab/persistence/mongodb/internal/MongoDBConvertUtils.java
Outdated
Show resolved
Hide resolved
...ence.mongodb/src/main/java/org/openhab/persistence/mongodb/internal/MongoDBConvertUtils.java
Outdated
Show resolved
Hide resolved
...ence.mongodb/src/main/java/org/openhab/persistence/mongodb/internal/MongoDBConvertUtils.java
Show resolved
Hide resolved
String valueStr = obj.getString(FIELD_VALUE); | ||
if (StringUtils.isNumeric(valueStr)) { | ||
Instant i = Instant.ofEpochMilli(new BigDecimal(valueStr).longValue()); | ||
ZonedDateTime z = ZonedDateTime.ofInstant(i, TimeZone.getDefault().toZoneId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TimeZoneProvider should be used to get the time-zone configured in openHAB. You can add a ZoneId
parameter and let the service provide this.
See for example:
Lines 74 to 79 in f8bcfb0
@Activate | |
public JdbcPersistenceService(final @Reference ItemRegistry itemRegistry, | |
final @Reference TimeZoneProvider timeZoneProvider) { | |
super(timeZoneProvider); | |
this.itemRegistry = itemRegistry; | |
} |
return new DateTimeType(z); | ||
} else { | ||
return new DateTimeType( | ||
ZonedDateTime.ofInstant(obj.getDate(FIELD_VALUE).toInstant(), ZoneId.systemDefault())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. I don't understand why you have chosen a different approach here compared to line 142?
....mongodb/src/test/java/org/openhab/persistence/mongodb/internal/MongoDBConvertUtilsTest.java
Outdated
Show resolved
Hide resolved
....mongodb/src/test/java/org/openhab/persistence/mongodb/internal/MongoDBConvertUtilsTest.java
Show resolved
Hide resolved
…hab/persistence/mongodb/internal/MongoDBConvertUtilsTest.java Co-authored-by: Jacob Laursen <[email protected]> Signed-off-by: konradzawadka <[email protected]>
…hab/persistence/mongodb/internal/MongoDBConvertUtilsTest.java Co-authored-by: Jacob Laursen <[email protected]> Signed-off-by: konradzawadka <[email protected]>
…hab/persistence/mongodb/internal/MongoDBConvertUtils.java Co-authored-by: Jacob Laursen <[email protected]> Signed-off-by: konradzawadka <[email protected]>
…hab/persistence/mongodb/internal/MongoDBConvertUtils.java Co-authored-by: Jacob Laursen <[email protected]> Signed-off-by: konradzawadka <[email protected]>
…hab/persistence/mongodb/internal/MongoDBConvertUtils.java Co-authored-by: Jacob Laursen <[email protected]> Signed-off-by: konradzawadka <[email protected]>
Gentle ping @konradzawadka can you proceed with this PR, by fixing the conflicts and addressing the comments? |
I guess this PR is related to openhab/openhab-core#1954 Woudl be nice if we can proceed with this. Another ping @konradzawadka do you need anything to proceed? |
Also a ping to @marciseli @boomer41 and @ulbi who contributed to this persistence service in the past. Hopefully they can test, confirm, or assist in any way to get this PR finished. |
Mainly superseded by #16333 if there is anything left to fix @konradzawadka feel free to open a new PR or issue |
To reproduce the issue configure item as here:
Then value stored in mongodb is:
7.3 °C
Should be:
7.3
Following fix improves storage and also refactor other conversion based on InfluxDB implementation.