mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Add buttons to Motionblinds BLE integration (#114227)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
parent
7b56643278
commit
6423501498
@ -807,6 +807,7 @@ omit =
|
||||
homeassistant/components/motion_blinds/entity.py
|
||||
homeassistant/components/motion_blinds/sensor.py
|
||||
homeassistant/components/motionblinds_ble/__init__.py
|
||||
homeassistant/components/motionblinds_ble/button.py
|
||||
homeassistant/components/motionblinds_ble/cover.py
|
||||
homeassistant/components/motionblinds_ble/entity.py
|
||||
homeassistant/components/motionblinds_ble/select.py
|
||||
|
@ -28,7 +28,7 @@ from .const import CONF_BLIND_TYPE, CONF_MAC_CODE, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORMS: list[Platform] = [Platform.COVER, Platform.SELECT]
|
||||
PLATFORMS: list[Platform] = [Platform.BUTTON, Platform.COVER, Platform.SELECT]
|
||||
|
||||
CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
|
||||
|
||||
|
88
homeassistant/components/motionblinds_ble/button.py
Normal file
88
homeassistant/components/motionblinds_ble/button.py
Normal file
@ -0,0 +1,88 @@
|
||||
"""Button entities for the Motionblinds BLE integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable, Coroutine
|
||||
from dataclasses import dataclass
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from motionblindsble.device import MotionDevice
|
||||
|
||||
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import ATTR_CONNECT, ATTR_DISCONNECT, ATTR_FAVORITE, CONF_MAC_CODE, DOMAIN
|
||||
from .entity import MotionblindsBLEEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class MotionblindsBLEButtonEntityDescription(ButtonEntityDescription):
|
||||
"""Entity description of a button entity with command attribute."""
|
||||
|
||||
command: Callable[[MotionDevice], Coroutine[Any, Any, None]]
|
||||
|
||||
|
||||
BUTTON_TYPES: list[MotionblindsBLEButtonEntityDescription] = [
|
||||
MotionblindsBLEButtonEntityDescription(
|
||||
key=ATTR_CONNECT,
|
||||
translation_key=ATTR_CONNECT,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
command=lambda device: device.connect(),
|
||||
),
|
||||
MotionblindsBLEButtonEntityDescription(
|
||||
key=ATTR_DISCONNECT,
|
||||
translation_key=ATTR_DISCONNECT,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
command=lambda device: device.disconnect(),
|
||||
),
|
||||
MotionblindsBLEButtonEntityDescription(
|
||||
key=ATTR_FAVORITE,
|
||||
translation_key=ATTR_FAVORITE,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
command=lambda device: device.favorite(),
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up button entities based on a config entry."""
|
||||
|
||||
device: MotionDevice = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
async_add_entities(
|
||||
MotionblindsBLEButtonEntity(
|
||||
device,
|
||||
entry,
|
||||
entity_description,
|
||||
unique_id_suffix=entity_description.key,
|
||||
)
|
||||
for entity_description in BUTTON_TYPES
|
||||
)
|
||||
|
||||
|
||||
class MotionblindsBLEButtonEntity(MotionblindsBLEEntity, ButtonEntity):
|
||||
"""Representation of a button entity."""
|
||||
|
||||
entity_description: MotionblindsBLEButtonEntityDescription
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Log button entity information."""
|
||||
_LOGGER.debug(
|
||||
"(%s) Setting up %s button entity",
|
||||
self.entry.data[CONF_MAC_CODE],
|
||||
self.entity_description.key,
|
||||
)
|
||||
|
||||
async def async_press(self) -> None:
|
||||
"""Handle the button press."""
|
||||
await self.entity_description.command(self.device)
|
@ -1,5 +1,8 @@
|
||||
"""Constants for the Motionblinds BLE integration."""
|
||||
|
||||
ATTR_CONNECT = "connect"
|
||||
ATTR_DISCONNECT = "disconnect"
|
||||
ATTR_FAVORITE = "favorite"
|
||||
ATTR_SPEED = "speed"
|
||||
|
||||
CONF_LOCAL_NAME = "local_name"
|
||||
|
15
homeassistant/components/motionblinds_ble/icon.json
Normal file
15
homeassistant/components/motionblinds_ble/icon.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"entity": {
|
||||
"button": {
|
||||
"connect": {
|
||||
"default": "mdi:bluetooth"
|
||||
},
|
||||
"disconnect": {
|
||||
"default": "mdi:bluetooth-off"
|
||||
},
|
||||
"favorite": {
|
||||
"default": "mdi:star"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -35,6 +35,17 @@
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"button": {
|
||||
"connect": {
|
||||
"name": "[%key:common::action::connect%]"
|
||||
},
|
||||
"disconnect": {
|
||||
"name": "[%key:common::action::disconnect%]"
|
||||
},
|
||||
"favorite": {
|
||||
"name": "Favorite"
|
||||
}
|
||||
},
|
||||
"select": {
|
||||
"speed": {
|
||||
"name": "Speed",
|
||||
|
Loading…
x
Reference in New Issue
Block a user