test_config_flow.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. """Tests for the config flow."""
  2. from unittest.mock import ANY, AsyncMock, MagicMock, patch
  3. import pytest
  4. import voluptuous as vol
  5. from homeassistant.const import CONF_HOST, CONF_NAME
  6. from pytest_homeassistant_custom_component.common import MockConfigEntry
  7. from custom_components.tuya_local import (
  8. async_migrate_entry,
  9. async_setup_entry,
  10. config_flow,
  11. )
  12. from custom_components.tuya_local.const import (
  13. CONF_DEVICE_CID,
  14. CONF_DEVICE_ID,
  15. CONF_LOCAL_KEY,
  16. CONF_POLL_ONLY,
  17. CONF_PROTOCOL_VERSION,
  18. CONF_TYPE,
  19. DOMAIN,
  20. )
  21. @pytest.fixture(autouse=True)
  22. def auto_enable_custom_integrations(enable_custom_integrations):
  23. yield
  24. @pytest.fixture(autouse=True)
  25. def prevent_task_creation():
  26. with patch(
  27. "custom_components.tuya_local.device.TuyaLocalDevice.register_entity",
  28. ):
  29. yield
  30. @pytest.fixture
  31. def bypass_setup():
  32. """Prevent actual setup of the integration after config flow."""
  33. with patch(
  34. "custom_components.tuya_local.async_setup_entry",
  35. return_value=True,
  36. ):
  37. yield
  38. @pytest.mark.asyncio
  39. async def test_init_entry(hass):
  40. """Test initialisation of the config flow."""
  41. entry = MockConfigEntry(
  42. domain=DOMAIN,
  43. version=11,
  44. title="test",
  45. data={
  46. CONF_DEVICE_ID: "deviceid",
  47. CONF_HOST: "hostname",
  48. CONF_LOCAL_KEY: "localkey",
  49. CONF_POLL_ONLY: False,
  50. CONF_PROTOCOL_VERSION: "auto",
  51. CONF_TYPE: "kogan_kahtp_heater",
  52. CONF_DEVICE_CID: None,
  53. },
  54. options={},
  55. )
  56. entry.add_to_hass(hass)
  57. await hass.config_entries.async_setup(entry.entry_id)
  58. await hass.async_block_till_done()
  59. assert hass.states.get("climate.test")
  60. assert hass.states.get("lock.test_child_lock")
  61. @pytest.mark.asyncio
  62. @patch("custom_components.tuya_local.setup_device")
  63. async def test_migrate_entry(mock_setup, hass):
  64. """Test migration from old entry format."""
  65. mock_device = MagicMock()
  66. mock_device.async_inferred_type = AsyncMock(return_value="goldair_gpph_heater")
  67. mock_setup.return_value = mock_device
  68. entry = MockConfigEntry(
  69. domain=DOMAIN,
  70. version=1,
  71. title="test",
  72. data={
  73. CONF_DEVICE_ID: "deviceid",
  74. CONF_HOST: "hostname",
  75. CONF_LOCAL_KEY: "localkey",
  76. CONF_TYPE: "auto",
  77. "climate": True,
  78. "child_lock": True,
  79. "display_light": True,
  80. },
  81. )
  82. assert await async_migrate_entry(hass, entry)
  83. mock_device.async_inferred_type = AsyncMock(return_value=None)
  84. mock_device.reset_mock()
  85. entry = MockConfigEntry(
  86. domain=DOMAIN,
  87. version=1,
  88. title="test2",
  89. data={
  90. CONF_DEVICE_ID: "deviceid",
  91. CONF_HOST: "hostname",
  92. CONF_LOCAL_KEY: "localkey",
  93. CONF_TYPE: "unknown",
  94. "climate": False,
  95. },
  96. )
  97. assert not await async_migrate_entry(hass, entry)
  98. mock_device.reset_mock()
  99. entry = MockConfigEntry(
  100. domain=DOMAIN,
  101. version=2,
  102. title="test3",
  103. data={
  104. CONF_DEVICE_ID: "deviceid",
  105. CONF_HOST: "hostname",
  106. CONF_LOCAL_KEY: "localkey",
  107. CONF_TYPE: "auto",
  108. },
  109. options={
  110. "climate": False,
  111. },
  112. )
  113. assert not await async_migrate_entry(hass, entry)
  114. mock_device.async_inferred_type = AsyncMock(return_value="smartplugv1")
  115. mock_device.reset_mock()
  116. entry = MockConfigEntry(
  117. domain=DOMAIN,
  118. version=3,
  119. title="test4",
  120. data={
  121. CONF_DEVICE_ID: "deviceid",
  122. CONF_HOST: "hostname",
  123. CONF_LOCAL_KEY: "localkey",
  124. CONF_TYPE: "smartplugv1",
  125. },
  126. options={
  127. "switch": True,
  128. },
  129. )
  130. assert await async_migrate_entry(hass, entry)
  131. mock_device.async_inferred_type = AsyncMock(return_value="smartplugv2")
  132. mock_device.reset_mock()
  133. entry = MockConfigEntry(
  134. domain=DOMAIN,
  135. version=3,
  136. title="test5",
  137. data={
  138. CONF_DEVICE_ID: "deviceid",
  139. CONF_HOST: "hostname",
  140. CONF_LOCAL_KEY: "localkey",
  141. CONF_TYPE: "smartplugv1",
  142. },
  143. options={
  144. "switch": True,
  145. },
  146. )
  147. assert await async_migrate_entry(hass, entry)
  148. mock_device.async_inferred_type = AsyncMock(return_value="goldair_dehumidifier")
  149. mock_device.reset_mock()
  150. entry = MockConfigEntry(
  151. domain=DOMAIN,
  152. version=4,
  153. title="test6",
  154. data={
  155. CONF_DEVICE_ID: "deviceid",
  156. CONF_HOST: "hostname",
  157. CONF_LOCAL_KEY: "localkey",
  158. CONF_TYPE: "goldair_dehumidifier",
  159. },
  160. options={
  161. "humidifier": True,
  162. "fan": True,
  163. "light": True,
  164. "lock": False,
  165. "switch": True,
  166. },
  167. )
  168. assert await async_migrate_entry(hass, entry)
  169. mock_device.async_inferred_type = AsyncMock(
  170. return_value="grid_connect_usb_double_power_point"
  171. )
  172. mock_device.reset_mock()
  173. entry = MockConfigEntry(
  174. domain=DOMAIN,
  175. version=6,
  176. title="test7",
  177. data={
  178. CONF_DEVICE_ID: "deviceid",
  179. CONF_HOST: "hostname",
  180. CONF_LOCAL_KEY: "localkey",
  181. CONF_TYPE: "grid_connect_usb_double_power_point",
  182. },
  183. options={
  184. "switch_main_switch": True,
  185. "switch_left_outlet": True,
  186. "switch_right_outlet": True,
  187. },
  188. )
  189. assert await async_migrate_entry(hass, entry)
  190. @pytest.mark.asyncio
  191. async def test_flow_user_init(hass):
  192. """Test the initialisation of the form in the first step of the config flow."""
  193. result = await hass.config_entries.flow.async_init(
  194. DOMAIN, context={"source": "user"}
  195. )
  196. expected = {
  197. "data_schema": ANY,
  198. "description_placeholders": None,
  199. "errors": {},
  200. "flow_id": ANY,
  201. "handler": DOMAIN,
  202. "step_id": "user",
  203. "type": "form",
  204. "last_step": ANY,
  205. }
  206. assert expected == result
  207. # Check the schema. Simple comparison does not work since they are not
  208. # the same object
  209. try:
  210. result["data_schema"](
  211. {CONF_DEVICE_ID: "test", CONF_LOCAL_KEY: "test", CONF_HOST: "test"}
  212. )
  213. except vol.MultipleInvalid:
  214. assert False
  215. try:
  216. result["data_schema"]({CONF_DEVICE_ID: "missing_some"})
  217. assert False
  218. except vol.MultipleInvalid:
  219. pass
  220. @pytest.mark.asyncio
  221. @patch("custom_components.tuya_local.config_flow.TuyaLocalDevice")
  222. async def test_async_test_connection_valid(mock_device, hass):
  223. """Test that device is returned when connection is valid."""
  224. mock_instance = AsyncMock()
  225. mock_instance.has_returned_state = True
  226. mock_device.return_value = mock_instance
  227. hass.data[DOMAIN] = {"deviceid": {"device": mock_instance}}
  228. device = await config_flow.async_test_connection(
  229. {
  230. CONF_DEVICE_ID: "deviceid",
  231. CONF_LOCAL_KEY: "localkey",
  232. CONF_HOST: "hostname",
  233. CONF_PROTOCOL_VERSION: "auto",
  234. },
  235. hass,
  236. )
  237. assert device == mock_instance
  238. mock_instance.pause.assert_called_once()
  239. mock_instance.resume.assert_called_once()
  240. @pytest.mark.asyncio
  241. @patch("custom_components.tuya_local.config_flow.TuyaLocalDevice")
  242. async def test_async_test_connection_for_subdevice_valid(mock_device, hass):
  243. """Test that subdevice is returned when connection is valid."""
  244. mock_instance = AsyncMock()
  245. mock_instance.has_returned_state = True
  246. mock_device.return_value = mock_instance
  247. hass.data[DOMAIN] = {"subdeviceid": {"device": mock_instance}}
  248. device = await config_flow.async_test_connection(
  249. {
  250. CONF_DEVICE_ID: "deviceid",
  251. CONF_LOCAL_KEY: "localkey",
  252. CONF_HOST: "hostname",
  253. CONF_PROTOCOL_VERSION: "auto",
  254. CONF_DEVICE_CID: "subdeviceid",
  255. },
  256. hass,
  257. )
  258. assert device == mock_instance
  259. mock_instance.pause.assert_called_once()
  260. mock_instance.resume.assert_called_once()
  261. @pytest.mark.asyncio
  262. @patch("custom_components.tuya_local.config_flow.TuyaLocalDevice")
  263. async def test_async_test_connection_invalid(mock_device, hass):
  264. """Test that None is returned when connection is invalid."""
  265. mock_instance = AsyncMock()
  266. mock_instance.has_returned_state = False
  267. mock_device.return_value = mock_instance
  268. device = await config_flow.async_test_connection(
  269. {
  270. CONF_DEVICE_ID: "deviceid",
  271. CONF_LOCAL_KEY: "localkey",
  272. CONF_HOST: "hostname",
  273. CONF_PROTOCOL_VERSION: "auto",
  274. },
  275. hass,
  276. )
  277. assert device is None
  278. @pytest.mark.asyncio
  279. @patch("custom_components.tuya_local.config_flow.async_test_connection")
  280. async def test_flow_user_init_invalid_config(mock_test, hass):
  281. """Test errors populated when config is invalid."""
  282. mock_test.return_value = None
  283. flow = await hass.config_entries.flow.async_init(DOMAIN, context={"source": "user"})
  284. result = await hass.config_entries.flow.async_configure(
  285. flow["flow_id"],
  286. user_input={
  287. CONF_DEVICE_ID: "deviceid",
  288. CONF_HOST: "hostname",
  289. CONF_LOCAL_KEY: "badkey",
  290. CONF_PROTOCOL_VERSION: "auto",
  291. CONF_POLL_ONLY: False,
  292. },
  293. )
  294. assert {"base": "connection"} == result["errors"]
  295. def setup_device_mock(mock, failure=False, type="test"):
  296. mock_type = MagicMock()
  297. mock_type.legacy_type = type
  298. mock_type.config_type = type
  299. mock_type.match_quality.return_value = 100
  300. mock_iter = MagicMock()
  301. mock_iter.__aiter__.return_value = [mock_type] if not failure else []
  302. mock.async_possible_types = MagicMock(return_value=mock_iter)
  303. @pytest.mark.asyncio
  304. @patch("custom_components.tuya_local.config_flow.async_test_connection")
  305. async def test_flow_user_init_data_valid(mock_test, hass):
  306. """Test we advance to the next step when connection config is valid."""
  307. mock_device = MagicMock()
  308. setup_device_mock(mock_device)
  309. mock_test.return_value = mock_device
  310. flow = await hass.config_entries.flow.async_init(DOMAIN, context={"source": "user"})
  311. result = await hass.config_entries.flow.async_configure(
  312. flow["flow_id"],
  313. user_input={
  314. CONF_DEVICE_ID: "deviceid",
  315. CONF_HOST: "hostname",
  316. CONF_LOCAL_KEY: "localkey",
  317. },
  318. )
  319. assert "form" == result["type"]
  320. assert "select_type" == result["step_id"]
  321. @pytest.mark.asyncio
  322. @patch.object(config_flow.ConfigFlowHandler, "device")
  323. async def test_flow_select_type_init(mock_device, hass):
  324. """Test the initialisation of the form in the 2nd step of the config flow."""
  325. setup_device_mock(mock_device)
  326. result = await hass.config_entries.flow.async_init(
  327. DOMAIN, context={"source": "select_type"}
  328. )
  329. expected = {
  330. "data_schema": ANY,
  331. "description_placeholders": None,
  332. "errors": None,
  333. "flow_id": ANY,
  334. "handler": DOMAIN,
  335. "step_id": "select_type",
  336. "type": "form",
  337. "last_step": ANY,
  338. }
  339. assert expected == result
  340. # Check the schema. Simple comparison does not work since they are not
  341. # the same object
  342. try:
  343. result["data_schema"]({CONF_TYPE: "test"})
  344. except vol.MultipleInvalid:
  345. assert False
  346. try:
  347. result["data_schema"]({CONF_TYPE: "not_test"})
  348. assert False
  349. except vol.MultipleInvalid:
  350. pass
  351. @pytest.mark.asyncio
  352. @patch.object(config_flow.ConfigFlowHandler, "device")
  353. async def test_flow_select_type_aborts_when_no_match(mock_device, hass):
  354. """Test the flow aborts when an unsupported device is used."""
  355. setup_device_mock(mock_device, failure=True)
  356. result = await hass.config_entries.flow.async_init(
  357. DOMAIN, context={"source": "select_type"}
  358. )
  359. assert result["type"] == "abort"
  360. assert result["reason"] == "not_supported"
  361. @pytest.mark.asyncio
  362. @patch.object(config_flow.ConfigFlowHandler, "device")
  363. async def test_flow_select_type_data_valid(mock_device, hass):
  364. """Test the flow continues when valid data is supplied."""
  365. setup_device_mock(mock_device, type="smartplugv1")
  366. flow = await hass.config_entries.flow.async_init(
  367. DOMAIN, context={"source": "select_type"}
  368. )
  369. result = await hass.config_entries.flow.async_configure(
  370. flow["flow_id"],
  371. user_input={CONF_TYPE: "smartplugv1"},
  372. )
  373. assert "form" == result["type"]
  374. assert "choose_entities" == result["step_id"]
  375. @pytest.mark.asyncio
  376. async def test_flow_choose_entities_init(hass):
  377. """Test the initialisation of the form in the 3rd step of the config flow."""
  378. with patch.dict(config_flow.ConfigFlowHandler.data, {CONF_TYPE: "smartplugv1"}):
  379. result = await hass.config_entries.flow.async_init(
  380. DOMAIN, context={"source": "choose_entities"}
  381. )
  382. expected = {
  383. "data_schema": ANY,
  384. "description_placeholders": None,
  385. "errors": None,
  386. "flow_id": ANY,
  387. "handler": DOMAIN,
  388. "step_id": "choose_entities",
  389. "type": "form",
  390. "last_step": ANY,
  391. }
  392. assert expected == result
  393. # Check the schema. Simple comparison does not work since they are not
  394. # the same object
  395. try:
  396. result["data_schema"]({CONF_NAME: "test"})
  397. except vol.MultipleInvalid:
  398. assert False
  399. try:
  400. result["data_schema"]({"climate": True})
  401. assert False
  402. except vol.MultipleInvalid:
  403. pass
  404. @pytest.mark.asyncio
  405. async def test_flow_choose_entities_creates_config_entry(hass, bypass_setup):
  406. """Test the flow ends when data is valid."""
  407. with patch.dict(
  408. config_flow.ConfigFlowHandler.data,
  409. {
  410. CONF_DEVICE_ID: "deviceid",
  411. CONF_LOCAL_KEY: "localkey",
  412. CONF_HOST: "hostname",
  413. CONF_POLL_ONLY: False,
  414. CONF_PROTOCOL_VERSION: "auto",
  415. CONF_TYPE: "kogan_kahtp_heater",
  416. CONF_DEVICE_CID: None,
  417. },
  418. ):
  419. flow = await hass.config_entries.flow.async_init(
  420. DOMAIN, context={"source": "choose_entities"}
  421. )
  422. result = await hass.config_entries.flow.async_configure(
  423. flow["flow_id"],
  424. user_input={
  425. CONF_NAME: "test",
  426. },
  427. )
  428. expected = {
  429. "version": 13,
  430. "context": {"source": "choose_entities"},
  431. "type": "create_entry",
  432. "flow_id": ANY,
  433. "handler": DOMAIN,
  434. "title": "test",
  435. "description": None,
  436. "description_placeholders": None,
  437. "result": ANY,
  438. "options": {},
  439. "data": {
  440. CONF_DEVICE_ID: "deviceid",
  441. CONF_HOST: "hostname",
  442. CONF_LOCAL_KEY: "localkey",
  443. CONF_POLL_ONLY: False,
  444. CONF_PROTOCOL_VERSION: "auto",
  445. CONF_TYPE: "kogan_kahtp_heater",
  446. CONF_DEVICE_CID: None,
  447. },
  448. }
  449. assert expected == result
  450. @pytest.mark.asyncio
  451. async def test_options_flow_init(hass):
  452. """Test config flow options."""
  453. config_entry = MockConfigEntry(
  454. domain=DOMAIN,
  455. version=13,
  456. unique_id="uniqueid",
  457. data={
  458. CONF_DEVICE_ID: "deviceid",
  459. CONF_HOST: "hostname",
  460. CONF_LOCAL_KEY: "localkey",
  461. CONF_NAME: "test",
  462. CONF_POLL_ONLY: False,
  463. CONF_PROTOCOL_VERSION: "auto",
  464. CONF_TYPE: "smartplugv1",
  465. CONF_DEVICE_CID: "",
  466. },
  467. )
  468. config_entry.add_to_hass(hass)
  469. assert await hass.config_entries.async_setup(config_entry.entry_id)
  470. await hass.async_block_till_done()
  471. # show initial form
  472. result = await hass.config_entries.options.async_init(config_entry.entry_id)
  473. assert "form" == result["type"]
  474. assert "user" == result["step_id"]
  475. assert {} == result["errors"]
  476. assert result["data_schema"](
  477. {
  478. CONF_HOST: "hostname",
  479. CONF_LOCAL_KEY: "localkey",
  480. }
  481. )
  482. @pytest.mark.asyncio
  483. @patch("custom_components.tuya_local.config_flow.async_test_connection")
  484. async def test_options_flow_modifies_config(mock_test, hass):
  485. mock_device = MagicMock()
  486. mock_test.return_value = mock_device
  487. config_entry = MockConfigEntry(
  488. domain=DOMAIN,
  489. version=13,
  490. unique_id="uniqueid",
  491. data={
  492. CONF_DEVICE_ID: "deviceid",
  493. CONF_HOST: "hostname",
  494. CONF_LOCAL_KEY: "localkey",
  495. CONF_NAME: "test",
  496. CONF_POLL_ONLY: False,
  497. CONF_PROTOCOL_VERSION: "auto",
  498. CONF_TYPE: "ble_pt216_temp_humidity",
  499. CONF_DEVICE_CID: "subdeviceid",
  500. },
  501. )
  502. config_entry.add_to_hass(hass)
  503. assert await hass.config_entries.async_setup(config_entry.entry_id)
  504. await hass.async_block_till_done()
  505. # show initial form
  506. form = await hass.config_entries.options.async_init(config_entry.entry_id)
  507. # submit updated config
  508. result = await hass.config_entries.options.async_configure(
  509. form["flow_id"],
  510. user_input={
  511. CONF_HOST: "new_hostname",
  512. CONF_LOCAL_KEY: "new_key",
  513. CONF_POLL_ONLY: False,
  514. CONF_PROTOCOL_VERSION: 3.3,
  515. CONF_DEVICE_CID: "subdeviceid",
  516. },
  517. )
  518. expected = {
  519. CONF_HOST: "new_hostname",
  520. CONF_LOCAL_KEY: "new_key",
  521. CONF_POLL_ONLY: False,
  522. CONF_PROTOCOL_VERSION: 3.3,
  523. CONF_DEVICE_CID: "subdeviceid",
  524. }
  525. assert "create_entry" == result["type"]
  526. assert "" == result["title"]
  527. assert result["result"] is True
  528. assert expected == result["data"]
  529. @pytest.mark.asyncio
  530. @patch("custom_components.tuya_local.config_flow.async_test_connection")
  531. async def test_options_flow_fails_when_connection_fails(mock_test, hass):
  532. mock_test.return_value = None
  533. config_entry = MockConfigEntry(
  534. domain=DOMAIN,
  535. version=13,
  536. unique_id="uniqueid",
  537. data={
  538. CONF_DEVICE_ID: "deviceid",
  539. CONF_HOST: "hostname",
  540. CONF_LOCAL_KEY: "localkey",
  541. CONF_NAME: "test",
  542. CONF_POLL_ONLY: False,
  543. CONF_PROTOCOL_VERSION: "auto",
  544. CONF_TYPE: "smartplugv1",
  545. CONF_DEVICE_CID: "",
  546. },
  547. )
  548. config_entry.add_to_hass(hass)
  549. assert await hass.config_entries.async_setup(config_entry.entry_id)
  550. await hass.async_block_till_done()
  551. # show initial form
  552. form = await hass.config_entries.options.async_init(config_entry.entry_id)
  553. # submit updated config
  554. result = await hass.config_entries.options.async_configure(
  555. form["flow_id"],
  556. user_input={
  557. CONF_HOST: "new_hostname",
  558. CONF_LOCAL_KEY: "new_key",
  559. },
  560. )
  561. assert "form" == result["type"]
  562. assert "user" == result["step_id"]
  563. assert {"base": "connection"} == result["errors"]
  564. @pytest.mark.asyncio
  565. @patch("custom_components.tuya_local.config_flow.async_test_connection")
  566. async def test_options_flow_fails_when_config_is_missing(mock_test, hass):
  567. mock_device = MagicMock()
  568. mock_test.return_value = mock_device
  569. config_entry = MockConfigEntry(
  570. domain=DOMAIN,
  571. version=13,
  572. unique_id="uniqueid",
  573. data={
  574. CONF_DEVICE_ID: "deviceid",
  575. CONF_HOST: "hostname",
  576. CONF_LOCAL_KEY: "localkey",
  577. CONF_NAME: "test",
  578. CONF_POLL_ONLY: False,
  579. CONF_PROTOCOL_VERSION: "auto",
  580. CONF_TYPE: "non_existing",
  581. },
  582. )
  583. config_entry.add_to_hass(hass)
  584. await hass.config_entries.async_setup(config_entry.entry_id)
  585. await hass.async_block_till_done()
  586. # show initial form
  587. result = await hass.config_entries.options.async_init(config_entry.entry_id)
  588. assert result["type"] == "abort"
  589. assert result["reason"] == "not_supported"
  590. @pytest.mark.asyncio
  591. @patch("custom_components.tuya_local.setup_device")
  592. async def test_async_setup_entry_for_switch(mock_device, hass):
  593. """Test setting up based on a config entry. Repeats test_init_entry."""
  594. config_entry = MockConfigEntry(
  595. domain=DOMAIN,
  596. version=13,
  597. unique_id="uniqueid",
  598. data={
  599. CONF_DEVICE_ID: "deviceid",
  600. CONF_HOST: "hostname",
  601. CONF_LOCAL_KEY: "localkey",
  602. CONF_NAME: "test",
  603. CONF_POLL_ONLY: False,
  604. CONF_PROTOCOL_VERSION: 3.3,
  605. CONF_TYPE: "smartplugv2",
  606. },
  607. )
  608. assert await async_setup_entry(hass, config_entry)