-
Notifications
You must be signed in to change notification settings - Fork 780
Feature time of day condition #6465 #6530
Feature time of day condition #6465 #6530
Conversation
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); |
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.
An automation handler is recreated on configuration change. Please extract configuration in the contructor.
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.
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(), |
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.
The error log level is used for serious events only. A user configuration mistake is maximum a warning.
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!
} | ||
|
||
LocalTime currentTime = LocalTime.now().truncatedTo(ChronoUnit.MINUTES); | ||
LocalTime startTime = LocalTime.parse(startTimeConfig).truncatedTo(ChronoUnit.MINUTES); |
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.
Do this conversion in the constructor as well, e.g. can be assigned to final fields.
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.
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>
752a7ab
to
5a02d00
Compare
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.
looks pretty good to me - thanks @Eseraz!
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:
And if you click on 'it is a certain time of day' you will get the configuration dialogue for the newly added TimeOfDayCondition.