mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 10:47:51 +00:00
Fix lutron caseta Sunnata Keypad support (#75324)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
cd59d3ab81
commit
09aaf45f0a
@ -46,6 +46,7 @@ from .const import (
|
||||
from .device_trigger import (
|
||||
DEVICE_TYPE_SUBTYPE_MAP_TO_LIP,
|
||||
LEAP_TO_DEVICE_TYPE_SUBTYPE_MAP,
|
||||
_lutron_model_to_device_type,
|
||||
)
|
||||
from .models import LutronCasetaData
|
||||
from .util import serial_to_unique_id
|
||||
@ -281,7 +282,7 @@ def _async_subscribe_pico_remote_events(
|
||||
else:
|
||||
action = ACTION_RELEASE
|
||||
|
||||
type_ = device["type"]
|
||||
type_ = _lutron_model_to_device_type(device["model"], device["type"])
|
||||
area, name = _area_and_name_from_name(device["name"])
|
||||
leap_button_number = device["button_number"]
|
||||
lip_button_number = async_get_lip_button(type_, leap_button_number)
|
||||
|
@ -39,6 +39,13 @@ def _reverse_dict(forward_dict: dict) -> dict:
|
||||
return {v: k for k, v in forward_dict.items()}
|
||||
|
||||
|
||||
LUTRON_MODEL_TO_TYPE = {
|
||||
"RRST-W2B-XX": "SunnataKeypad_2Button",
|
||||
"RRST-W3RL-XX": "SunnataKeypad_3ButtonRaiseLower",
|
||||
"RRST-W4B-XX": "SunnataKeypad_4Button",
|
||||
}
|
||||
|
||||
|
||||
SUPPORTED_INPUTS_EVENTS_TYPES = [ACTION_PRESS, ACTION_RELEASE]
|
||||
|
||||
LUTRON_BUTTON_TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
|
||||
@ -379,9 +386,13 @@ async def async_validate_trigger_config(
|
||||
if not device:
|
||||
return config
|
||||
|
||||
if not (schema := DEVICE_TYPE_SCHEMA_MAP.get(device["type"])):
|
||||
if not (
|
||||
schema := DEVICE_TYPE_SCHEMA_MAP.get(
|
||||
_lutron_model_to_device_type(device["model"], device["type"])
|
||||
)
|
||||
):
|
||||
raise InvalidDeviceAutomationConfig(
|
||||
f"Device type {device['type']} not supported: {config[CONF_DEVICE_ID]}"
|
||||
f"Device model {device['model']} with type {device['type']} not supported: {config[CONF_DEVICE_ID]}"
|
||||
)
|
||||
|
||||
return schema(config)
|
||||
@ -396,7 +407,9 @@ async def async_get_triggers(
|
||||
if not (device := get_button_device_by_dr_id(hass, device_id)):
|
||||
raise InvalidDeviceAutomationConfig(f"Device not found: {device_id}")
|
||||
|
||||
valid_buttons = DEVICE_TYPE_SUBTYPE_MAP_TO_LEAP.get(device["type"], {})
|
||||
valid_buttons = DEVICE_TYPE_SUBTYPE_MAP_TO_LEAP.get(
|
||||
_lutron_model_to_device_type(device["model"], device["type"]), {}
|
||||
)
|
||||
|
||||
for trigger in SUPPORTED_INPUTS_EVENTS_TYPES:
|
||||
for subtype in valid_buttons:
|
||||
@ -413,10 +426,16 @@ async def async_get_triggers(
|
||||
return triggers
|
||||
|
||||
|
||||
def _device_model_to_type(model: str) -> str:
|
||||
def _device_model_to_type(device_registry_model: str) -> str:
|
||||
"""Convert a lutron_caseta device registry entry model to type."""
|
||||
_, device_type = model.split(" ")
|
||||
return device_type.replace("(", "").replace(")", "")
|
||||
model, p_device_type = device_registry_model.split(" ")
|
||||
device_type = p_device_type.replace("(", "").replace(")", "")
|
||||
return _lutron_model_to_device_type(model, device_type)
|
||||
|
||||
|
||||
def _lutron_model_to_device_type(model: str, device_type: str) -> str:
|
||||
"""Get the mapped type based on the lutron model or type."""
|
||||
return LUTRON_MODEL_TO_TYPE.get(model, device_type)
|
||||
|
||||
|
||||
async def async_attach_trigger(
|
||||
|
@ -64,8 +64,8 @@ MOCK_BUTTON_DEVICES = [
|
||||
{"Number": 11},
|
||||
],
|
||||
"leap_name": "Front Steps_Front Steps Sunnata Keypad",
|
||||
"type": "SunnataKeypad_3ButtonRaiseLower",
|
||||
"model": "PJ2-3BRL-GXX-X01",
|
||||
"type": "SunnataKeypad",
|
||||
"model": "RRST-W4B-XX",
|
||||
"serial": 43845547,
|
||||
},
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user