mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Convert configurator to use markdown (#10668)
This commit is contained in:
parent
a83e741dc7
commit
62a740ba22
@ -50,15 +50,19 @@ def async_request_config(
|
|||||||
|
|
||||||
Will return an ID to be used for sequent calls.
|
Will return an ID to be used for sequent calls.
|
||||||
"""
|
"""
|
||||||
|
if link_name is not None and link_url is not None:
|
||||||
|
description += '\n\n[{}]({})'.format(link_name, link_url)
|
||||||
|
|
||||||
|
if description_image is not None:
|
||||||
|
description += '\n\n'.format(description_image)
|
||||||
|
|
||||||
instance = hass.data.get(_KEY_INSTANCE)
|
instance = hass.data.get(_KEY_INSTANCE)
|
||||||
|
|
||||||
if instance is None:
|
if instance is None:
|
||||||
instance = hass.data[_KEY_INSTANCE] = Configurator(hass)
|
instance = hass.data[_KEY_INSTANCE] = Configurator(hass)
|
||||||
|
|
||||||
request_id = instance.async_request_config(
|
request_id = instance.async_request_config(
|
||||||
name, callback,
|
name, callback, description, submit_caption, fields, entity_picture)
|
||||||
description, description_image, submit_caption,
|
|
||||||
fields, link_name, link_url, entity_picture)
|
|
||||||
|
|
||||||
if DATA_REQUESTS not in hass.data:
|
if DATA_REQUESTS not in hass.data:
|
||||||
hass.data[DATA_REQUESTS] = {}
|
hass.data[DATA_REQUESTS] = {}
|
||||||
@ -137,9 +141,8 @@ class Configurator(object):
|
|||||||
|
|
||||||
@async_callback
|
@async_callback
|
||||||
def async_request_config(
|
def async_request_config(
|
||||||
self, name, callback,
|
self, name, callback, description, submit_caption, fields,
|
||||||
description, description_image, submit_caption,
|
entity_picture):
|
||||||
fields, link_name, link_url, entity_picture):
|
|
||||||
"""Set up a request for configuration."""
|
"""Set up a request for configuration."""
|
||||||
entity_id = async_generate_entity_id(
|
entity_id = async_generate_entity_id(
|
||||||
ENTITY_ID_FORMAT, name, hass=self.hass)
|
ENTITY_ID_FORMAT, name, hass=self.hass)
|
||||||
@ -161,10 +164,7 @@ class Configurator(object):
|
|||||||
data.update({
|
data.update({
|
||||||
key: value for key, value in [
|
key: value for key, value in [
|
||||||
(ATTR_DESCRIPTION, description),
|
(ATTR_DESCRIPTION, description),
|
||||||
(ATTR_DESCRIPTION_IMAGE, description_image),
|
|
||||||
(ATTR_SUBMIT_CAPTION, submit_caption),
|
(ATTR_SUBMIT_CAPTION, submit_caption),
|
||||||
(ATTR_LINK_NAME, link_name),
|
|
||||||
(ATTR_LINK_URL, link_url),
|
|
||||||
] if value is not None
|
] if value is not None
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -85,6 +85,12 @@ SCENE_SCHEMA = vol.Schema({
|
|||||||
ATTR_IS_HUE_GROUP = "is_hue_group"
|
ATTR_IS_HUE_GROUP = "is_hue_group"
|
||||||
GROUP_NAME_ALL_HUE_LIGHTS = "All Hue Lights"
|
GROUP_NAME_ALL_HUE_LIGHTS = "All Hue Lights"
|
||||||
|
|
||||||
|
CONFIG_INSTRUCTIONS = """
|
||||||
|
Press the button on the bridge to register Philips Hue with Home Assistant.
|
||||||
|
|
||||||
|

|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def _find_host_from_config(hass, filename=PHUE_CONFIG_FILE):
|
def _find_host_from_config(hass, filename=PHUE_CONFIG_FILE):
|
||||||
"""Attempt to detect host based on existing configuration."""
|
"""Attempt to detect host based on existing configuration."""
|
||||||
@ -298,10 +304,8 @@ def request_configuration(host, hass, add_devices, filename,
|
|||||||
|
|
||||||
_CONFIGURING[host] = configurator.request_config(
|
_CONFIGURING[host] = configurator.request_config(
|
||||||
"Philips Hue", hue_configuration_callback,
|
"Philips Hue", hue_configuration_callback,
|
||||||
description=("Press the button on the bridge to register Philips Hue "
|
description=CONFIG_INSTRUCTIONS,
|
||||||
"with Home Assistant."),
|
|
||||||
entity_picture="/static/images/logo_philips_hue.png",
|
entity_picture="/static/images/logo_philips_hue.png",
|
||||||
description_image="/static/images/config_philips_hue.jpg",
|
|
||||||
submit_caption="I have pressed the button"
|
submit_caption="I have pressed the button"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -44,12 +44,13 @@ class TestConfigurator(unittest.TestCase):
|
|||||||
"""Test request config with all possible info."""
|
"""Test request config with all possible info."""
|
||||||
exp_attr = {
|
exp_attr = {
|
||||||
ATTR_FRIENDLY_NAME: "Test Request",
|
ATTR_FRIENDLY_NAME: "Test Request",
|
||||||
configurator.ATTR_DESCRIPTION: "config description",
|
configurator.ATTR_DESCRIPTION: """config description
|
||||||
configurator.ATTR_DESCRIPTION_IMAGE: "config image url",
|
|
||||||
|
[link name](link url)
|
||||||
|
|
||||||
|
""",
|
||||||
configurator.ATTR_SUBMIT_CAPTION: "config submit caption",
|
configurator.ATTR_SUBMIT_CAPTION: "config submit caption",
|
||||||
configurator.ATTR_FIELDS: [],
|
configurator.ATTR_FIELDS: [],
|
||||||
configurator.ATTR_LINK_NAME: "link name",
|
|
||||||
configurator.ATTR_LINK_URL: "link url",
|
|
||||||
configurator.ATTR_ENTITY_PICTURE: "config entity picture",
|
configurator.ATTR_ENTITY_PICTURE: "config entity picture",
|
||||||
configurator.ATTR_CONFIGURE_ID: configurator.request_config(
|
configurator.ATTR_CONFIGURE_ID: configurator.request_config(
|
||||||
self.hass,
|
self.hass,
|
||||||
@ -70,7 +71,7 @@ class TestConfigurator(unittest.TestCase):
|
|||||||
state = states[0]
|
state = states[0]
|
||||||
|
|
||||||
self.assertEqual(configurator.STATE_CONFIGURE, state.state)
|
self.assertEqual(configurator.STATE_CONFIGURE, state.state)
|
||||||
assert exp_attr == dict(state.attributes)
|
assert exp_attr == state.attributes
|
||||||
|
|
||||||
def test_callback_called_on_configure(self):
|
def test_callback_called_on_configure(self):
|
||||||
"""Test if our callback gets called when configure service called."""
|
"""Test if our callback gets called when configure service called."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user