test_device.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. from time import time
  2. from unittest import IsolatedAsyncioTestCase
  3. from unittest.mock import ANY, AsyncMock, Mock, call, patch
  4. from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP
  5. from custom_components.tuya_local.device import TuyaLocalDevice
  6. from .const import EUROM_600_HEATER_PAYLOAD
  7. class TestDevice(IsolatedAsyncioTestCase):
  8. def setUp(self):
  9. device_patcher = patch("tinytuya.Device")
  10. self.addCleanup(device_patcher.stop)
  11. self.mock_api = device_patcher.start()
  12. self.mock_api().parent = None
  13. hass_patcher = patch("homeassistant.core.HomeAssistant")
  14. self.addCleanup(hass_patcher.stop)
  15. self.hass = hass_patcher.start()
  16. self.hass().is_running = True
  17. self.hass().is_stopping = False
  18. self.hass().data = {"tuya_local": {}}
  19. def job(func, *args):
  20. return func(*args)
  21. self.hass().async_add_executor_job = AsyncMock()
  22. self.hass().async_add_executor_job.side_effect = job
  23. sleep_patcher = patch("asyncio.sleep")
  24. self.addCleanup(sleep_patcher.stop)
  25. self.mock_sleep = sleep_patcher.start()
  26. lock_patcher = patch("custom_components.tuya_local.device.Lock")
  27. self.addCleanup(lock_patcher.stop)
  28. self.mock_lock = lock_patcher.start()
  29. self.subject = TuyaLocalDevice(
  30. "Some name",
  31. "some_dev_id",
  32. "some.ip.address",
  33. "some_local_key",
  34. "auto",
  35. None,
  36. self.hass(),
  37. )
  38. # For most tests we want the protocol working
  39. self.subject._api_protocol_version_index = 0
  40. self.subject._api_protocol_working = True
  41. self.subject._protocol_configured = "auto"
  42. def test_configures_tinytuya_correctly(self):
  43. self.mock_api.assert_called_with(
  44. "some_dev_id", "some.ip.address", "some_local_key"
  45. )
  46. self.assertIs(self.subject._api, self.mock_api())
  47. def test_name(self):
  48. """Returns the name given at instantiation."""
  49. self.assertEqual(self.subject.name, "Some name")
  50. def test_unique_id(self):
  51. """Returns the unique ID presented by the API class."""
  52. self.assertIs(self.subject.unique_id, self.mock_api().id)
  53. def test_device_info(self):
  54. """Returns generic info plus the unique ID for categorisation."""
  55. self.assertEqual(
  56. self.subject.device_info,
  57. {
  58. "identifiers": {("tuya_local", self.mock_api().id)},
  59. "name": "Some name",
  60. "manufacturer": "Tuya",
  61. },
  62. )
  63. def test_has_returned_state(self):
  64. """Returns True if the device has returned its state."""
  65. self.subject._cached_state = EUROM_600_HEATER_PAYLOAD
  66. self.assertTrue(self.subject.has_returned_state)
  67. self.subject._cached_state = {"updated_at": 0}
  68. self.assertFalse(self.subject.has_returned_state)
  69. async def test_refreshes_state_if_no_cached_state_exists(self):
  70. self.subject._cached_state = {}
  71. self.subject.async_refresh = AsyncMock()
  72. await self.subject.async_inferred_type()
  73. self.subject.async_refresh.assert_awaited()
  74. async def test_detection_returns_none_when_device_type_not_detected(self):
  75. self.subject._cached_state = {"192": False, "updated_at": time()}
  76. self.assertEqual(await self.subject.async_inferred_type(), None)
  77. async def test_refreshes_when_there_is_no_pending_reset(self):
  78. self.subject._cached_state = {"updated_at": time() - 19}
  79. self.mock_api().status.return_value = {"dps": {"1": "called"}}
  80. await self.subject.async_refresh()
  81. self.mock_api().status.assert_called_once()
  82. self.assertEqual(self.subject._cached_state["1"], "called")
  83. async def test_refreshes_when_there_is_expired_pending_reset(self):
  84. self.subject._cached_state = {"updated_at": time() - 20}
  85. self.mock_api().status.return_value = {"dps": {"1": "called"}}
  86. await self.subject.async_refresh()
  87. self.mock_api().status.assert_called_once()
  88. self.assertEqual(self.subject._cached_state["1"], "called")
  89. async def test_refresh_retries_up_to_eleven_times(self):
  90. self.subject._api_protocol_working = False
  91. self.mock_api().status.side_effect = [
  92. Exception("Error"),
  93. Exception("Error"),
  94. Exception("Error"),
  95. Exception("Error"),
  96. Exception("Error"),
  97. Exception("Error"),
  98. Exception("Error"),
  99. Exception("Error"),
  100. Exception("Error"),
  101. Exception("Error"),
  102. {"dps": {"1": False}},
  103. ]
  104. await self.subject.async_refresh()
  105. self.assertEqual(self.mock_api().status.call_count, 11)
  106. self.assertEqual(self.subject._cached_state["1"], False)
  107. async def test_refresh_clears_cache_after_allowed_failures(self):
  108. self.subject._cached_state = {"1": True}
  109. self.subject._pending_updates = {
  110. "1": {"value": False, "updated_at": time(), "sent": True}
  111. }
  112. self.mock_api().status.side_effect = [
  113. Exception("Error"),
  114. Exception("Error"),
  115. Exception("Error"),
  116. ]
  117. await self.subject.async_refresh()
  118. self.assertEqual(self.mock_api().status.call_count, 3)
  119. self.assertEqual(self.subject._cached_state, {"updated_at": 0})
  120. self.assertEqual(self.subject._pending_updates, {})
  121. async def test_api_protocol_version_is_rotated_with_each_failure(self):
  122. self.subject._api_protocol_version_index = None
  123. self.subject._api_protocol_working = False
  124. self.mock_api().status.side_effect = [
  125. Exception("Error"),
  126. Exception("Error"),
  127. Exception("Error"),
  128. Exception("Error"),
  129. Exception("Error"),
  130. Exception("Error"),
  131. Exception("Error"),
  132. ]
  133. await self.subject.async_refresh()
  134. self.mock_api().set_version.assert_has_calls(
  135. [call(3.1), call(3.2), call(3.4), call(3.5), call(3.3), call(3.1)]
  136. )
  137. async def test_api_protocol_version_is_stable_once_successful(self):
  138. self.subject._api_protocol_version_index = None
  139. self.subject._api_protocol_working = False
  140. self.mock_api().status.side_effect = [
  141. Exception("Error"),
  142. Exception("Error"),
  143. Exception("Error"),
  144. {"dps": {"1": False}},
  145. {"dps": {"1": False}},
  146. Exception("Error"),
  147. Exception("Error"),
  148. {"dps": {"1": False}},
  149. ]
  150. await self.subject.async_refresh()
  151. self.assertEqual(self.subject._api_protocol_version_index, 3)
  152. self.assertTrue(self.subject._api_protocol_working)
  153. await self.subject.async_refresh()
  154. self.assertEqual(self.subject._api_protocol_version_index, 3)
  155. await self.subject.async_refresh()
  156. self.assertEqual(self.subject._api_protocol_version_index, 3)
  157. self.mock_api().set_version.assert_has_calls(
  158. [
  159. call(3.1),
  160. call(3.2),
  161. call(3.4),
  162. ]
  163. )
  164. async def test_api_protocol_version_is_not_rotated_when_not_auto(self):
  165. # Set up preconditions for the test
  166. self.subject._protocol_configured = 3.4
  167. self.subject._api_protocol_version_index = None
  168. self.subject._api_protocol_working = False
  169. self.mock_api().status.side_effect = [
  170. Exception("Error"),
  171. Exception("Error"),
  172. Exception("Error"),
  173. {"dps": {"1": False}},
  174. {"dps": {"1": False}},
  175. Exception("Error"),
  176. Exception("Error"),
  177. Exception("Error"),
  178. Exception("Error"),
  179. Exception("Error"),
  180. Exception("Error"),
  181. Exception("Error"),
  182. {"dps": {"1": False}},
  183. ]
  184. await self.subject._rotate_api_protocol_version()
  185. self.mock_api().set_version.assert_called_once_with(3.4)
  186. self.mock_api().set_version.reset_mock()
  187. await self.subject.async_refresh()
  188. self.assertEqual(self.subject._api_protocol_version_index, 3)
  189. await self.subject.async_refresh()
  190. self.assertEqual(self.subject._api_protocol_version_index, 3)
  191. await self.subject.async_refresh()
  192. self.assertEqual(self.subject._api_protocol_version_index, 3)
  193. def test_reset_cached_state_clears_cached_state_and_pending_updates(self):
  194. self.subject._cached_state = {"1": True, "updated_at": time()}
  195. self.subject._pending_updates = {
  196. "1": {"value": False, "updated_at": time(), "sent": True}
  197. }
  198. self.subject._reset_cached_state()
  199. self.assertEqual(self.subject._cached_state, {"updated_at": 0})
  200. self.assertEqual(self.subject._pending_updates, {})
  201. def test_get_property_returns_value_from_cached_state(self):
  202. self.subject._cached_state = {"1": True}
  203. self.assertEqual(self.subject.get_property("1"), True)
  204. def test_get_property_returns_pending_update_value(self):
  205. self.subject._pending_updates = {
  206. "1": {"value": False, "updated_at": time() - 4, "sent": True}
  207. }
  208. self.assertEqual(self.subject.get_property("1"), False)
  209. def test_pending_update_value_overrides_cached_value(self):
  210. self.subject._cached_state = {"1": True}
  211. self.subject._pending_updates = {
  212. "1": {"value": False, "updated_at": time() - 4, "sent": True}
  213. }
  214. self.assertEqual(self.subject.get_property("1"), False)
  215. def test_expired_pending_update_value_does_not_override_cached_value(self):
  216. self.subject._cached_state = {"1": True}
  217. self.subject._pending_updates = {
  218. "1": {"value": False, "updated_at": time() - 5, "sent": True}
  219. }
  220. self.assertEqual(self.subject.get_property("1"), True)
  221. def test_get_property_returns_none_when_value_does_not_exist(self):
  222. self.subject._cached_state = {"1": True}
  223. self.assertIs(self.subject.get_property("2"), None)
  224. async def test_async_set_property_sends_to_api(self):
  225. await self.subject.async_set_property("1", False)
  226. self.mock_api().set_multiple_values.assert_called_once()
  227. async def test_set_property_immediately_stores_pending_updates(self):
  228. self.subject._cached_state = {"1": True}
  229. await self.subject.async_set_property("1", False)
  230. self.assertFalse(self.subject.get_property("1"))
  231. async def test_set_properties_takes_no_action_when_nothing_provided(self):
  232. with patch("asyncio.sleep") as mock:
  233. await self.subject.async_set_properties({})
  234. mock.assert_not_called()
  235. def test_anticipate_property_value_updates_cached_state(self):
  236. self.subject._cached_state = {"1": True}
  237. self.subject.anticipate_property_value("1", False)
  238. self.assertEqual(self.subject._cached_state["1"], False)
  239. def test_get_key_for_value_returns_key_from_object_matching_value(self):
  240. obj = {"key1": "value1", "key2": "value2"}
  241. self.assertEqual(
  242. TuyaLocalDevice.get_key_for_value(obj, "value1"),
  243. "key1",
  244. )
  245. self.assertEqual(
  246. TuyaLocalDevice.get_key_for_value(obj, "value2"),
  247. "key2",
  248. )
  249. def test_get_key_for_value_returns_fallback_when_value_not_found(self):
  250. obj = {"key1": "value1", "key2": "value2"}
  251. self.assertEqual(
  252. TuyaLocalDevice.get_key_for_value(obj, "value3", fallback="fb"),
  253. "fb",
  254. )
  255. def test_refresh_cached_state(self):
  256. # set up preconditions
  257. self.mock_api().status.return_value = {"dps": {"1": "CHANGED"}}
  258. self.subject._cached_state = {"1": "UNCHANGED", "updated_at": 123}
  259. # call the function under test
  260. self.subject._refresh_cached_state()
  261. # Did it call the API as expected?
  262. self.mock_api().status.assert_called_once()
  263. # Did it update the cached state?
  264. self.assertDictEqual(
  265. self.subject._cached_state,
  266. {"1": "CHANGED"} | self.subject._cached_state,
  267. )
  268. # Did it update the timestamp on the cached state?
  269. self.assertAlmostEqual(
  270. self.subject._cached_state["updated_at"],
  271. time(),
  272. delta=2,
  273. )
  274. def test_set_values(self):
  275. # set up preconditions
  276. self.subject._pending_updates = {
  277. "1": {"value": "sample", "updated_at": time() - 2, "sent": False},
  278. }
  279. # call the function under test
  280. self.subject._set_values({"1": "sample"})
  281. # did it send what it was asked?
  282. self.mock_api().set_multiple_values.assert_called_once_with(
  283. {"1": "sample"}, nowait=True
  284. )
  285. # did it mark the pending updates as sent?
  286. self.assertTrue(self.subject._pending_updates["1"]["sent"])
  287. # did it update the time on the pending updates?
  288. self.assertAlmostEqual(
  289. self.subject._pending_updates["1"]["updated_at"],
  290. time(),
  291. delta=2,
  292. )
  293. # did it lock and unlock when sending
  294. self.subject._lock.acquire.assert_called_once()
  295. self.subject._lock.release.assert_called_once()
  296. def test_pending_updates_cleared_on_receipt(self):
  297. # Set up the preconditions
  298. now = time()
  299. self.subject._pending_updates = {
  300. "1": {"value": True, "updated_at": now, "sent": True},
  301. "2": {"value": True, "updated_at": now, "sent": False}, # unsent
  302. "3": {"value": True, "updated_at": now, "sent": True}, # unmatched
  303. "4": {"value": True, "updated_at": now, "sent": True}, # not received
  304. }
  305. self.subject._remove_properties_from_pending_updates(
  306. {"1": True, "2": True, "3": False}
  307. )
  308. self.assertDictEqual(
  309. self.subject._pending_updates,
  310. {
  311. "2": {"value": True, "updated_at": now, "sent": False},
  312. "3": {"value": True, "updated_at": now, "sent": True},
  313. "4": {"value": True, "updated_at": now, "sent": True},
  314. },
  315. )
  316. def test_actually_start(self):
  317. # Set up the preconditions
  318. self.subject.receive_loop = AsyncMock()
  319. self.subject.receive_loop.return_value = "LOOP"
  320. self.hass().bus.async_listen_once.return_value = "LISTENER"
  321. self.subject._running = False
  322. # run the function under test
  323. self.subject.actually_start()
  324. # did it register a listener for EVENT_HOMEASSISTANT_STOP?
  325. self.hass().bus.async_listen_once.assert_called_once_with(
  326. EVENT_HOMEASSISTANT_STOP, self.subject.async_stop
  327. )
  328. self.assertEqual(self.subject._shutdown_listener, "LISTENER")
  329. # did it set the running flag?
  330. self.assertTrue(self.subject._running)
  331. # did it schedule the loop?
  332. # self.hass().async_create_task.assert_called_once()
  333. def test_start_starts_when_ha_running(self):
  334. # Set up preconditions
  335. self.hass().is_running = True
  336. listener = Mock()
  337. self.subject._startup_listener = listener
  338. self.subject.actually_start = Mock()
  339. # Call the function under test
  340. self.subject.start()
  341. # Did it actually start?
  342. self.subject.actually_start.assert_called_once()
  343. # Did it cancel the startup listener?
  344. self.assertIsNone(self.subject._startup_listener)
  345. listener.assert_called_once()
  346. def test_start_schedules_for_later_when_ha_starting(self):
  347. # Set up preconditions
  348. self.hass().is_running = False
  349. self.hass().bus.async_listen_once.return_value = "LISTENER"
  350. self.subject.actually_start = Mock()
  351. # Call the function under test
  352. self.subject.start()
  353. # Did it avoid actually starting?
  354. self.subject.actually_start.assert_not_called()
  355. # Did it register a listener?
  356. self.assertEqual(self.subject._startup_listener, "LISTENER")
  357. self.hass().bus.async_listen_once.assert_called_once_with(
  358. EVENT_HOMEASSISTANT_STARTED, self.subject.actually_start
  359. )
  360. def test_start_does_nothing_when_ha_stopping(self):
  361. # Set up preconditions
  362. self.hass().is_running = True
  363. self.hass().is_stopping = True
  364. self.subject.actually_start = Mock()
  365. # Call the function under test
  366. self.subject.start()
  367. # Did it avoid actually starting?
  368. self.subject.actually_start.assert_not_called()
  369. # Did it avoid registering a listener?
  370. self.hass().bus.async_listen_once.assert_not_called()
  371. self.assertIsNone(self.subject._startup_listener)
  372. async def test_async_stop(self):
  373. # Set up preconditions
  374. listener = Mock()
  375. self.subject._refresh_task = None
  376. self.subject._shutdown_listener = listener
  377. self.subject._children = [1, 2, 3]
  378. # Call the function under test
  379. await self.subject.async_stop()
  380. # Shutdown listener doesn't get cancelled as HA does that
  381. listener.assert_not_called()
  382. # Were the child entities cleared?
  383. self.assertEqual(self.subject._children, [])
  384. # Did it wait for the refresh task to finish then clear it?
  385. # This doesn't work because AsyncMock only mocks awaitable method calls
  386. # but we want an awaitable object
  387. # refresh.assert_awaited_once()
  388. self.assertIsNone(self.subject._refresh_task)
  389. async def test_async_stop_when_not_running(self):
  390. # Set up preconditions
  391. self._refresh_task = None
  392. self.subject._shutdown_listener = None
  393. self.subject._children = []
  394. # Call the function under test
  395. await self.subject.async_stop()
  396. # Was the shutdown listener left empty?
  397. self.assertIsNone(self.subject._shutdown_listener)
  398. # Were the child entities cleared?
  399. self.assertEqual(self.subject._children, [])
  400. # Was the refresh task left empty?
  401. self.assertIsNone(self.subject._refresh_task)
  402. def test_register_first_entity_ha_running(self):
  403. # Set up preconditions
  404. self.subject._children = []
  405. self.subject._running = False
  406. self.subject._startup_listener = None
  407. self.subject.start = Mock()
  408. entity = AsyncMock()
  409. entity._config = Mock()
  410. entity._config.dps.return_value = []
  411. # despite the name, the below HA function is not async and does not need to be awaited
  412. entity.async_schedule_update_ha_state = Mock()
  413. # Call the function under test
  414. self.subject.register_entity(entity)
  415. # Was the entity added to the list?
  416. self.assertEqual(self.subject._children, [entity])
  417. # Did we start the loop?
  418. self.subject.start.assert_called_once()
  419. def test_register_subsequent_entity_ha_running(self):
  420. # Set up preconditions
  421. first = AsyncMock()
  422. second = AsyncMock()
  423. second._config = Mock()
  424. second._config.dps.return_value = []
  425. self.subject._children = [first]
  426. self.subject._running = True
  427. self.subject._startup_listener = None
  428. self.subject.start = Mock()
  429. # Call the function under test
  430. self.subject.register_entity(second)
  431. # Was the entity added to the list?
  432. self.assertCountEqual(self.subject._children, [first, second])
  433. # Did we avoid restarting the loop?
  434. self.subject.start.assert_not_called()
  435. def test_register_subsequent_entity_ha_starting(self):
  436. # Set up preconditions
  437. first = AsyncMock()
  438. second = AsyncMock()
  439. second._config = Mock()
  440. second._config.dps.return_value = []
  441. self.subject._children = [first]
  442. self.subject._running = False
  443. self.subject._startup_listener = Mock()
  444. self.subject.start = Mock()
  445. # Call the function under test
  446. self.subject.register_entity(second)
  447. # Was the entity added to the list?
  448. self.assertCountEqual(self.subject._children, [first, second])
  449. # Did we avoid restarting the loop?
  450. self.subject.start.assert_not_called()
  451. async def test_unregister_one_of_many_entities(self):
  452. # Set up preconditions
  453. self.subject._children = ["First", "Second"]
  454. self.subject.async_stop = AsyncMock()
  455. # Call the function under test
  456. await self.subject.async_unregister_entity("First")
  457. # Was the entity removed from the list?
  458. self.assertCountEqual(self.subject._children, ["Second"])
  459. # Is the loop still running?
  460. self.subject.async_stop.assert_not_called()
  461. async def test_unregister_last_entity(self):
  462. # Set up preconditions
  463. self.subject._children = ["Last"]
  464. self.subject.async_stop = AsyncMock()
  465. # Call the function under test
  466. await self.subject.async_unregister_entity("Last")
  467. # Was the entity removed from the list?
  468. self.assertEqual(self.subject._children, [])
  469. # Was the loop stopped?
  470. self.subject.async_stop.assert_called_once()
  471. async def test_async_receive(self):
  472. # Set up preconditions
  473. self.mock_api().status.return_value = {"dps": {"1": "INIT", "2": 2}}
  474. self.mock_api().receive.return_value = {"1": "UPDATED"}
  475. self.subject._running = True
  476. self.subject._cached_state = {"updated_at": 0}
  477. # Call the function under test
  478. print("starting test loop...")
  479. loop = self.subject.async_receive()
  480. print("getting first iteration...")
  481. result = await loop.__anext__()
  482. # Check that the loop was started, but without persistent connection
  483. # since there was no state returned yet and it might need to negotiate
  484. # version.
  485. self.mock_api().set_socketPersistent.assert_called_once_with(False)
  486. # Check that a full poll was done
  487. self.mock_api().status.assert_called_once()
  488. self.assertDictEqual(result, {"1": "INIT", "2": 2, "full_poll": ANY})
  489. # Prepare for next round
  490. self.subject._cached_state = self.subject._cached_state | result
  491. self.mock_api().set_socketPersistent.reset_mock()
  492. self.mock_api().status.reset_mock()
  493. self.subject._cached_state["updated_at"] = time()
  494. # Call the function under test
  495. print("getting second iteration...")
  496. result = await loop.__anext__()
  497. # Check that a heartbeat poll was done
  498. self.mock_api().status.assert_not_called()
  499. self.mock_api().heartbeat.assert_called_once()
  500. self.mock_api().receive.assert_called_once()
  501. self.assertDictEqual(result, {"1": "UPDATED", "full_poll": ANY})
  502. # Check that the connection was made persistent now that data has been
  503. # returned
  504. self.mock_api().set_socketPersistent.assert_called_once_with(True)
  505. # Prepare for next iteration
  506. self.subject._running = False
  507. self.mock_api().set_socketPersistent.reset_mock()
  508. # Call the function under test
  509. print("getting last iteration...")
  510. try:
  511. result = await loop.__anext__()
  512. self.fail("Should have raised an exception to quit the loop")
  513. # Check that the loop terminated
  514. except StopAsyncIteration:
  515. pass
  516. self.mock_api().set_socketPersistent.assert_called_once_with(False)
  517. def test_should_poll(self):
  518. self.subject._cached_state = {"1": "sample", "updated_at": time()}
  519. self.subject._poll_only = False
  520. self.subject._temporary_poll = False
  521. # Test temporary poll via pause/resume
  522. self.assertFalse(self.subject.should_poll)
  523. self.subject.pause()
  524. self.assertTrue(self.subject.should_poll)
  525. self.subject.resume()
  526. self.assertFalse(self.subject.should_poll)
  527. # Test configured polling
  528. self.subject._poll_only = True
  529. self.assertTrue(self.subject.should_poll)
  530. self.subject._poll_only = False
  531. # Test initial polling
  532. self.subject._cached_state = {}
  533. self.assertTrue(self.subject.should_poll)