Add "cancel room setpoint override" button to opentherm_gw (#132162)

pull/133508/head
mvn23 2024-12-18 19:46:30 +01:00 committed by GitHub
parent 4daf6dd41d
commit 0ff2a0d66d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 51 additions and 1 deletions

View File

@ -16,7 +16,12 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import OpenThermGatewayHub
from .const import DATA_GATEWAYS, DATA_OPENTHERM_GW, GATEWAY_DEVICE_DESCRIPTION
from .const import (
DATA_GATEWAYS,
DATA_OPENTHERM_GW,
GATEWAY_DEVICE_DESCRIPTION,
THERMOSTAT_DEVICE_DESCRIPTION,
)
from .entity import OpenThermEntity, OpenThermEntityDescription
@ -30,6 +35,12 @@ class OpenThermButtonEntityDescription(
BUTTON_DESCRIPTIONS: tuple[OpenThermButtonEntityDescription, ...] = (
OpenThermButtonEntityDescription(
key="cancel_room_setpoint_override",
translation_key="cancel_room_setpoint_override",
device_description=THERMOSTAT_DEVICE_DESCRIPTION,
action=lambda hub: hub.set_room_setpoint(0),
),
OpenThermButtonEntityDescription(
key="restart_button",
device_class=ButtonDeviceClass.RESTART,

View File

@ -158,6 +158,11 @@
"name": "Programmed change has priority over override"
}
},
"button": {
"cancel_room_setpoint_override": {
"name": "Cancel room setpoint override"
}
},
"select": {
"gpio_mode_n": {
"name": "GPIO {gpio_id} mode",

View File

@ -16,6 +16,40 @@ from .conftest import MINIMAL_STATUS
from tests.common import MockConfigEntry
async def test_cancel_room_setpoint_override_button(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_config_entry: MockConfigEntry,
mock_pyotgw: MagicMock,
) -> None:
"""Test cancel room setpoint override button."""
mock_pyotgw.return_value.set_target_temp = AsyncMock(return_value=0)
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert (
button_entity_id := entity_registry.async_get_entity_id(
BUTTON_DOMAIN,
OPENTHERM_DOMAIN,
f"{mock_config_entry.data[CONF_ID]}-{OpenThermDeviceIdentifier.THERMOSTAT}-cancel_room_setpoint_override",
)
) is not None
await hass.services.async_call(
BUTTON_DOMAIN,
SERVICE_PRESS,
{
ATTR_ENTITY_ID: button_entity_id,
},
blocking=True,
)
mock_pyotgw.return_value.set_target_temp.assert_awaited_once_with(0, True)
async def test_restart_button(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,