Add knx.save_scene action (#186719)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Matthias Alphart
2026-10-16 08:17:25 -04:00
committed by GitHub
co-authored by Claude Opus 5.5
parent a52df4a58a
commit fe298d3dd8
7 changed files with 63 additions and 2 deletions
+1
View File
@@ -122,6 +122,7 @@ SERVICE_KNX_ATTR_REMOVE: Final = "remove"
SERVICE_KNX_EVENT_REGISTER: Final = "event_register"
SERVICE_KNX_EXPOSURE_REGISTER: Final = "exposure_register"
SERVICE_KNX_READ: Final = "read"
SERVICE_KNX_SAVE_SCENE: Final = "save_scene"
REPAIR_ISSUE_DATA_SECURE_GROUP_KEY: Final = "data_secure_group_key_issue"
REPAIR_ISSUE_ENTITY_VALIDATION_ERROR: Final = "entity_validation_error"
+3
View File
@@ -51,6 +51,9 @@
"reload": {
"service": "mdi:reload"
},
"save_scene": {
"service": "mdi:content-save-cog"
},
"send": {
"service": "mdi:email-arrow-right"
}
+4
View File
@@ -71,6 +71,10 @@ class _KnxScene(BaseScene, _KnxEntityBase):
"""Activate the scene."""
await self._device.run()
async def async_save_scene(self) -> None:
"""Tell KNX actuators to store their current state in this scene."""
await self._device.learn()
@override
def after_update_callback(self, device: XknxDevice) -> None:
"""Call after device was updated."""
+15 -2
View File
@@ -11,7 +11,7 @@ from xknx.telegram import Telegram
from xknx.telegram.address import parse_device_group_address
from xknx.telegram.apci import GroupValueRead, GroupValueResponse, GroupValueWrite
from homeassistant.const import CONF_TYPE, SERVICE_RELOAD
from homeassistant.const import CONF_TYPE, SERVICE_RELOAD, Platform
from homeassistant.core import (
HomeAssistant,
ServiceCall,
@@ -21,7 +21,10 @@ from homeassistant.core import (
)
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.service import async_register_admin_service
from homeassistant.helpers.service import (
async_register_admin_service,
async_register_platform_entity_service,
)
from homeassistant.util.json import JsonValueType
from .const import (
@@ -35,6 +38,7 @@ from .const import (
SERVICE_KNX_EVENT_REGISTER,
SERVICE_KNX_EXPOSURE_REGISTER,
SERVICE_KNX_READ,
SERVICE_KNX_SAVE_SCENE,
SERVICE_KNX_SEND,
)
from .expose import create_knx_exposure
@@ -97,6 +101,15 @@ def async_setup_services(hass: HomeAssistant) -> None:
service_reload_integration,
)
async_register_platform_entity_service(
hass,
DOMAIN,
SERVICE_KNX_SAVE_SCENE,
entity_domain=Platform.SCENE,
schema=None,
func="async_save_scene",
)
@callback
def get_knx_module(hass: HomeAssistant) -> KNXModule:
@@ -74,3 +74,8 @@ exposure_register:
selector:
boolean:
reload:
save_scene:
target:
entity:
domain: scene
integration: knx
@@ -1821,6 +1821,10 @@
"description": "Reloads the KNX integration.",
"name": "[%key:common::action::reload%]"
},
"save_scene": {
"description": "Tells KNX actuators to store their current state in the scene of the selected scene entity. Requires actuators supporting scene learning (DPT 18.001).",
"name": "Save scene"
},
"send": {
"description": "Sends arbitrary data directly to the KNX bus.",
"fields": {
+31
View File
@@ -1,5 +1,7 @@
"""Test KNX scene."""
import pytest
from homeassistant.components.knx.const import KNX_ADDRESS
from homeassistant.components.knx.schema import SceneSchema
from homeassistant.const import (
@@ -70,6 +72,35 @@ async def test_activate_knx_scene(
assert len(events) == 5
async def test_save_knx_scene(
hass: HomeAssistant, knx: KNXTestKit, caplog: pytest.LogCaptureFixture
) -> None:
"""Test saving a KNX scene sends a DPT 18.001 learn telegram."""
await knx.setup_integration(
{
SceneSchema.PLATFORM: [
{
CONF_NAME: "test",
SceneSchema.CONF_SCENE_NUMBER: 24,
KNX_ADDRESS: "1/1/1",
},
]
}
)
events = async_capture_events(hass, "state_changed")
await hass.services.async_call(
"knx", "save_scene", {"entity_id": "scene.test"}, blocking=True
)
# learn bit set on the 0-based raw scene number
await knx.assert_write("1/1/1", (0x97,))
# saving is not an activation
assert len(events) == 0
# the outgoing telegram is decodable by the device processing it
assert "Can not process" not in caplog.text
async def test_scene_ui_create(
hass: HomeAssistant,
knx: KNXTestKit,