Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
8edac514
Unverified
Commit
8edac514
authored
5 months ago
by
Erik Montnemery
Committed by
GitHub
5 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Remove explicit templating of telegram_bot service data (#128906)
parent
f34ba9bf
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
homeassistant/components/telegram_bot/__init__.py
+8
-39
8 additions, 39 deletions
homeassistant/components/telegram_bot/__init__.py
with
8 additions
and
39 deletions
homeassistant/components/telegram_bot/__init__.py
+
8
−
39
View file @
8edac514
...
...
@@ -37,7 +37,6 @@ from homeassistant.const import (
HTTP_DIGEST_AUTHENTICATION
,
)
from
homeassistant.core
import
Context
,
HomeAssistant
,
ServiceCall
from
homeassistant.exceptions
import
TemplateError
from
homeassistant.helpers
import
config_validation
as
cv
,
issue_registry
as
ir
from
homeassistant.helpers.typing
import
ConfigType
from
homeassistant.loader
import
async_get_loaded_integration
...
...
@@ -175,14 +174,14 @@ BASE_SERVICE_SCHEMA = vol.Schema(
)
SERVICE_SCHEMA_SEND_MESSAGE
=
BASE_SERVICE_SCHEMA
.
extend
(
{
vol
.
Required
(
ATTR_MESSAGE
):
cv
.
template
,
vol
.
Optional
(
ATTR_TITLE
):
cv
.
template
}
{
vol
.
Required
(
ATTR_MESSAGE
):
cv
.
string
,
vol
.
Optional
(
ATTR_TITLE
):
cv
.
string
}
)
SERVICE_SCHEMA_SEND_FILE
=
BASE_SERVICE_SCHEMA
.
extend
(
{
vol
.
Optional
(
ATTR_URL
):
cv
.
template
,
vol
.
Optional
(
ATTR_FILE
):
cv
.
template
,
vol
.
Optional
(
ATTR_CAPTION
):
cv
.
template
,
vol
.
Optional
(
ATTR_URL
):
cv
.
string
,
vol
.
Optional
(
ATTR_FILE
):
cv
.
string
,
vol
.
Optional
(
ATTR_CAPTION
):
cv
.
string
,
vol
.
Optional
(
ATTR_USERNAME
):
cv
.
string
,
vol
.
Optional
(
ATTR_PASSWORD
):
cv
.
string
,
vol
.
Optional
(
ATTR_AUTHENTICATION
):
cv
.
string
,
...
...
@@ -196,8 +195,8 @@ SERVICE_SCHEMA_SEND_STICKER = SERVICE_SCHEMA_SEND_FILE.extend(
SERVICE_SCHEMA_SEND_LOCATION
=
BASE_SERVICE_SCHEMA
.
extend
(
{
vol
.
Required
(
ATTR_LONGITUDE
):
cv
.
template
,
vol
.
Required
(
ATTR_LATITUDE
):
cv
.
template
,
vol
.
Required
(
ATTR_LONGITUDE
):
cv
.
string
,
vol
.
Required
(
ATTR_LATITUDE
):
cv
.
string
,
}
)
...
...
@@ -229,7 +228,7 @@ SERVICE_SCHEMA_EDIT_CAPTION = vol.Schema(
cv
.
positive_int
,
vol
.
All
(
cv
.
string
,
"
last
"
)
),
vol
.
Required
(
ATTR_CHAT_ID
):
vol
.
Coerce
(
int
),
vol
.
Required
(
ATTR_CAPTION
):
cv
.
template
,
vol
.
Required
(
ATTR_CAPTION
):
cv
.
string
,
vol
.
Optional
(
ATTR_KEYBOARD_INLINE
):
cv
.
ensure_list
,
},
extra
=
vol
.
ALLOW_EXTRA
,
...
...
@@ -248,7 +247,7 @@ SERVICE_SCHEMA_EDIT_REPLYMARKUP = vol.Schema(
SERVICE_SCHEMA_ANSWER_CALLBACK_QUERY
=
vol
.
Schema
(
{
vol
.
Required
(
ATTR_MESSAGE
):
cv
.
template
,
vol
.
Required
(
ATTR_MESSAGE
):
cv
.
string
,
vol
.
Required
(
ATTR_CALLBACK_QUERY_ID
):
vol
.
Coerce
(
int
),
vol
.
Optional
(
ATTR_SHOW_ALERT
):
cv
.
boolean
,
},
...
...
@@ -402,38 +401,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async
def
async_send_telegram_message
(
service
:
ServiceCall
)
->
None
:
"""
Handle sending Telegram Bot message service calls.
"""
def
_render_template_attr
(
data
,
attribute
):
if
attribute_templ
:
=
data
.
get
(
attribute
):
if
any
(
isinstance
(
attribute_templ
,
vtype
)
for
vtype
in
(
float
,
int
,
str
)
):
data
[
attribute
]
=
attribute_templ
else
:
try
:
data
[
attribute
]
=
attribute_templ
.
async_render
(
parse_result
=
False
)
except
TemplateError
as
exc
:
_LOGGER
.
error
(
"
TemplateError in %s: %s -> %s
"
,
attribute
,
attribute_templ
.
template
,
exc
,
)
data
[
attribute
]
=
attribute_templ
.
template
msgtype
=
service
.
service
kwargs
=
dict
(
service
.
data
)
for
attribute
in
(
ATTR_MESSAGE
,
ATTR_TITLE
,
ATTR_URL
,
ATTR_FILE
,
ATTR_CAPTION
,
ATTR_LONGITUDE
,
ATTR_LATITUDE
,
):
_render_template_attr
(
kwargs
,
attribute
)
_LOGGER
.
debug
(
"
New telegram message %s: %s
"
,
msgtype
,
kwargs
)
if
msgtype
==
SERVICE_SEND_MESSAGE
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment