mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 04:08:19 -04:00
Keep the Lutron Caséta bridge connected on an unmapped button number (#184579)
This commit is contained in:
@@ -438,7 +438,10 @@ def async_get_lip_button(device_type: str, leap_button: int) -> int | None:
|
||||
leap_button_num_to_name := LEAP_TO_DEVICE_TYPE_SUBTYPE_MAP.get(device_type)
|
||||
) is None:
|
||||
return None
|
||||
return lip_buttons_name_to_num[leap_button_num_to_name[leap_button]]
|
||||
# Some devices report button numbers their mapping doesn't list
|
||||
if (button_name := leap_button_num_to_name.get(leap_button)) is None:
|
||||
return None
|
||||
return lip_buttons_name_to_num.get(button_name)
|
||||
|
||||
|
||||
@callback
|
||||
@@ -473,7 +476,7 @@ def _async_subscribe_keypad_events(
|
||||
lip_button_number = async_get_lip_button(keypad_type, leap_button_number)
|
||||
button_type = LEAP_TO_DEVICE_TYPE_SUBTYPE_MAP.get(
|
||||
keypad_type, leap_to_keypad_button_names[keypad_device_id]
|
||||
)[leap_button_number]
|
||||
).get(leap_button_number)
|
||||
|
||||
hass.bus.async_fire(
|
||||
LUTRON_CASETA_BUTTON_EVENT,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""The tests for Lutron Caséta device triggers."""
|
||||
|
||||
from pylutron_caseta import BUTTON_STATUS_PRESSED
|
||||
import pytest
|
||||
from pytest_unordered import unordered
|
||||
|
||||
@@ -14,7 +15,9 @@ from homeassistant.components.lutron_caseta import (
|
||||
)
|
||||
from homeassistant.components.lutron_caseta.const import (
|
||||
ACTION_LONG_PRESS,
|
||||
ACTION_PRESS,
|
||||
ACTION_RELEASE,
|
||||
ATTR_BUTTON_NUMBER,
|
||||
ATTR_BUTTON_TYPE,
|
||||
ATTR_LEAP_BUTTON_NUMBER,
|
||||
BUTTON_STATUS_LONG_HOLD,
|
||||
@@ -407,6 +410,35 @@ async def test_unknown_leap_event_type_maps_to_release_action(
|
||||
assert captured[0].data[ATTR_ACTION] == ACTION_RELEASE
|
||||
|
||||
|
||||
class MockUnknownButtonBridge(MockBridge):
|
||||
"""Mock bridge with a button number its keypad type doesn't list."""
|
||||
|
||||
def load_buttons(self):
|
||||
"""Load mock buttons with an unknown button number."""
|
||||
buttons = super().load_buttons()
|
||||
buttons["111"]["button_number"] = 26
|
||||
return buttons
|
||||
|
||||
|
||||
async def test_unknown_leap_button_number_fires_event(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test a button number missing from the keypad mapping still fires an event."""
|
||||
config_entry_id = await _async_setup_lutron_with_picos(
|
||||
hass, MockUnknownButtonBridge
|
||||
)
|
||||
bridge = hass.config_entries.async_get_entry(config_entry_id).runtime_data.bridge
|
||||
captured = async_capture_events(hass, LUTRON_CASETA_BUTTON_EVENT)
|
||||
|
||||
bridge.call_button_subscribers("111", BUTTON_STATUS_PRESSED)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(captured) == 1
|
||||
assert captured[0].data[ATTR_LEAP_BUTTON_NUMBER] == 26
|
||||
assert captured[0].data[ATTR_BUTTON_NUMBER] is None
|
||||
assert captured[0].data[ATTR_ACTION] == ACTION_PRESS
|
||||
|
||||
|
||||
async def test_if_fires_on_button_event_without_lip(
|
||||
hass: HomeAssistant,
|
||||
service_calls: list[ServiceCall],
|
||||
|
||||
Reference in New Issue
Block a user