Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions appdaemontestframework/hass_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import mock
from appdaemon.plugins.hass.hassapi import Hass
from packaging.version import Version
import uuid

CURRENT_APPDAEMON_VERSION = Version(appdaemon.utils.__version__)

Expand Down Expand Up @@ -82,17 +83,17 @@ def _hass_init_mock(self, _ad, name, *_args):
# Wrap all these so we can re-use the AppDaemon code, but check
# if they were called
SpyMockHandler(Hass, 'run_in'),
MockHandler(Hass, 'run_once'),
MockHandler(Hass, 'run_at'),
MockHandler(Hass, 'run_daily'),
MockHandler(Hass, 'run_hourly'),
MockHandler(Hass, 'run_minutely'),
MockHandler(Hass, 'run_every'),
MockHandler(Hass, 'run_once', side_effect=self._uuid4),
MockHandler(Hass, 'run_at', side_effect=self._uuid4),
MockHandler(Hass, 'run_daily', side_effect=self._uuid4),
MockHandler(Hass, 'run_hourly', side_effect=self._uuid4),
MockHandler(Hass, 'run_minutely', side_effect=self._uuid4),
MockHandler(Hass, 'run_every', side_effect=self._uuid4),
SpyMockHandler(Hass, 'cancel_timer'),

### Sunrise and sunset functions
MockHandler(Hass, 'run_at_sunrise'),
MockHandler(Hass, 'run_at_sunset'),
MockHandler(Hass, 'run_at_sunrise', side_effect=self._uuid4),
MockHandler(Hass, 'run_at_sunset', side_effect=self._uuid4),

### Listener callback registrations functions
MockHandler(Hass, 'listen_event'),
Expand Down Expand Up @@ -149,6 +150,10 @@ def _log_log(msg, level='INFO'):
get_logging_level_from_name = logging.getLevelName
logging.log(get_logging_level_from_name(level), msg)

def _uuid4(*args, **kwargs):
#return uuid4 for handle identification
return uuid.uuid4()


class MockHandler:
"""
Expand Down
Loading