mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 10:47:10 +00:00
Fix RM mini 3 update manager (#40215)
This commit is contained in:
parent
27f11a1022
commit
2f7b6bfa2d
@ -1,12 +1,15 @@
|
|||||||
"""Support for fetching data from Broadlink devices."""
|
"""Support for fetching data from Broadlink devices."""
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from functools import partial
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import broadlink as blk
|
||||||
from broadlink.exceptions import (
|
from broadlink.exceptions import (
|
||||||
AuthorizationError,
|
AuthorizationError,
|
||||||
BroadlinkException,
|
BroadlinkException,
|
||||||
CommandNotSupportedError,
|
CommandNotSupportedError,
|
||||||
|
DeviceOfflineError,
|
||||||
StorageError,
|
StorageError,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,6 +21,9 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
def get_update_manager(device):
|
def get_update_manager(device):
|
||||||
"""Return an update manager for a given Broadlink device."""
|
"""Return an update manager for a given Broadlink device."""
|
||||||
|
if device.api.model.startswith("RM mini"):
|
||||||
|
return BroadlinkRMMini3UpdateManager(device)
|
||||||
|
|
||||||
update_managers = {
|
update_managers = {
|
||||||
"A1": BroadlinkA1UpdateManager,
|
"A1": BroadlinkA1UpdateManager,
|
||||||
"MP1": BroadlinkMP1UpdateManager,
|
"MP1": BroadlinkMP1UpdateManager,
|
||||||
@ -95,6 +101,22 @@ class BroadlinkMP1UpdateManager(BroadlinkUpdateManager):
|
|||||||
return await self.device.async_request(self.device.api.check_power)
|
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):
|
class BroadlinkRMUpdateManager(BroadlinkUpdateManager):
|
||||||
"""Manages updates for Broadlink RM2 and RM4 devices."""
|
"""Manages updates for Broadlink RM2 and RM4 devices."""
|
||||||
|
|
||||||
|
@ -95,6 +95,9 @@ class BroadlinkDevice:
|
|||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.broadlink.device.blk.gendevice",
|
"homeassistant.components.broadlink.device.blk.gendevice",
|
||||||
return_value=mock_api,
|
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.config_entries.async_setup(mock_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -164,7 +164,7 @@ async def test_device_setup_update_authorization_error(hass):
|
|||||||
|
|
||||||
async def test_device_setup_update_authentication_error(hass):
|
async def test_device_setup_update_authentication_error(hass):
|
||||||
"""Test we handle an authentication error in the update step."""
|
"""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 = device.get_mock_api()
|
||||||
mock_api.check_sensors.side_effect = blke.AuthorizationError()
|
mock_api.check_sensors.side_effect = blke.AuthorizationError()
|
||||||
mock_api.auth.side_effect = (None, blke.AuthenticationError())
|
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):
|
async def test_device_setup_update_broadlink_exception(hass):
|
||||||
"""Test we handle a Broadlink exception in the update step."""
|
"""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 = device.get_mock_api()
|
||||||
mock_api.check_sensors.side_effect = blke.BroadlinkException()
|
mock_api.check_sensors.side_effect = blke.BroadlinkException()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user