mirror of
https://github.com/home-assistant/core.git
synced 2026-09-27 01:46:11 -04:00
Add support for the Broadlink RM5 Plus (#183058)
This commit is contained in:
@@ -6,10 +6,10 @@ DOMAIN = "broadlink"
|
||||
|
||||
DOMAINS_AND_TYPES = {
|
||||
Platform.CLIMATE: {"HYS"},
|
||||
Platform.INFRARED: {"RM4MINI", "RM4PRO", "RMMINI", "RMMINIB", "RMPRO"},
|
||||
Platform.INFRARED: {"RM4MINI", "RM4PRO", "RM5PLUS", "RMMINI", "RMMINIB", "RMPRO"},
|
||||
Platform.LIGHT: {"LB1", "LB2"},
|
||||
Platform.RADIO_FREQUENCY: {"RM4PRO", "RMPRO"},
|
||||
Platform.REMOTE: {"RM4MINI", "RM4PRO", "RMMINI", "RMMINIB", "RMPRO"},
|
||||
Platform.REMOTE: {"RM4MINI", "RM4PRO", "RM5PLUS", "RMMINI", "RMMINIB", "RMPRO"},
|
||||
Platform.SELECT: {"HYS"},
|
||||
Platform.SENSOR: {
|
||||
"A1",
|
||||
@@ -29,6 +29,7 @@ DOMAINS_AND_TYPES = {
|
||||
"MP1S",
|
||||
"RM4MINI",
|
||||
"RM4PRO",
|
||||
"RM5PLUS",
|
||||
"RMMINI",
|
||||
"RMMINIB",
|
||||
"RMPRO",
|
||||
|
||||
@@ -37,7 +37,7 @@ from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import BroadlinkDevice
|
||||
from .const import DOMAIN
|
||||
from .const import DOMAIN, DOMAINS_AND_TYPES
|
||||
from .entity import BroadlinkEntity
|
||||
from .helpers import data_packet, import_device, mac_address
|
||||
|
||||
@@ -119,7 +119,7 @@ async def async_setup_entry(
|
||||
device = hass.data[DOMAIN].devices[config_entry.entry_id]
|
||||
switches: list[BroadlinkSwitch] = []
|
||||
|
||||
if device.api.type in {"RM4MINI", "RM4PRO", "RMMINI", "RMMINIB", "RMPRO"}:
|
||||
if device.api.type in DOMAINS_AND_TYPES[Platform.REMOTE]:
|
||||
platform_data = hass.data[DOMAIN].platforms.setdefault(Platform.SWITCH, {})
|
||||
platform_data[device.api.mac] = async_add_entities, device
|
||||
elif device.api.type == "SP1":
|
||||
|
||||
@@ -32,6 +32,7 @@ def get_update_manager(device: BroadlinkDevice[_ApiT]) -> BroadlinkUpdateManager
|
||||
"MP1S": BroadlinkMP1SUpdateManager,
|
||||
"RM4MINI": BroadlinkRMUpdateManager,
|
||||
"RM4PRO": BroadlinkRMUpdateManager,
|
||||
"RM5PLUS": BroadlinkRMUpdateManager,
|
||||
"RMMINI": BroadlinkRMUpdateManager,
|
||||
"RMMINIB": BroadlinkRMUpdateManager,
|
||||
"RMPRO": BroadlinkRMUpdateManager,
|
||||
|
||||
@@ -103,6 +103,16 @@ BROADLINK_DEVICES = {
|
||||
10024,
|
||||
5,
|
||||
),
|
||||
"Study": (
|
||||
"192.168.0.17",
|
||||
"34ea34b61d2f",
|
||||
"RM5 plus",
|
||||
"Broadlink",
|
||||
"RM5PLUS",
|
||||
0x5224,
|
||||
57,
|
||||
5,
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,12 +31,13 @@ def broadlink_setup_fixture():
|
||||
yield
|
||||
|
||||
|
||||
async def test_flow_user_works(hass: HomeAssistant) -> None:
|
||||
@pytest.mark.parametrize("device_name", ["Living Room", "Study"])
|
||||
async def test_flow_user_works(hass: HomeAssistant, device_name: str) -> None:
|
||||
"""Test a config flow initiated by the user.
|
||||
|
||||
Best case scenario with no errors or locks.
|
||||
"""
|
||||
device = get_device("Living Room")
|
||||
device = get_device(device_name)
|
||||
mock_api = device.get_mock_api()
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
||||
@@ -8,7 +8,7 @@ import pytest
|
||||
from homeassistant.components.broadlink.const import DOMAIN
|
||||
from homeassistant.components.broadlink.device import get_domains
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import ATTR_FRIENDLY_NAME
|
||||
from homeassistant.const import ATTR_FRIENDLY_NAME, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
@@ -40,6 +40,23 @@ async def test_device_setup(hass: HomeAssistant) -> None:
|
||||
assert mock_init.call_count == 0
|
||||
|
||||
|
||||
async def test_device_setup_rm5plus(hass: HomeAssistant) -> None:
|
||||
"""Test an RM5 Plus sets up with the IR remote platforms and no sensors."""
|
||||
device = get_device("Study")
|
||||
|
||||
with patch.object(
|
||||
hass.config_entries, "async_forward_entry_setups"
|
||||
) as mock_forward:
|
||||
mock_setup = await device.setup_entry(hass)
|
||||
|
||||
assert mock_setup.entry.state is ConfigEntryState.LOADED
|
||||
assert set(mock_forward.mock_calls[0][1][1]) == {
|
||||
Platform.INFRARED,
|
||||
Platform.REMOTE,
|
||||
Platform.SWITCH,
|
||||
}
|
||||
|
||||
|
||||
async def test_device_setup_authentication_error(hass: HomeAssistant) -> None:
|
||||
"""Test we handle an authentication error."""
|
||||
device = get_device("Living Room")
|
||||
|
||||
@@ -16,7 +16,7 @@ from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
from . import get_device
|
||||
|
||||
IR_DEVICES = ["Entrance", "Living Room", "Office", "Garage"]
|
||||
IR_DEVICES = ["Entrance", "Living Room", "Office", "Garage", "Study"]
|
||||
NON_IR_DEVICE = "Bedroom"
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ from . import get_device
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
REMOTE_DEVICES = ["Entrance", "Living Room", "Office", "Garage"]
|
||||
REMOTE_DEVICES = ["Entrance", "Living Room", "Office", "Garage", "Study"]
|
||||
|
||||
IR_PACKET = (
|
||||
"JgBGAJKVETkRORA6ERQRFBEUERQRFBE5ETkQOhAVEBUQFREUEBUQ"
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
"""Tests for Broadlink switches."""
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.broadlink.const import DOMAIN
|
||||
from homeassistant.components.broadlink.switch import (
|
||||
PLATFORM_SCHEMA,
|
||||
async_setup_platform,
|
||||
)
|
||||
from homeassistant.components.switch import (
|
||||
DOMAIN as SWITCH_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
@@ -12,6 +20,11 @@ from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
from . import get_device
|
||||
|
||||
IR_PACKET = (
|
||||
"JgBGAJKVETkRORA6ERQRFBEUERQRFBE5ETkQOhAVEBUQFREUEBUQ"
|
||||
"OhEUERQRORE5EBURFBA6EBUQOhE5EBUQFRA6EDoRFBEADQUAAA=="
|
||||
)
|
||||
|
||||
|
||||
async def test_switch_setup_works(
|
||||
hass: HomeAssistant,
|
||||
@@ -132,3 +145,34 @@ async def test_slots_switch_turn_off_turn_on(
|
||||
assert hass.states.get(switch.entity_id).state == STATE_ON
|
||||
|
||||
assert mock_setup.api.auth.call_count == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"device_name", ["Entrance", "Living Room", "Office", "Garage", "Study"]
|
||||
)
|
||||
async def test_custom_ir_switch_setup_works(
|
||||
hass: HomeAssistant, device_name: str
|
||||
) -> None:
|
||||
"""Test a custom IR switch from YAML is added to each type of remote."""
|
||||
device = get_device(device_name)
|
||||
mock_setup = await device.setup_entry(hass)
|
||||
|
||||
config = PLATFORM_SCHEMA(
|
||||
{
|
||||
"platform": DOMAIN,
|
||||
"mac": device.mac,
|
||||
"switches": [
|
||||
{"name": "Fan", "command_on": IR_PACKET, "command_off": IR_PACKET}
|
||||
],
|
||||
}
|
||||
)
|
||||
await async_setup_platform(hass, config, MagicMock())
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity_ids = hass.states.async_entity_ids(SWITCH_DOMAIN)
|
||||
assert len(entity_ids) == 1
|
||||
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN, SERVICE_TURN_ON, {"entity_id": entity_ids[0]}, blocking=True
|
||||
)
|
||||
assert mock_setup.api.send_data.call_count == 1
|
||||
|
||||
Reference in New Issue
Block a user