hass-core/homeassistant/components/blebox/button.py
Michał Huryn ca93aacc57
Add blebox tvLiftBox support (#74395)
* Added tvLiftBox support.

* Changes after @epenet code review.

* After @epenet code review, dictionaries moved to relevant modules.

* Import path changed to full path.

* Removed redundant code in BLEBOX_TO_<platform>_DEVICE_CLASSES for switch and button platforms.

* Post isort on covers.

* Added tests, required version bump. As property was added inside dependency.
2022-07-11 12:24:37 +02:00

48 lines
1.6 KiB
Python

"""BleBox button entities implementation."""
from __future__ import annotations
from homeassistant.components.button import ButtonDeviceClass, ButtonEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import BleBoxEntity, create_blebox_entities
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up a BleBox button entry."""
create_blebox_entities(
hass, config_entry, async_add_entities, BleBoxButtonEntity, "buttons"
)
class BleBoxButtonEntity(BleBoxEntity, ButtonEntity):
"""Representation of BleBox buttons."""
def __init__(self, feature):
"""Initialize a BleBox button feature."""
super().__init__(feature)
self._attr_device_class = ButtonDeviceClass.UPDATE
self._attr_icon = self.get_icon()
def get_icon(self):
"""Return icon for endpoint."""
if "up" in self._feature.query_string:
return "mdi:arrow-up-circle"
if "down" in self._feature.query_string:
return "mdi:arrow-down-circle"
if "fav" in self._feature.query_string:
return "mdi:heart-circle"
if "open" in self._feature.query_string:
return "mdi:arrow-up-circle"
if "close" in self._feature.query_string:
return "mdi:arrow-down-circle"
return ""
async def async_press(self) -> None:
"""Handle the button press."""
await self._feature.set()