mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Support reloading the telegram notify platform (#39529)
* Support reloading the telegram notify platform * services.yaml
This commit is contained in:
parent
65b227126d
commit
93555fed75
@ -1 +1,4 @@
|
|||||||
"""The telegram component."""
|
"""The telegram component."""
|
||||||
|
|
||||||
|
DOMAIN = "telegram"
|
||||||
|
PLATFORMS = ["notify"]
|
||||||
|
@ -12,6 +12,9 @@ from homeassistant.components.notify import (
|
|||||||
BaseNotificationService,
|
BaseNotificationService,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_LOCATION
|
from homeassistant.const import ATTR_LOCATION
|
||||||
|
from homeassistant.helpers.reload import setup_reload_service
|
||||||
|
|
||||||
|
from . import DOMAIN as TELEGRAM_DOMAIN, PLATFORMS
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -29,6 +32,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({vol.Required(CONF_CHAT_ID): vol.Coerce
|
|||||||
|
|
||||||
def get_service(hass, config, discovery_info=None):
|
def get_service(hass, config, discovery_info=None):
|
||||||
"""Get the Telegram notification service."""
|
"""Get the Telegram notification service."""
|
||||||
|
|
||||||
|
setup_reload_service(hass, TELEGRAM_DOMAIN, PLATFORMS)
|
||||||
chat_id = config.get(CONF_CHAT_ID)
|
chat_id = config.get(CONF_CHAT_ID)
|
||||||
return TelegramNotificationService(hass, chat_id)
|
return TelegramNotificationService(hass, chat_id)
|
||||||
|
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
reload:
|
||||||
|
description: Reload telegram notify services.
|
1
tests/components/telegram/__init__.py
Normal file
1
tests/components/telegram/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
"""Tests for telegram component."""
|
53
tests/components/telegram/test_notify.py
Normal file
53
tests/components/telegram/test_notify.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
"""The tests for the telegram.notify platform."""
|
||||||
|
from os import path
|
||||||
|
|
||||||
|
from homeassistant import config as hass_config
|
||||||
|
import homeassistant.components.notify as notify
|
||||||
|
from homeassistant.components.telegram 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."""
|
||||||
|
|
||||||
|
with patch("homeassistant.components.telegram_bot.async_setup", return_value=True):
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
notify.DOMAIN,
|
||||||
|
{
|
||||||
|
notify.DOMAIN: [
|
||||||
|
{
|
||||||
|
"name": DOMAIN,
|
||||||
|
"platform": DOMAIN,
|
||||||
|
"chat_id": 1,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert hass.services.has_service(notify.DOMAIN, DOMAIN)
|
||||||
|
|
||||||
|
yaml_path = path.join(
|
||||||
|
_get_fixtures_base_path(),
|
||||||
|
"fixtures",
|
||||||
|
"telegram/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, "telegram_reloaded")
|
||||||
|
|
||||||
|
|
||||||
|
def _get_fixtures_base_path():
|
||||||
|
return path.dirname(path.dirname(path.dirname(__file__)))
|
4
tests/fixtures/telegram/configuration.yaml
vendored
Normal file
4
tests/fixtures/telegram/configuration.yaml
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
notify:
|
||||||
|
- name: telegram_reloaded
|
||||||
|
platform: telegram
|
||||||
|
chat_id: 2
|
Loading…
x
Reference in New Issue
Block a user