diff --git a/homeassistant/components/broadlink/updater.py b/homeassistant/components/broadlink/updater.py index bd124d1e1acfb6..8b6f1316f52d51 100644 --- a/homeassistant/components/broadlink/updater.py +++ b/homeassistant/components/broadlink/updater.py @@ -1,12 +1,15 @@ """Support for fetching data from Broadlink devices.""" from abc import ABC, abstractmethod from datetime import timedelta +from functools import partial import logging +import broadlink as blk from broadlink.exceptions import ( AuthorizationError, BroadlinkException, CommandNotSupportedError, + DeviceOfflineError, StorageError, ) @@ -18,6 +21,9 @@ def get_update_manager(device): """Return an update manager for a given Broadlink device.""" + if device.api.model.startswith("RM mini"): + return BroadlinkRMMini3UpdateManager(device) + update_managers = { "A1": BroadlinkA1UpdateManager, "MP1": BroadlinkMP1UpdateManager, @@ -95,6 +101,22 @@ async def async_fetch_data(self): return await self.device.async_request(self.device.api.check_power) +class BroadlinkRMMini3UpdateManager(BroadlinkUpdateManager): + """Manages updates for Broadlink RM mini 3 devices.""" + + async def async_fetch_data(self): + """Fetch data from the device.""" + hello = partial( + blk.discover, + discover_ip_address=self.device.api.host[0], + timeout=self.device.api.timeout, + ) + devices = await self.device.hass.async_add_executor_job(hello) + if not devices: + raise DeviceOfflineError("The device is offline") + return {} + + class BroadlinkRMUpdateManager(BroadlinkUpdateManager): """Manages updates for Broadlink RM2 and RM4 devices.""" diff --git a/tests/components/broadlink/__init__.py b/tests/components/broadlink/__init__.py index 87a23d7074c45c..86756c922f15f8 100644 --- a/tests/components/broadlink/__init__.py +++ b/tests/components/broadlink/__init__.py @@ -95,6 +95,9 @@ async def setup_entry(self, hass, mock_api=None, mock_entry=None): with patch( "homeassistant.components.broadlink.device.blk.gendevice", return_value=mock_api, + ), patch( + "homeassistant.components.broadlink.updater.blk.discover", + return_value=[mock_api], ): await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() diff --git a/tests/components/broadlink/test_device.py b/tests/components/broadlink/test_device.py index a226c5e484f6ab..1e68921e9bdd5d 100644 --- a/tests/components/broadlink/test_device.py +++ b/tests/components/broadlink/test_device.py @@ -164,7 +164,7 @@ async def test_device_setup_update_authorization_error(hass): async def test_device_setup_update_authentication_error(hass): """Test we handle an authentication error in the update step.""" - device = get_device("Living Room") + device = get_device("Garage") mock_api = device.get_mock_api() mock_api.check_sensors.side_effect = blke.AuthorizationError() mock_api.auth.side_effect = (None, blke.AuthenticationError()) @@ -190,7 +190,7 @@ async def test_device_setup_update_authentication_error(hass): async def test_device_setup_update_broadlink_exception(hass): """Test we handle a Broadlink exception in the update step.""" - device = get_device("Living Room") + device = get_device("Garage") mock_api = device.get_mock_api() mock_api.check_sensors.side_effect = blke.BroadlinkException()