mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
cleanup
This commit is contained in:
parent
15d8b84074
commit
4d01e0a773
@ -222,34 +222,41 @@ def _async_build_button_devices(
|
|||||||
parent_device_info = parent_keypad["device_info"]
|
parent_device_info = parent_keypad["device_info"]
|
||||||
parent_name = parent_device_info["name"]
|
parent_name = parent_device_info["name"]
|
||||||
|
|
||||||
has_device_name = True
|
button_key: str | None = None
|
||||||
if not (device_name := device.get("device_name")):
|
button_name: str
|
||||||
|
device_name = cast(str | None, device.get("device_name"))
|
||||||
|
user_defined_name = bool(device_name)
|
||||||
|
if device_name:
|
||||||
|
button_name = device_name
|
||||||
|
else:
|
||||||
# device name (button name) is missing, probably a caseta pico
|
# device name (button name) is missing, probably a caseta pico
|
||||||
# try to get the name using the button number from the triggers
|
# try to get the name using the button number from the triggers
|
||||||
# disable the button by default
|
# disable the button by default
|
||||||
has_device_name = False
|
|
||||||
keypad_device = all_devices[device["parent_device"]]
|
keypad_device = all_devices[device["parent_device"]]
|
||||||
button_numbers = LEAP_TO_DEVICE_TYPE_SUBTYPE_MAP.get(
|
button_numbers = LEAP_TO_DEVICE_TYPE_SUBTYPE_MAP.get(
|
||||||
keypad_device["type"],
|
keypad_device["type"],
|
||||||
{},
|
{},
|
||||||
)
|
)
|
||||||
device_name = (
|
button_key = button_numbers.get(int(device["button_number"]))
|
||||||
button_numbers.get(
|
button_name = (
|
||||||
int(device["button_number"]),
|
button_key
|
||||||
f"button {device['button_number']}",
|
or f"button {device['button_number']}".replace("_", " ").title()
|
||||||
)
|
|
||||||
.replace("_", " ")
|
|
||||||
.title()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Append the child device name to the end of the parent keypad
|
# Append the child device name to the end of the parent keypad
|
||||||
# name to create the entity name
|
# name to create the entity name
|
||||||
full_name = f"{parent_name} {device_name}"
|
full_name = f"{parent_name} {button_name}"
|
||||||
# Set the device_info to the same as the Parent Keypad
|
# Set the device_info to the same as the Parent Keypad
|
||||||
# The entities will be nested inside the keypad device
|
# The entities will be nested inside the keypad device
|
||||||
buttons.append(
|
buttons.append(
|
||||||
LutronCasetaButtonDevice(
|
LutronCasetaButtonDevice(
|
||||||
button_id, device, full_name, has_device_name, parent_device_info
|
button_id,
|
||||||
|
device,
|
||||||
|
button_key,
|
||||||
|
button_name,
|
||||||
|
full_name,
|
||||||
|
user_defined_name,
|
||||||
|
parent_device_info,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ async def async_setup_entry(
|
|||||||
class LutronCasetaButton(LutronCasetaDevice, ButtonEntity):
|
class LutronCasetaButton(LutronCasetaDevice, ButtonEntity):
|
||||||
"""Representation of a Lutron pico and keypad button."""
|
"""Representation of a Lutron pico and keypad button."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
data: LutronCasetaData,
|
data: LutronCasetaData,
|
||||||
@ -32,8 +34,8 @@ class LutronCasetaButton(LutronCasetaDevice, ButtonEntity):
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Init a button entity."""
|
"""Init a button entity."""
|
||||||
super().__init__(button_device.device, data)
|
super().__init__(button_device.device, data)
|
||||||
self._attr_entity_registry_enabled_default = button_device.has_device_name
|
self._attr_entity_registry_enabled_default = button_device.user_defined_name
|
||||||
self._attr_name = button_device.full_name
|
self._attr_name = button_device.button_name
|
||||||
self._attr_device_info = button_device.parent_device_info
|
self._attr_device_info = button_device.parent_device_info
|
||||||
|
|
||||||
async def async_press(self) -> None:
|
async def async_press(self) -> None:
|
||||||
|
@ -39,6 +39,7 @@ class LutronCasetaButtonEvent(LutronCasetaDevice, EventEntity):
|
|||||||
|
|
||||||
_attr_device_class = EventDeviceClass.BUTTON
|
_attr_device_class = EventDeviceClass.BUTTON
|
||||||
_attr_event_types = [ACTION_PRESS, ACTION_RELEASE]
|
_attr_event_types = [ACTION_PRESS, ACTION_RELEASE]
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -48,7 +49,8 @@ class LutronCasetaButtonEvent(LutronCasetaDevice, EventEntity):
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Init a button event entity."""
|
"""Init a button event entity."""
|
||||||
super().__init__(button_device.device, data)
|
super().__init__(button_device.device, data)
|
||||||
self._attr_name = button_device.full_name
|
self._attr_name = button_device.button_name
|
||||||
|
self._attr_translation_key = button_device.button_key
|
||||||
self._attr_device_info = button_device.parent_device_info
|
self._attr_device_info = button_device.parent_device_info
|
||||||
self._button_id = button_device.button_id
|
self._button_id = button_device.button_id
|
||||||
self._entry_id = entry_id
|
self._entry_id = entry_id
|
||||||
|
@ -41,8 +41,10 @@ class LutronCasetaButtonDevice:
|
|||||||
|
|
||||||
button_id: int
|
button_id: int
|
||||||
device: dict
|
device: dict
|
||||||
|
button_key: str | None
|
||||||
|
button_name: str
|
||||||
full_name: str
|
full_name: str
|
||||||
has_device_name: bool
|
user_defined_name: bool
|
||||||
parent_device_info: DeviceInfo
|
parent_device_info: DeviceInfo
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user