Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions homeassistant/components/knx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
CONF_PORT,
CONF_TYPE,
EVENT_HOMEASSISTANT_STOP,
SERVICE_RELOAD,
Platform,
)
from homeassistant.core import Event, HomeAssistant, ServiceCall
Expand Down Expand Up @@ -312,6 +313,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
schema=SERVICE_KNX_EXPOSURE_REGISTER_SCHEMA,
)

async def _reload_integration(call: ServiceCall) -> None:
"""Reload the integration."""
await hass.config_entries.async_reload(entry.entry_id)
hass.bus.async_fire(f"event_{DOMAIN}_reloaded", context=call.context)

async_register_admin_service(hass, DOMAIN, SERVICE_RELOAD, _reload_integration)

await register_panel(hass)

return True
Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/knx/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,6 @@ exposure_register:
default: false
selector:
boolean:
reload:
name: Reload
description: Reload the KNX integration.
24 changes: 24 additions & 0 deletions tests/components/knx/test_services.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""Test KNX services."""
from unittest.mock import patch

import pytest
from xknx.telegram.apci import GroupValueResponse, GroupValueWrite

from homeassistant.components.knx import async_unload_entry as knx_async_unload_entry
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant

Expand Down Expand Up @@ -250,3 +253,24 @@ async def test_exposure_register(hass: HomeAssistant, knx: KNXTestKit) -> None:
hass.states.async_set(test_entity, STATE_OFF, {test_attribute: 25})
await knx.assert_telegram_count(1)
await knx.assert_write(test_address, (25,))


async def test_reload_service(
hass: HomeAssistant,
knx: KNXTestKit,
) -> None:
"""Test reload service."""
await knx.setup_integration({})

with patch(
"homeassistant.components.knx.async_unload_entry", wraps=knx_async_unload_entry
) as mock_unload_entry, patch(
"homeassistant.components.knx.async_setup_entry"
) as mock_setup_entry:
await hass.services.async_call(
"knx",
"reload",
blocking=True,
)
mock_unload_entry.assert_called_once()
mock_setup_entry.assert_called_once()