-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8d1b54
commit 400d1dd
Showing
4 changed files
with
57 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from datetime import timedelta | ||
from time import sleep | ||
|
||
from HABAppTests import OpenhabTmpItem, TestBaseRule | ||
|
||
from HABApp.core.events import ValueUpdateEventFilter | ||
from HABApp.core.items.base_valueitem import datetime | ||
from HABApp.openhab.items import DatetimeItem | ||
|
||
|
||
class TestSchedulerOhInteraction(TestBaseRule): | ||
def __init__(self) -> None: | ||
super().__init__() | ||
|
||
self.add_test('Test scheduler oh_item', self.test_scheduler_every) | ||
|
||
@OpenhabTmpItem.create('DateTime', arg_name='tmp_item') | ||
def test_scheduler_every(self, tmp_item: OpenhabTmpItem) -> None: | ||
|
||
item_states = [] | ||
item = DatetimeItem.get_item(tmp_item.name) | ||
listener = item.listen_event(lambda x: item_states.append(x), ValueUpdateEventFilter()) | ||
|
||
next_hour = datetime.now().replace(second=0, microsecond=0) + timedelta(hours=1) | ||
|
||
try: | ||
job = self.run.once(next_hour, lambda: 1/0) | ||
job.to_item(item) | ||
job.cancel() | ||
sleep(0.2) | ||
finally: | ||
listener.cancel() | ||
|
||
assert item_states == [next_hour, None] | ||
|
||
|
||
TestSchedulerOhInteraction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters