diff --git a/homeassistant/components/rest/__init__.py b/homeassistant/components/rest/__init__.py index e0b743c1d37..69bc6172341 100644 --- a/homeassistant/components/rest/__init__.py +++ b/homeassistant/components/rest/__init__.py @@ -1,4 +1,4 @@ """The rest component.""" DOMAIN = "rest" -PLATFORMS = ["binary_sensor", "sensor", "switch"] +PLATFORMS = ["binary_sensor", "notify", "sensor", "switch"] diff --git a/homeassistant/components/rest/notify.py b/homeassistant/components/rest/notify.py index 9860334afbf..d7ee57b4f8e 100644 --- a/homeassistant/components/rest/notify.py +++ b/homeassistant/components/rest/notify.py @@ -28,6 +28,9 @@ from homeassistant.const import ( HTTP_OK, ) import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.reload import setup_reload_service + +from . import DOMAIN, PLATFORMS CONF_DATA = "data" CONF_DATA_TEMPLATE = "data_template" @@ -67,6 +70,8 @@ _LOGGER = logging.getLogger(__name__) def get_service(hass, config, discovery_info=None): """Get the RESTful notification service.""" + setup_reload_service(hass, DOMAIN, PLATFORMS) + resource = config.get(CONF_RESOURCE) method = config.get(CONF_METHOD) headers = config.get(CONF_HEADERS) diff --git a/homeassistant/components/rest/services.yaml b/homeassistant/components/rest/services.yaml index 717859d0c12..06baa8734f2 100644 --- a/homeassistant/components/rest/services.yaml +++ b/homeassistant/components/rest/services.yaml @@ -1,2 +1,2 @@ reload: - description: Reload all rest entities. + description: Reload all rest entities and notify services. diff --git a/homeassistant/helpers/reload.py b/homeassistant/helpers/reload.py index 19a1e46a6d4..89fcf45c29a 100644 --- a/homeassistant/helpers/reload.py +++ b/homeassistant/helpers/reload.py @@ -141,6 +141,12 @@ def async_get_platform( hass: HomeAssistantType, integration_name: str, integration_platform_name: str ) -> Optional[EntityPlatform]: """Find an existing platform.""" + if ( + DATA_ENTITY_PLATFORM not in hass.data + or integration_name not in hass.data[DATA_ENTITY_PLATFORM] + ): + return None + for integration_platform in hass.data[DATA_ENTITY_PLATFORM][integration_name]: if integration_platform.domain == integration_platform_name: platform: EntityPlatform = integration_platform diff --git a/tests/components/rest/test_notify.py b/tests/components/rest/test_notify.py new file mode 100644 index 00000000000..49f3876b97c --- /dev/null +++ b/tests/components/rest/test_notify.py @@ -0,0 +1,52 @@ +"""The tests for the rest.notify platform.""" +from os import path + +from homeassistant import config as hass_config +import homeassistant.components.notify as notify +from homeassistant.components.rest import DOMAIN +from homeassistant.const import SERVICE_RELOAD +from homeassistant.setup import async_setup_component + +from tests.async_mock import patch + + +async def test_reload_notify(hass): + """Verify we can reload the notify service.""" + + assert await async_setup_component( + hass, + notify.DOMAIN, + { + notify.DOMAIN: [ + { + "name": DOMAIN, + "platform": DOMAIN, + "resource": "http://127.0.0.1/off", + }, + ] + }, + ) + await hass.async_block_till_done() + + assert hass.services.has_service(notify.DOMAIN, DOMAIN) + + yaml_path = path.join( + _get_fixtures_base_path(), + "fixtures", + "rest/configuration.yaml", + ) + with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path): + await hass.services.async_call( + DOMAIN, + SERVICE_RELOAD, + {}, + blocking=True, + ) + await hass.async_block_till_done() + + assert not hass.services.has_service(notify.DOMAIN, DOMAIN) + assert hass.services.has_service(notify.DOMAIN, "rest_reloaded") + + +def _get_fixtures_base_path(): + return path.dirname(path.dirname(path.dirname(__file__))) diff --git a/tests/fixtures/rest/configuration.yaml b/tests/fixtures/rest/configuration.yaml index 7848a429026..69a4e771ebf 100644 --- a/tests/fixtures/rest/configuration.yaml +++ b/tests/fixtures/rest/configuration.yaml @@ -3,3 +3,8 @@ sensor: resource: "http://localhost" method: GET name: rollout + +notify: + - name: rest_reloaded + platform: rest + resource: http://127.0.0.1/on