-
-
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
[Robonect] Use global openHAB timezone for DateTime objects #7903
Conversation
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]>
Travis tests were successfulHey @t2000, |
Jar file for testing (please rename to .jar before placing it in the addons folder). |
Signed-off-by: Stefan Triller <[email protected]>
I have changed to code in a way that the user an configure the timezone from robonect on the |
Travis tests were successfulHey @t2000, |
Signed-off-by: Stefan Triller <[email protected]>
Using the default openHAb timezone now if noting is configured or an error occurs. |
Travis tests were successfulHey @t2000, |
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); |
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.
This will throw an NPE if timeZoneString
is null.
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, good catch!
I have fixed it.
Signed-off-by: Stefan Triller <[email protected]>
Travis tests were successfulHey @t2000, |
@@ -71,12 +74,16 @@ | |||
private ScheduledFuture<?> pollingJob; | |||
|
|||
private HttpClient httpClient; | |||
private TimeZoneProvider timeZoneProvider; | |||
|
|||
private ZoneId timeZone = ZoneId.of("Europe/Berlin"); |
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.
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.
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.
My suggestion is to more or less replace uses of timeZone
with a new method getTimeZone()
.
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.
I haven't thought about this. thanks for pointing it out!
I have added a commit to change this.
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.
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.
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.
Edit: I decided to drop my commit because it was difficult to fix the tests (accessing the config ran into an NPE).
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.
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.
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.
Hmm, I think we are talking about two different things here:
- The timezone of the
thing
and its fallbacks. - 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.
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.
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.
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.
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.
Version with getting timezone also if changed on Thing: |
Signed-off-by: Stefan Triller <[email protected]>
Travis tests were successfulHey @t2000, |
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.
LGTM
…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]>
…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]>
…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]>
…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]>
…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]>
…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]>
…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]>
…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]>
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]