mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fix device scanner test
This commit is contained in:
parent
46834aa0a5
commit
d3f1b83e57
@ -117,9 +117,17 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
|||||||
dev3 = device_tracker.ENTITY_ID_FORMAT.format('DEV3')
|
dev3 = device_tracker.ENTITY_ID_FORMAT.format('DEV3')
|
||||||
|
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
nowAlmostMinGone = (now + device_tracker.TIME_DEVICE_NOT_FOUND -
|
|
||||||
timedelta(seconds=1))
|
# Device scanner scans every 12 seconds. We need to sync our times to
|
||||||
nowMinGone = nowAlmostMinGone + timedelta(seconds=2)
|
# be every 12 seconds or else the time_changed event will be ignored.
|
||||||
|
nowAlmostMinimumGone = now + device_tracker.TIME_DEVICE_NOT_FOUND
|
||||||
|
nowAlmostMinimumGone -= timedelta(
|
||||||
|
seconds=(nowAlmostMinimumGone.second % 12))
|
||||||
|
|
||||||
|
nowMinimumGone = now + device_tracker.TIME_DEVICE_NOT_FOUND
|
||||||
|
nowMinimumGone += timedelta(seconds=12-(nowMinimumGone.second % 12))
|
||||||
|
|
||||||
|
print(now, nowAlmostMinimumGone, nowMinimumGone)
|
||||||
|
|
||||||
# Test initial is correct
|
# Test initial is correct
|
||||||
self.assertTrue(device_tracker.is_on(self.hass))
|
self.assertTrue(device_tracker.is_on(self.hass))
|
||||||
@ -168,7 +176,7 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
|||||||
|
|
||||||
# Test if device leaves what happens, test the time span
|
# Test if device leaves what happens, test the time span
|
||||||
self.hass.bus.fire(
|
self.hass.bus.fire(
|
||||||
ha.EVENT_TIME_CHANGED, {ha.ATTR_NOW: nowAlmostMinGone})
|
ha.EVENT_TIME_CHANGED, {ha.ATTR_NOW: nowAlmostMinimumGone})
|
||||||
|
|
||||||
self.hass.pool.block_till_done()
|
self.hass.pool.block_till_done()
|
||||||
|
|
||||||
@ -179,7 +187,8 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
|||||||
self.assertTrue(device_tracker.is_on(self.hass, dev3))
|
self.assertTrue(device_tracker.is_on(self.hass, dev3))
|
||||||
|
|
||||||
# Now test if gone for longer then error margin
|
# Now test if gone for longer then error margin
|
||||||
self.hass.bus.fire(ha.EVENT_TIME_CHANGED, {ha.ATTR_NOW: nowMinGone})
|
self.hass.bus.fire(
|
||||||
|
ha.EVENT_TIME_CHANGED, {ha.ATTR_NOW: nowMinimumGone})
|
||||||
|
|
||||||
self.hass.pool.block_till_done()
|
self.hass.pool.block_till_done()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user