Add tests for Broadlink remotes (#39235)

* Add tests for Broadlink remotes

* Reformat the tests with Black

* Add a helper method for device setup

* Rename device.setup() to device.setup_entry()

* Apply suggestions from code review

Co-authored-by: Chris Talkington <chris@talkingtontech.com>
This commit is contained in:
Felipe Martins DielandChris Talkington authored and GitHub committed 2020-09-03 16:51:08 -05:00
1 parent da82d171e0
commit 353b40b28a
2 files changed
+136 -1

No files matched your search

+16 -1
View File
@@ -1,7 +1,7 @@
"""Tests for the Broadlink integration."""
from homeassistant.components.broadlink.const import DOMAIN
from tests.async_mock import MagicMock
from tests.async_mock import MagicMock, patch
from tests.common import MockConfigEntry
# Do not edit/remove. Adding is ok.
@@ -76,6 +76,21 @@ class BroadlinkDevice:
self.timeout: int = timeout
self.fwversion: int = fwversion
async def setup_entry(self, hass, mock_api=None, mock_entry=None):
"""Set up the device."""
mock_api = mock_api or self.get_mock_api()
mock_entry = mock_entry or self.get_mock_entry()
mock_entry.add_to_hass(hass)
with patch(
"homeassistant.components.broadlink.device.blk.gendevice",
return_value=mock_api,
):
await hass.config_entries.async_setup(mock_entry.entry_id)
await hass.async_block_till_done()
return mock_api, mock_entry
def get_mock_api(self):
"""Return a mock device (API)."""
mock_api = MagicMock()