Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Feature time of day condition #6465 #6530

Merged
merged 9 commits into from
Nov 29, 2018

Conversation

Eseraz
Copy link
Contributor

@Eseraz Eseraz commented Nov 18, 2018

As suggested in issue #6465, this adds a new type of condition that checks if the current time is in a certain time span. The time span can be configured by the user through a start time and an end time. The condition is able to wrap around the midnight mark, so you can specify times from 19.00 to 01.00 for example.

In Paper UI the selection of conditions looks like this:
condition selection
And if you click on 'it is a certain time of day' you will get the configuration dialogue for the newly added TimeOfDayCondition.
configuration of time condition

This condition checks if the current time is before,
after, or equals to a time, which may be entered by
the user. This is part of eclipse-archived#6465.

Signed-off-by: Dominik Schlierf <dominik.schlierf.esh@web.de>
The time of day condition now compares if the current time is
between a start and end time. Also supports wrapping around midnight,
if the end time is before the start time.

This is part of the issue eclipse-archived#6465.

Signed-off-by: Dominik Schlierf <dominik.schlierf.esh@web.de>
In order to avoid overlapping of time conditions intervals
the condition will no longer return true, if the current time
is equals to the end of the time interval.

This references eclipse-archived#6465 and was implemented due to a suggestion
of @openhab-5iver.

Signed-off-by: Dominik Schlierf <dominik.schlierf.esh@web.de>
Signed-off-by: Dominik Schlierf <dominik.schlierf.esh@web.de>
The launch configuration of the
"org.eclipse.smarthome.automation.module.timer.test.launch" package was
outdated and unable to run. This commit fixes that.

Signed-off-by: Dominik Schlierf <dominik.schlierf.esh@web.de>
The DayOfWeekConditionHandlerTest provides a lot of functionality that may
be used in the TimeOfDayConditionHandlerTest to test feature eclipse-archived#6465. In order to avoid duplicate code, a base class has been extracted.

Also-by: Kai Kreuzer <kai@openhab.org>
Signed-off-by: Dominik Schlierf <dominik.schlierf.esh@web.de>
This is a test that is based on the previously created
BaseConditionHandlerTest. It is used to test the TimeOfDayConditionHandler
which is part of feature eclipse-archived#6465.

Signed-off-by: Dominik Schlierf <dominik.schlierf.esh@web.de>
@Override
public boolean isSatisfied(Map<String, Object> inputs) {

String startTimeConfig = (String) module.getConfiguration().get(START_TIME);
Copy link
Contributor

Choose a reason for hiding this comment

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

An automation handler is recreated on configuration change. Please extract configuration in the contructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know! It is now :)

String startTimeConfig = (String) module.getConfiguration().get(START_TIME);
String endTimeConfig = (String) module.getConfiguration().get(END_TIME);
if (startTimeConfig == null || endTimeConfig == null) {
logger.error("Time condition with id {} is not well configured: startTime={} endTime = {}", module.getId(),
Copy link
Contributor

Choose a reason for hiding this comment

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

The error log level is used for serious events only. A user configuration mistake is maximum a warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok!

}

LocalTime currentTime = LocalTime.now().truncatedTo(ChronoUnit.MINUTES);
LocalTime startTime = LocalTime.parse(startTimeConfig).truncatedTo(ChronoUnit.MINUTES);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do this conversion in the constructor as well, e.g. can be assigned to final fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Added suggestions by @davidgraeff. Improves eclipse-archived#6564.

Signed-off-by: Dominik Schlierf <dominik.schlierf.esh@web.de>
Improves eclipse-archived#6465.

Signed-off-by: Dominik Schlierf <dominik.schlierf.esh@web.de>
@Eseraz Eseraz force-pushed the feature_TimeOfDayCondition branch from 752a7ab to 5a02d00 Compare November 20, 2018 21:16
Copy link
Contributor

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

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

looks pretty good to me - thanks @Eseraz!

@kaikreuzer kaikreuzer merged commit 6253a45 into eclipse-archived:master Nov 29, 2018
@kaikreuzer kaikreuzer added this to the 0.10.0 milestone Dec 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants