From 70e2ff351da38a72266966a2557ce80814966815 Mon Sep 17 00:00:00 2001 From: Guy Shefer Date: Sun, 31 Dec 2023 16:39:00 +0200 Subject: [PATCH] Add Tami4 integration boil water button (#103400) * Implement boil water button * Sort platforms list * Get API directly * Cleanup * Rename boil button string Co-authored-by: Joost Lekkerkerker * Add button to .coveragerc * Change ButtonEntityDescription to EntityDescription * Update homeassistant/components/tami4/button.py * Update homeassistant/components/tami4/button.py --------- Co-authored-by: Joost Lekkerkerker --- .coveragerc | 1 + homeassistant/components/tami4/__init__.py | 2 +- homeassistant/components/tami4/button.py | 42 +++++++++++++++++++++ homeassistant/components/tami4/strings.json | 5 +++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 homeassistant/components/tami4/button.py diff --git a/.coveragerc b/.coveragerc index 44e424260c170..d17676d79c94a 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1318,6 +1318,7 @@ omit = homeassistant/components/tado/device_tracker.py homeassistant/components/tado/sensor.py homeassistant/components/tado/water_heater.py + homeassistant/components/tami4/button.py homeassistant/components/tank_utility/sensor.py homeassistant/components/tankerkoenig/__init__.py homeassistant/components/tankerkoenig/binary_sensor.py diff --git a/homeassistant/components/tami4/__init__.py b/homeassistant/components/tami4/__init__.py index 846f119493084..643363b128523 100644 --- a/homeassistant/components/tami4/__init__.py +++ b/homeassistant/components/tami4/__init__.py @@ -11,7 +11,7 @@ from .const import API, CONF_REFRESH_TOKEN, COORDINATOR, DOMAIN from .coordinator import Tami4EdgeWaterQualityCoordinator -PLATFORMS: list[Platform] = [Platform.SENSOR] +PLATFORMS: list[Platform] = [Platform.BUTTON, Platform.SENSOR] async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: diff --git a/homeassistant/components/tami4/button.py b/homeassistant/components/tami4/button.py new file mode 100644 index 0000000000000..30ff4824e18a0 --- /dev/null +++ b/homeassistant/components/tami4/button.py @@ -0,0 +1,42 @@ +"""Button entities for Tami4Edge.""" +import logging + +from Tami4EdgeAPI import Tami4EdgeAPI + +from homeassistant.components.button import ButtonEntity +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity import EntityDescription +from homeassistant.helpers.entity_platform import AddEntitiesCallback + +from .const import API, DOMAIN +from .entity import Tami4EdgeBaseEntity + +_LOGGER = logging.getLogger(__name__) + +ENTITY_DESCRIPTION = EntityDescription( + key="boil_water", + translation_key="boil_water", + icon="mdi:kettle-steam", +) + + +async def async_setup_entry( + hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback +) -> None: + """Perform the setup for Tami4Edge.""" + api: Tami4EdgeAPI = hass.data[DOMAIN][entry.entry_id][API] + + async_add_entities([Tami4EdgeBoilButton(api)]) + + +class Tami4EdgeBoilButton(Tami4EdgeBaseEntity, ButtonEntity): + """Boil button entity for Tami4Edge.""" + + def __init__(self, api: Tami4EdgeAPI) -> None: + """Initialize the button entity.""" + super().__init__(api, ENTITY_DESCRIPTION) + + def press(self) -> None: + """Handle the button press.""" + self._api.boil_water() diff --git a/homeassistant/components/tami4/strings.json b/homeassistant/components/tami4/strings.json index 9036d92d6f1a4..79447d93e9e6b 100644 --- a/homeassistant/components/tami4/strings.json +++ b/homeassistant/components/tami4/strings.json @@ -22,6 +22,11 @@ "filter_litters_passed": { "name": "Filter water passed" } + }, + "button": { + "boil_water": { + "name": "Boil water" + } } }, "config": {