mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 00:37:13 +00:00
Invert DOMAIN alias in telegram (#144313)
This commit is contained in:
parent
66c86c0461
commit
60846434d3
@ -20,17 +20,17 @@ from homeassistant.components.telegram_bot import (
|
|||||||
ATTR_MESSAGE_TAG,
|
ATTR_MESSAGE_TAG,
|
||||||
ATTR_MESSAGE_THREAD_ID,
|
ATTR_MESSAGE_THREAD_ID,
|
||||||
ATTR_PARSER,
|
ATTR_PARSER,
|
||||||
|
DOMAIN as TELEGRAM_BOT_DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_LOCATION
|
from homeassistant.const import ATTR_LOCATION
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.reload import setup_reload_service
|
from homeassistant.helpers.reload import setup_reload_service
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import DOMAIN as TELEGRAM_DOMAIN, PLATFORMS
|
from . import DOMAIN, PLATFORMS
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DOMAIN = "telegram_bot"
|
|
||||||
ATTR_KEYBOARD = "keyboard"
|
ATTR_KEYBOARD = "keyboard"
|
||||||
ATTR_INLINE_KEYBOARD = "inline_keyboard"
|
ATTR_INLINE_KEYBOARD = "inline_keyboard"
|
||||||
ATTR_PHOTO = "photo"
|
ATTR_PHOTO = "photo"
|
||||||
@ -52,7 +52,7 @@ def get_service(
|
|||||||
) -> TelegramNotificationService:
|
) -> TelegramNotificationService:
|
||||||
"""Get the Telegram notification service."""
|
"""Get the Telegram notification service."""
|
||||||
|
|
||||||
setup_reload_service(hass, TELEGRAM_DOMAIN, PLATFORMS)
|
setup_reload_service(hass, 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)
|
||||||
|
|
||||||
@ -115,37 +115,45 @@ class TelegramNotificationService(BaseNotificationService):
|
|||||||
photos = photos if isinstance(photos, list) else [photos]
|
photos = photos if isinstance(photos, list) else [photos]
|
||||||
for photo_data in photos:
|
for photo_data in photos:
|
||||||
service_data.update(photo_data)
|
service_data.update(photo_data)
|
||||||
self.hass.services.call(DOMAIN, "send_photo", service_data=service_data)
|
self.hass.services.call(
|
||||||
|
TELEGRAM_BOT_DOMAIN, "send_photo", service_data=service_data
|
||||||
|
)
|
||||||
return None
|
return None
|
||||||
if data is not None and ATTR_VIDEO in data:
|
if data is not None and ATTR_VIDEO in data:
|
||||||
videos = data.get(ATTR_VIDEO)
|
videos = data.get(ATTR_VIDEO)
|
||||||
videos = videos if isinstance(videos, list) else [videos]
|
videos = videos if isinstance(videos, list) else [videos]
|
||||||
for video_data in videos:
|
for video_data in videos:
|
||||||
service_data.update(video_data)
|
service_data.update(video_data)
|
||||||
self.hass.services.call(DOMAIN, "send_video", service_data=service_data)
|
self.hass.services.call(
|
||||||
|
TELEGRAM_BOT_DOMAIN, "send_video", service_data=service_data
|
||||||
|
)
|
||||||
return None
|
return None
|
||||||
if data is not None and ATTR_VOICE in data:
|
if data is not None and ATTR_VOICE in data:
|
||||||
voices = data.get(ATTR_VOICE)
|
voices = data.get(ATTR_VOICE)
|
||||||
voices = voices if isinstance(voices, list) else [voices]
|
voices = voices if isinstance(voices, list) else [voices]
|
||||||
for voice_data in voices:
|
for voice_data in voices:
|
||||||
service_data.update(voice_data)
|
service_data.update(voice_data)
|
||||||
self.hass.services.call(DOMAIN, "send_voice", service_data=service_data)
|
self.hass.services.call(
|
||||||
|
TELEGRAM_BOT_DOMAIN, "send_voice", service_data=service_data
|
||||||
|
)
|
||||||
return None
|
return None
|
||||||
if data is not None and ATTR_LOCATION in data:
|
if data is not None and ATTR_LOCATION in data:
|
||||||
service_data.update(data.get(ATTR_LOCATION))
|
service_data.update(data.get(ATTR_LOCATION))
|
||||||
return self.hass.services.call(
|
return self.hass.services.call(
|
||||||
DOMAIN, "send_location", service_data=service_data
|
TELEGRAM_BOT_DOMAIN, "send_location", service_data=service_data
|
||||||
)
|
)
|
||||||
if data is not None and ATTR_DOCUMENT in data:
|
if data is not None and ATTR_DOCUMENT in data:
|
||||||
service_data.update(data.get(ATTR_DOCUMENT))
|
service_data.update(data.get(ATTR_DOCUMENT))
|
||||||
return self.hass.services.call(
|
return self.hass.services.call(
|
||||||
DOMAIN, "send_document", service_data=service_data
|
TELEGRAM_BOT_DOMAIN, "send_document", service_data=service_data
|
||||||
)
|
)
|
||||||
|
|
||||||
# Send message
|
# Send message
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"TELEGRAM NOTIFIER calling %s.send_message with %s", DOMAIN, service_data
|
"TELEGRAM NOTIFIER calling %s.send_message with %s",
|
||||||
|
TELEGRAM_BOT_DOMAIN,
|
||||||
|
service_data,
|
||||||
)
|
)
|
||||||
return self.hass.services.call(
|
return self.hass.services.call(
|
||||||
DOMAIN, "send_message", service_data=service_data
|
TELEGRAM_BOT_DOMAIN, "send_message", service_data=service_data
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user