test_device.py 24 KB

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