Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

konradzawadka
Copy link

@konradzawadka konradzawadka commented Sep 18, 2023

To reproduce the issue configure item as here:

Number:Temperature      supplyTemperature                                                             <temperature>    (gTemperature, gAir)       ["Point","Temperature"]    {channel="modbus:data:localhostTCP:temperature:supplyTemperature:number"}

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.

@konradzawadka konradzawadka requested a review from a team as a code owner September 18, 2023 13:10
@openhab-bot
Copy link
Collaborator

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

Signed-off-by: konradzawadka <konradzawadka@gmail.com>
@jlaur jlaur changed the title [mongodb]: fix quantity type storage, introduce new types [mongodb] Fix quantity type storage, introduce new types Sep 18, 2023
@konradzawadka
Copy link
Author

@jlaur do you see chance for fix, is the fix valid?

Copy link
Contributor

@jlaur jlaur left a 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;
Copy link
Contributor

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.

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());
Copy link
Contributor

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:

@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()));
Copy link
Contributor

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?

konradzawadka and others added 5 commits October 27, 2023 14:26
…hab/persistence/mongodb/internal/MongoDBConvertUtilsTest.java

Co-authored-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: konradzawadka <konradzawadka@gmail.com>
…hab/persistence/mongodb/internal/MongoDBConvertUtilsTest.java

Co-authored-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: konradzawadka <konradzawadka@gmail.com>
…hab/persistence/mongodb/internal/MongoDBConvertUtils.java

Co-authored-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: konradzawadka <konradzawadka@gmail.com>
…hab/persistence/mongodb/internal/MongoDBConvertUtils.java

Co-authored-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: konradzawadka <konradzawadka@gmail.com>
…hab/persistence/mongodb/internal/MongoDBConvertUtils.java

Co-authored-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: konradzawadka <konradzawadka@gmail.com>
@lsiepel
Copy link
Contributor

lsiepel commented May 10, 2024

Gentle ping @konradzawadka can you proceed with this PR, by fixing the conflicts and addressing the comments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants