Remove deprecated methods from core
This commit is contained in:
parent
70a528c04b
commit
af8f6bcaba
2 changed files with 2 additions and 155 deletions
|
@ -23,7 +23,7 @@ import homeassistant.util.dt as dt_util
|
|||
from homeassistant.helpers.event import track_state_change
|
||||
from homeassistant.const import (
|
||||
__version__, EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP,
|
||||
ATTR_FRIENDLY_NAME, TEMP_CELCIUS,
|
||||
EVENT_STATE_CHANGED, ATTR_FRIENDLY_NAME, TEMP_CELCIUS,
|
||||
TEMP_FAHRENHEIT)
|
||||
|
||||
PST = pytz.timezone('America/Los_Angeles')
|
||||
|
@ -93,65 +93,6 @@ class TestHomeAssistant(unittest.TestCase):
|
|||
|
||||
self.assertEqual(1, len(calls))
|
||||
|
||||
def test_track_point_in_time(self):
|
||||
""" Test track point in time. """
|
||||
before_birthday = datetime(1985, 7, 9, 12, 0, 0, tzinfo=dt_util.UTC)
|
||||
birthday_paulus = datetime(1986, 7, 9, 12, 0, 0, tzinfo=dt_util.UTC)
|
||||
after_birthday = datetime(1987, 7, 9, 12, 0, 0, tzinfo=dt_util.UTC)
|
||||
|
||||
runs = []
|
||||
|
||||
self.hass.track_point_in_utc_time(
|
||||
lambda x: runs.append(1), birthday_paulus)
|
||||
|
||||
self._send_time_changed(before_birthday)
|
||||
self.hass.pool.block_till_done()
|
||||
self.assertEqual(0, len(runs))
|
||||
|
||||
self._send_time_changed(birthday_paulus)
|
||||
self.hass.pool.block_till_done()
|
||||
self.assertEqual(1, len(runs))
|
||||
|
||||
# A point in time tracker will only fire once, this should do nothing
|
||||
self._send_time_changed(birthday_paulus)
|
||||
self.hass.pool.block_till_done()
|
||||
self.assertEqual(1, len(runs))
|
||||
|
||||
self.hass.track_point_in_time(
|
||||
lambda x: runs.append(1), birthday_paulus)
|
||||
|
||||
self._send_time_changed(after_birthday)
|
||||
self.hass.pool.block_till_done()
|
||||
self.assertEqual(2, len(runs))
|
||||
|
||||
def test_track_time_change(self):
|
||||
""" Test tracking time change. """
|
||||
wildcard_runs = []
|
||||
specific_runs = []
|
||||
|
||||
self.hass.track_time_change(lambda x: wildcard_runs.append(1))
|
||||
self.hass.track_utc_time_change(
|
||||
lambda x: specific_runs.append(1), second=[0, 30])
|
||||
|
||||
self._send_time_changed(datetime(2014, 5, 24, 12, 0, 0))
|
||||
self.hass.pool.block_till_done()
|
||||
self.assertEqual(1, len(specific_runs))
|
||||
self.assertEqual(1, len(wildcard_runs))
|
||||
|
||||
self._send_time_changed(datetime(2014, 5, 24, 12, 0, 15))
|
||||
self.hass.pool.block_till_done()
|
||||
self.assertEqual(1, len(specific_runs))
|
||||
self.assertEqual(2, len(wildcard_runs))
|
||||
|
||||
self._send_time_changed(datetime(2014, 5, 24, 12, 0, 30))
|
||||
self.hass.pool.block_till_done()
|
||||
self.assertEqual(2, len(specific_runs))
|
||||
self.assertEqual(3, len(wildcard_runs))
|
||||
|
||||
def _send_time_changed(self, now):
|
||||
""" Send a time changed event. """
|
||||
self.hass.bus.fire(ha.EVENT_TIME_CHANGED, {ha.ATTR_NOW: now})
|
||||
|
||||
|
||||
class TestEvent(unittest.TestCase):
|
||||
""" Test Event class. """
|
||||
|
@ -358,52 +299,11 @@ class TestStateMachine(unittest.TestCase):
|
|||
# If it does not exist, we should get False
|
||||
self.assertFalse(self.states.remove('light.Bowl'))
|
||||
|
||||
def test_track_change(self):
|
||||
""" Test states.track_change. """
|
||||
self.pool.add_worker()
|
||||
|
||||
# 2 lists to track how often our callbacks got called
|
||||
specific_runs = []
|
||||
wildcard_runs = []
|
||||
|
||||
self.states.track_change(
|
||||
'light.Bowl', lambda a, b, c: specific_runs.append(1), 'on', 'off')
|
||||
|
||||
self.states.track_change(
|
||||
'light.Bowl', lambda a, b, c: wildcard_runs.append(1),
|
||||
ha.MATCH_ALL, ha.MATCH_ALL)
|
||||
|
||||
# Set same state should not trigger a state change/listener
|
||||
self.states.set('light.Bowl', 'on')
|
||||
self.bus._pool.block_till_done()
|
||||
self.assertEqual(0, len(specific_runs))
|
||||
self.assertEqual(0, len(wildcard_runs))
|
||||
|
||||
# State change off -> on
|
||||
self.states.set('light.Bowl', 'off')
|
||||
self.bus._pool.block_till_done()
|
||||
self.assertEqual(1, len(specific_runs))
|
||||
self.assertEqual(1, len(wildcard_runs))
|
||||
|
||||
# State change off -> off
|
||||
self.states.set('light.Bowl', 'off', {"some_attr": 1})
|
||||
self.bus._pool.block_till_done()
|
||||
self.assertEqual(1, len(specific_runs))
|
||||
self.assertEqual(2, len(wildcard_runs))
|
||||
|
||||
# State change off -> on
|
||||
self.states.set('light.Bowl', 'on')
|
||||
self.bus._pool.block_till_done()
|
||||
self.assertEqual(1, len(specific_runs))
|
||||
self.assertEqual(3, len(wildcard_runs))
|
||||
|
||||
def test_case_insensitivty(self):
|
||||
self.pool.add_worker()
|
||||
runs = []
|
||||
|
||||
track_state_change(
|
||||
ha._MockHA(self.bus), 'light.BoWl', lambda a, b, c: runs.append(1),
|
||||
ha.MATCH_ALL, ha.MATCH_ALL)
|
||||
self.bus.listen(EVENT_STATE_CHANGED, lambda event: runs.append(event))
|
||||
|
||||
self.states.set('light.BOWL', 'off')
|
||||
self.bus._pool.block_till_done()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue