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

[Robonect] Use global openHAB timezone for DateTime objects #7903

Merged
merged 5 commits into from
Jun 17, 2020

Conversation

t2000
Copy link
Contributor

@t2000 t2000 commented Jun 12, 2020

Use the timezone that has been configured by the user in openHAB settings
for all robonect messages instead of UTC.

Fixes #7848

Signed-off-by: Stefan Triller [email protected]

Use the timezone that has been configured by the user in openHAB settings
for all robonect messages instead of UTC.

Fixes openhab#7848

Signed-off-by: Stefan Triller <[email protected]>
@t2000 t2000 requested a review from reyem as a code owner June 12, 2020 08:56
@TravisBuddy
Copy link

Travis tests were successful

Hey @t2000,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

@t2000
Copy link
Contributor Author

t2000 commented Jun 12, 2020

Jar file for testing (please rename to .jar before placing it in the addons folder).
Also make sure to deactivate the pre-installed (original) binding first!

org.openhab.binding.robonect-2.5.6-SNAPSHOT.zip

@t2000
Copy link
Contributor Author

t2000 commented Jun 12, 2020

I have changed to code in a way that the user an configure the timezone from robonect on the Thing and afterwards it will be converted into the time that the user has configured in openHAB.

org.openhab.binding.robonect-2.5.6-SNAPSHOT.zip

@TravisBuddy
Copy link

Travis tests were successful

Hey @t2000,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

@t2000
Copy link
Contributor Author

t2000 commented Jun 12, 2020

Using the default openHAb timezone now if noting is configured or an error occurs.

org.openhab.binding.robonect-2.5.6-SNAPSHOT.zip

@TravisBuddy
Copy link

Travis tests were successful

Hey @t2000,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

@me2000
Copy link

me2000 commented Jun 12, 2020

Tested it with a fresh OH 2.5.5 install plus this JAR and it works. Times are now corrected inside the binding and set and displayed correctly.


String timeZoneString = robonectConfig.getTimezone();
try {
timeZone = ZoneId.of(timeZoneString);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will throw an NPE if timeZoneString is null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good catch!

I have fixed it.

@cpmeister cpmeister added the enhancement An enhancement or new feature for an existing add-on label Jun 12, 2020
Signed-off-by: Stefan Triller <[email protected]>
@TravisBuddy
Copy link

Travis tests were successful

Hey @t2000,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

@@ -71,12 +74,16 @@
private ScheduledFuture<?> pollingJob;

private HttpClient httpClient;
private TimeZoneProvider timeZoneProvider;

private ZoneId timeZone = ZoneId.of("Europe/Berlin");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of caching this value in a field, you might consider dynamically creating it every time since its value should fall back to the timeZoneProvider timezone whenever it isn't specified by the config.
The problem I see is that the value returned by timeZoneProvider might change over time if the user changes settings in runtime.
So any value returned by timeZoneProvider should never be cached since it might change at any time, without notification.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion is to more or less replace uses of timeZone with a new method getTimeZone().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't thought about this. thanks for pointing it out!

I have added a commit to change this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this again and noticed that if you change the configuration of the thing, the handler gets restarted anyway, because it doesn't overwrite handleConfigurationUpdate and thus the BaseThingHandler#handleConfigurationUpdate will call dispose() and initialize(), so my previous implementation would also read the changed value within initialize().

I leave it up to you, to include the commit with the change or to drop it during merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: I decided to drop my commit because it was difficult to fix the tests (accessing the config ran into an NPE).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to the return value of timeZoneProvider changing during runtime. A change in the return value wouldn't notify the handler and it wouldn't restart the handler or binding in any way. The binding shouldn't save what timeZoneProvider return into a field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think we are talking about two different things here:

  1. The timezone of the thing and its fallbacks.
  2. The timezone as it should be presented to the user.

For point 2 I am always using the currently configured time in convertUnitToDateTimeType()

// we provide the time in the format as configured in the openHAB settings
 ZonedDateTime zdt = adjustedInstant.atZone(timeZoneProvider.getTimeZone());

as its always requested from the timeZoneProvider.

For point 1. the information from the timeZoneProvider acts as a fallback only for the lifetime of the Thinghandler, or until someone sets the correct time on the thing (because then dispose and initialize will be called anyway.

So do you want me to change this, even if its just a fallback and even a warning is printed to the user to make him aware of that he should add the correct zone to his Thing configuration? I am fine with doing so, if you think its better. I just wanted to clarify things and see if I have understood you correctly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with doing so, if you think its better. I just wanted to clarify things and see if I have understood you correctly.

Yep you have understood me correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great :)

i have now changed it in a way that the warning about the not set timezone on the thing will only be printed once on the startup of the handler and if it is not set, I get it from the timezoneProvider at runtime for every call.

@t2000
Copy link
Contributor Author

t2000 commented Jun 14, 2020

Version with getting timezone also if changed on Thing:

org.openhab.binding.robonect-2.5.6-SNAPSHOT.zip

@TravisBuddy
Copy link

Travis tests were successful

Hey @t2000,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

Copy link
Contributor

@cpmeister cpmeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cpmeister cpmeister merged commit 00a2cd5 into openhab:2.5.x Jun 17, 2020
@cpmeister cpmeister added this to the 2.5.6 milestone Jun 17, 2020
@t2000 t2000 deleted the robonectTime branch June 17, 2020 18:24
knikhilwiz pushed a commit to knikhilwiz/openhab2-addons that referenced this pull request Jul 12, 2020
…7903)

* [Robonect] Use global openHAB timezone for DateTime objects

Use the timezone that has been configured by the user in openHAB settings
for all robonect messages instead of UTC.

Fixes openhab#7848

Signed-off-by: Stefan Triller <[email protected]>
CSchlipp pushed a commit to CSchlipp/openhab-addons that referenced this pull request Jul 26, 2020
…7903)

* [Robonect] Use global openHAB timezone for DateTime objects

Use the timezone that has been configured by the user in openHAB settings
for all robonect messages instead of UTC.

Fixes openhab#7848

Signed-off-by: Stefan Triller <[email protected]>
Signed-off-by: CSchlipp <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
…7903)

* [Robonect] Use global openHAB timezone for DateTime objects

Use the timezone that has been configured by the user in openHAB settings
for all robonect messages instead of UTC.

Fixes openhab#7848

Signed-off-by: Stefan Triller <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
…7903)

* [Robonect] Use global openHAB timezone for DateTime objects

Use the timezone that has been configured by the user in openHAB settings
for all robonect messages instead of UTC.

Fixes openhab#7848

Signed-off-by: Stefan Triller <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
…7903)

* [Robonect] Use global openHAB timezone for DateTime objects

Use the timezone that has been configured by the user in openHAB settings
for all robonect messages instead of UTC.

Fixes openhab#7848

Signed-off-by: Stefan Triller <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
…7903)

* [Robonect] Use global openHAB timezone for DateTime objects

Use the timezone that has been configured by the user in openHAB settings
for all robonect messages instead of UTC.

Fixes openhab#7848

Signed-off-by: Stefan Triller <[email protected]>
DaanMeijer pushed a commit to DaanMeijer/openhab-addons that referenced this pull request Sep 1, 2020
…7903)

* [Robonect] Use global openHAB timezone for DateTime objects

Use the timezone that has been configured by the user in openHAB settings
for all robonect messages instead of UTC.

Fixes openhab#7848

Signed-off-by: Stefan Triller <[email protected]>
Signed-off-by: Daan Meijer <[email protected]>
markus7017 pushed a commit to markus7017/openhab-addons that referenced this pull request Sep 19, 2020
…7903)

* [Robonect] Use global openHAB timezone for DateTime objects

Use the timezone that has been configured by the user in openHAB settings
for all robonect messages instead of UTC.

Fixes openhab#7848

Signed-off-by: Stefan Triller <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[robonect]: Reflect OH2 timezone offset to correctly display DateTimes
4 participants