Fix importing blueprints from forums with HTML entities (#44098)
parent
cff4f7bbbf
commit
a01cf72d67
|
@ -1,5 +1,6 @@
|
|||
"""Import logic for blueprint."""
|
||||
from dataclasses import dataclass
|
||||
import html
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
|
@ -110,7 +111,7 @@ def _extract_blueprint_from_community_topic(
|
|||
block_content = block_content.strip()
|
||||
|
||||
try:
|
||||
data = yaml.parse_yaml(block_content)
|
||||
data = yaml.parse_yaml(html.unescape(block_content))
|
||||
except HomeAssistantError:
|
||||
if block_syntax == "yaml":
|
||||
raise
|
||||
|
|
|
@ -16,6 +16,70 @@ def community_post():
|
|||
return load_fixture("blueprint/community_post.json")
|
||||
|
||||
|
||||
COMMUNITY_POST_INPUTS = {
|
||||
"remote": {
|
||||
"name": "Remote",
|
||||
"description": "IKEA remote to use",
|
||||
"selector": {
|
||||
"device": {
|
||||
"integration": "zha",
|
||||
"manufacturer": "IKEA of Sweden",
|
||||
"model": "TRADFRI remote control",
|
||||
}
|
||||
},
|
||||
},
|
||||
"light": {
|
||||
"name": "Light(s)",
|
||||
"description": "The light(s) to control",
|
||||
"selector": {"target": {"entity": {"domain": "light"}}},
|
||||
},
|
||||
"force_brightness": {
|
||||
"name": "Force turn on brightness",
|
||||
"description": 'Force the brightness to the set level below, when the "on" button on the remote is pushed and lights turn on.\n',
|
||||
"default": False,
|
||||
"selector": {"boolean": {}},
|
||||
},
|
||||
"brightness": {
|
||||
"name": "Brightness",
|
||||
"description": "Brightness of the light(s) when turning on",
|
||||
"default": 50,
|
||||
"selector": {
|
||||
"number": {
|
||||
"min": 0.0,
|
||||
"max": 100.0,
|
||||
"mode": "slider",
|
||||
"step": 1.0,
|
||||
"unit_of_measurement": "%",
|
||||
}
|
||||
},
|
||||
},
|
||||
"button_left_short": {
|
||||
"name": "Left button - short press",
|
||||
"description": "Action to run on short left button press",
|
||||
"default": [],
|
||||
"selector": {"action": {}},
|
||||
},
|
||||
"button_left_long": {
|
||||
"name": "Left button - long press",
|
||||
"description": "Action to run on long left button press",
|
||||
"default": [],
|
||||
"selector": {"action": {}},
|
||||
},
|
||||
"button_right_short": {
|
||||
"name": "Right button - short press",
|
||||
"description": "Action to run on short right button press",
|
||||
"default": [],
|
||||
"selector": {"action": {}},
|
||||
},
|
||||
"button_right_long": {
|
||||
"name": "Right button - long press",
|
||||
"description": "Action to run on long right button press",
|
||||
"default": [],
|
||||
"selector": {"action": {}},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_get_community_post_import_url():
|
||||
"""Test variations of generating import forum url."""
|
||||
assert (
|
||||
|
@ -57,10 +121,7 @@ def test_extract_blueprint_from_community_topic(community_post):
|
|||
)
|
||||
assert imported_blueprint is not None
|
||||
assert imported_blueprint.blueprint.domain == "automation"
|
||||
assert imported_blueprint.blueprint.inputs == {
|
||||
"service_to_call": None,
|
||||
"trigger_event": None,
|
||||
}
|
||||
assert imported_blueprint.blueprint.inputs == COMMUNITY_POST_INPUTS
|
||||
|
||||
|
||||
def test_extract_blueprint_from_community_topic_invalid_yaml():
|
||||
|
@ -103,11 +164,11 @@ async def test_fetch_blueprint_from_community_url(hass, aioclient_mock, communit
|
|||
)
|
||||
assert isinstance(imported_blueprint, importer.ImportedBlueprint)
|
||||
assert imported_blueprint.blueprint.domain == "automation"
|
||||
assert imported_blueprint.blueprint.inputs == {
|
||||
"service_to_call": None,
|
||||
"trigger_event": None,
|
||||
}
|
||||
assert imported_blueprint.suggested_filename == "balloob/test-topic"
|
||||
assert imported_blueprint.blueprint.inputs == COMMUNITY_POST_INPUTS
|
||||
assert (
|
||||
imported_blueprint.suggested_filename
|
||||
== "frenck/zha-ikea-five-button-remote-for-lights"
|
||||
)
|
||||
assert (
|
||||
imported_blueprint.blueprint.metadata["source_url"]
|
||||
== "https://community.home-assistant.io/t/test-topic/123/2"
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue