-
-
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
[ntp] Clean up #7834
[ntp] Clean up #7834
Conversation
Binding fully retested with these changes. |
I need to adjust the integration tests. |
Add null annotations Suppress one unused configutation setting (locale) Get the default timezone from TimeZoneProvider Map thing configuration and channel configuration to classes Signed-off-by: Laurent Garnier <[email protected]>
6f89095
to
04af195
Compare
Integration tests now ok again. |
private static final int DEFAULT_REFRESH_NTP = 30; | ||
private static final int DEFAULT_SERVER_PORT = 123; | ||
|
||
public @Nullable String hostname; |
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.
Why don't you use something like
public @Nullable String hostname; | |
public String hostname = "0.pool.ntp.org"; |
You can skip the whole logic below then and directly access the fields in the code. If the user sets set parameter, the default is overwritten.
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.
Ok, fixed.
private static final int DEFAULT_SERVER_PORT = 123; | ||
|
||
public @Nullable String hostname; | ||
public @Nullable Integer refreshInterval; |
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.
public @Nullable Integer refreshInterval; | |
public int refreshInterval = 60; |
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.
Ok, fixed.
@@ -44,12 +48,12 @@ public NtpDiscovery() throws IllegalArgumentException { | |||
} | |||
|
|||
@Override | |||
protected void activate(Map<String, Object> configProperties) { | |||
protected void activate(@Nullable Map<String, @Nullable Object> configProperties) { |
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.
Why is this needed at all? It only calls the method it overrides
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 should refactor this call and rather use injection.
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.
Constructor injection done.
@@ -54,217 +54,183 @@ | |||
* to one of the channels. | |||
* | |||
* @author Marcel Verpaalen - Initial contribution OH2 ntp binding | |||
* @author Thomas.Eichstaedt-Engelen OH1 ntp binding (getTime routine) | |||
* @author Thomas.Eichstaedt - Engelen OH1 ntp binding (getTime routine) |
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 looks wrong. Thomas's last name is "Eichstaedt-Engelen", so the spaces arounf the dash are wrong.
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.
There was a warning on this line but my change was stupid.
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.
Fixed
|
||
/** for publish purposes */ | ||
private DateTimeFormatter dateTimeFormat = DateTimeFormatter.ofPattern(DATE_PATTERN_WITH_TZ); | ||
|
||
private final LocaleProvider localeProvider; | ||
private @Nullable NtpThingConfiguration configuration; |
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.
Since all values have reasonable defaults, you can skip null checks by using
private @Nullable NtpThingConfiguration configuration; | |
private NtpThingConfiguration configuration = new NtpThingConfiguration(); |
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.
Ok, done.
NtpThingConfiguration config = getConfigAs(NtpThingConfiguration.class); | ||
configuration = config; |
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.
Why not use
NtpThingConfiguration config = getConfigAs(NtpThingConfiguration.class); | |
configuration = config; | |
configuration = getConfigAs(NtpThingConfiguration.class); |
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 to avoid null check warnings due to configuration which was nullable.
Now that configuration is non null, the local variable can be avoided.
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.
Local variable removed.
|
||
String timeZoneConfigValue = config.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.
If you use the defaults directly, you can access the fields here and omit most of the null checks/function calls.
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 can't define a default for the configuration because the expected default is the timezone provided by the TimeZoneProvider.
logger.debug("{} using default locale '{}', because configuration property '{}' is null.", | ||
getThing().getUID(), locale, PROPERTY_LOCALE); | ||
} | ||
timeZoneId = TimeZone.getTimeZone(timeZoneConfigValue).toZoneId(); | ||
} catch (Exception e) { |
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.
Is it necessary to catch Exception
here?
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.
You're right, it is not necessary because it returns GMT if the string is invalid.
Fixed.
@@ -37,14 +37,5 @@ | |||
public static final String CHANNEL_DATE_TIME = "dateTime"; | |||
public static final String CHANNEL_STRING = "string"; | |||
|
|||
// Custom Properties | |||
public static final String PROPERTY_NTP_SERVER_HOST = "hostname"; |
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 would prefer to keep the constants here, as that is what is most common in other bindings.
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 often saw the constants defined in th econfiguration class too.
But ok, I revert.
888c605
to
18f34f2
Compare
java.util.TimeZone is no more used. |
Use constructor injection for the discovery service Signed-off-by: Laurent Garnier <[email protected]>
18f34f2
to
c0e2029
Compare
Travis tests have failedHey @lolodomo, |
I have to test again but it is possible that parsing of the timezone configuration setting using |
New timezone parsing is working well. In fact |
And the full build is green. |
Signed-off-by: Laurent Garnier <[email protected]>
Travis tests have failedHey @lolodomo, |
1 similar comment
Travis tests have failedHey @lolodomo, |
Signed-off-by: Laurent Garnier <[email protected]>
This is not yet good as TimeZoneProvider is considered only at thing handler initialization. |
Signed-off-by: Laurent Garnier <[email protected]>
I tested how the binding is behaving with these changes when no timezone is set on the thing side but the user changes the openHAB system timezone. And this is working well, the openHAB system timezone is correctly taken into accound when the date/time is updated by the binding. |
@J-N-K : could you please finish your review or more exactly review my changes after your first review ? |
Signed-off-by: Laurent Garnier <[email protected]>
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
@J-N-K can you take a final look? |
Can we have this PR merged before 2.5.6 is released? |
@J-N-K friendly ping |
* [ntp] Clean up Add null annotations Suppress one unused configutation setting (locale) Get the default timezone from TimeZoneProvider Map thing configuration and channel configuration to classes Use constructor injection for the discovery service * Use TimeZoneProvider each time the timezone is required * Call activate in the discovery service constructor Signed-off-by: Laurent Garnier <[email protected]>
* [ntp] Clean up Add null annotations Suppress one unused configutation setting (locale) Get the default timezone from TimeZoneProvider Map thing configuration and channel configuration to classes Use constructor injection for the discovery service * Use TimeZoneProvider each time the timezone is required * Call activate in the discovery service constructor Signed-off-by: Laurent Garnier <[email protected]> Signed-off-by: CSchlipp <[email protected]>
* [ntp] Clean up Add null annotations Suppress one unused configutation setting (locale) Get the default timezone from TimeZoneProvider Map thing configuration and channel configuration to classes Use constructor injection for the discovery service * Use TimeZoneProvider each time the timezone is required * Call activate in the discovery service constructor Signed-off-by: Laurent Garnier <[email protected]> Signed-off-by: MPH80 <[email protected]>
* [ntp] Clean up Add null annotations Suppress one unused configutation setting (locale) Get the default timezone from TimeZoneProvider Map thing configuration and channel configuration to classes Use constructor injection for the discovery service * Use TimeZoneProvider each time the timezone is required * Call activate in the discovery service constructor Signed-off-by: Laurent Garnier <[email protected]>
* [ntp] Clean up Add null annotations Suppress one unused configutation setting (locale) Get the default timezone from TimeZoneProvider Map thing configuration and channel configuration to classes Use constructor injection for the discovery service * Use TimeZoneProvider each time the timezone is required * Call activate in the discovery service constructor Signed-off-by: Laurent Garnier <[email protected]>
* [ntp] Clean up Add null annotations Suppress one unused configutation setting (locale) Get the default timezone from TimeZoneProvider Map thing configuration and channel configuration to classes Use constructor injection for the discovery service * Use TimeZoneProvider each time the timezone is required * Call activate in the discovery service constructor Signed-off-by: Laurent Garnier <[email protected]>
* [ntp] Clean up Add null annotations Suppress one unused configutation setting (locale) Get the default timezone from TimeZoneProvider Map thing configuration and channel configuration to classes Use constructor injection for the discovery service * Use TimeZoneProvider each time the timezone is required * Call activate in the discovery service constructor Signed-off-by: Laurent Garnier <[email protected]>
* [ntp] Clean up Add null annotations Suppress one unused configutation setting (locale) Get the default timezone from TimeZoneProvider Map thing configuration and channel configuration to classes Use constructor injection for the discovery service * Use TimeZoneProvider each time the timezone is required * Call activate in the discovery service constructor Signed-off-by: Laurent Garnier <[email protected]> Signed-off-by: Daan Meijer <[email protected]>
* [ntp] Clean up Add null annotations Suppress one unused configutation setting (locale) Get the default timezone from TimeZoneProvider Map thing configuration and channel configuration to classes Use constructor injection for the discovery service * Use TimeZoneProvider each time the timezone is required * Call activate in the discovery service constructor Signed-off-by: Laurent Garnier <[email protected]>
Add null annotations
Suppress one unused configutation setting (locale)
Get the default timezone from TimeZoneProvider
Map thing configuration and channel configuration to classes
Use constructor injection for the discovery service
Signed-off-by: Laurent Garnier [email protected]