mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Avoid creating bond stop action button when there are no other buttons (#64869)
This commit is contained in:
parent
70b24b7843
commit
0ca38c0928
@ -39,14 +39,16 @@ class BondButtonEntityDescription(
|
||||
"""Class to describe a Bond Button entity."""
|
||||
|
||||
|
||||
STOP_BUTTON = BondButtonEntityDescription(
|
||||
key=Action.STOP,
|
||||
name="Stop Actions",
|
||||
icon="mdi:stop-circle-outline",
|
||||
mutually_exclusive=None,
|
||||
argument=None,
|
||||
)
|
||||
|
||||
|
||||
BUTTONS: tuple[BondButtonEntityDescription, ...] = (
|
||||
BondButtonEntityDescription(
|
||||
key=Action.STOP,
|
||||
name="Stop Actions",
|
||||
icon="mdi:stop-circle-outline",
|
||||
mutually_exclusive=None,
|
||||
argument=None,
|
||||
),
|
||||
BondButtonEntityDescription(
|
||||
key=Action.TOGGLE_POWER,
|
||||
name="Toggle Power",
|
||||
@ -233,17 +235,29 @@ async def async_setup_entry(
|
||||
data = hass.data[DOMAIN][entry.entry_id]
|
||||
hub: BondHub = data[HUB]
|
||||
bpup_subs: BPUPSubscriptions = data[BPUP_SUBS]
|
||||
entities: list[BondButtonEntity] = []
|
||||
|
||||
async_add_entities(
|
||||
BondButtonEntity(hub, device, bpup_subs, description)
|
||||
for device in hub.devices
|
||||
for description in BUTTONS
|
||||
if device.has_action(description.key)
|
||||
and (
|
||||
description.mutually_exclusive is None
|
||||
or not device.has_action(description.mutually_exclusive)
|
||||
)
|
||||
)
|
||||
for device in hub.devices:
|
||||
device_entities = [
|
||||
BondButtonEntity(hub, device, bpup_subs, description)
|
||||
for description in BUTTONS
|
||||
if device.has_action(description.key)
|
||||
and (
|
||||
description.mutually_exclusive is None
|
||||
or not device.has_action(description.mutually_exclusive)
|
||||
)
|
||||
]
|
||||
if device_entities and device.has_action(STOP_BUTTON.key):
|
||||
# Most devices have the stop action available, but
|
||||
# we only add the stop action button if we add actions
|
||||
# since its not so useful if there are no actions to stop
|
||||
device_entities.append(
|
||||
BondButtonEntity(hub, device, bpup_subs, STOP_BUTTON)
|
||||
)
|
||||
entities.extend(device_entities)
|
||||
|
||||
if entities:
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class BondButtonEntity(BondEntity, ButtonEntity):
|
||||
|
@ -13,6 +13,15 @@ from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
from .common import patch_bond_action, patch_bond_device_state, setup_platform
|
||||
|
||||
|
||||
def ceiling_fan(name: str):
|
||||
"""Create a ceiling fan with given name."""
|
||||
return {
|
||||
"name": name,
|
||||
"type": DeviceType.CEILING_FAN,
|
||||
"actions": [Action.SET_SPEED, Action.SET_DIRECTION, Action.STOP],
|
||||
}
|
||||
|
||||
|
||||
def light_brightness_increase_decrease_only(name: str):
|
||||
"""Create a light that can only increase or decrease brightness."""
|
||||
return {
|
||||
@ -80,6 +89,18 @@ async def test_mutually_exclusive_actions(hass: core.HomeAssistant):
|
||||
assert not hass.states.async_all("button")
|
||||
|
||||
|
||||
async def test_stop_not_created_no_other_buttons(hass: core.HomeAssistant):
|
||||
"""Tests we do not create the stop button when there are no other buttons."""
|
||||
await setup_platform(
|
||||
hass,
|
||||
BUTTON_DOMAIN,
|
||||
ceiling_fan("name-1"),
|
||||
bond_device_id="test-device-id",
|
||||
)
|
||||
|
||||
assert not hass.states.async_all("button")
|
||||
|
||||
|
||||
async def test_press_button_with_argument(hass: core.HomeAssistant):
|
||||
"""Tests we can press a button with an argument."""
|
||||
await setup_platform(
|
||||
|
Loading…
x
Reference in New Issue
Block a user