Allow homeassistant prefix for device info configuration url (#58414)
* Allow panel prefix for device info configuration url * Add to add-ons * Use homeassistant as the prefix * Update homeassistant/components/hassio/__init__.py Co-authored-by: Paulus Schoutsen <balloob@gmail.com> Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
def7c80e71
commit
d16304a201
3 changed files with 55 additions and 6 deletions
|
@ -661,6 +661,7 @@ def async_register_addons_in_dev_reg(
|
||||||
sw_version=addon[ATTR_VERSION],
|
sw_version=addon[ATTR_VERSION],
|
||||||
name=addon[ATTR_NAME],
|
name=addon[ATTR_NAME],
|
||||||
entry_type=ATTR_SERVICE,
|
entry_type=ATTR_SERVICE,
|
||||||
|
configuration_url=f"homeassistant://hassio/addon/{addon[ATTR_SLUG]}",
|
||||||
)
|
)
|
||||||
if manufacturer := addon.get(ATTR_REPOSITORY) or addon.get(ATTR_URL):
|
if manufacturer := addon.get(ATTR_REPOSITORY) or addon.get(ATTR_URL):
|
||||||
params[ATTR_MANUFACTURER] = manufacturer
|
params[ATTR_MANUFACTURER] = manufacturer
|
||||||
|
|
|
@ -8,6 +8,7 @@ from datetime import datetime, timedelta
|
||||||
from logging import Logger, getLogger
|
from logging import Logger, getLogger
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
from typing import TYPE_CHECKING, Any, Protocol
|
from typing import TYPE_CHECKING, Any, Protocol
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
@ -476,14 +477,17 @@ class EntityPlatform:
|
||||||
processed_dev_info[key] = device_info[key] # type: ignore[misc]
|
processed_dev_info[key] = device_info[key] # type: ignore[misc]
|
||||||
|
|
||||||
if "configuration_url" in device_info:
|
if "configuration_url" in device_info:
|
||||||
try:
|
configuration_url = str(device_info["configuration_url"])
|
||||||
processed_dev_info["configuration_url"] = cv.url(
|
if urlparse(configuration_url).scheme in [
|
||||||
device_info["configuration_url"]
|
"http",
|
||||||
)
|
"https",
|
||||||
except vol.Invalid:
|
"homeassistant",
|
||||||
|
]:
|
||||||
|
processed_dev_info["configuration_url"] = configuration_url
|
||||||
|
else:
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Ignoring invalid device configuration_url '%s'",
|
"Ignoring invalid device configuration_url '%s'",
|
||||||
device_info["configuration_url"],
|
configuration_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -967,6 +967,50 @@ async def test_device_info_invalid_url(hass, caplog):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_device_info_homeassistant_url(hass, caplog):
|
||||||
|
"""Test device info with homeassistant URL."""
|
||||||
|
registry = dr.async_get(hass)
|
||||||
|
registry.async_get_or_create(
|
||||||
|
config_entry_id="123",
|
||||||
|
connections=set(),
|
||||||
|
identifiers={("mqtt", "via-id")},
|
||||||
|
manufacturer="manufacturer",
|
||||||
|
model="via",
|
||||||
|
)
|
||||||
|
|
||||||
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
|
"""Mock setup entry method."""
|
||||||
|
async_add_entities(
|
||||||
|
[
|
||||||
|
# Valid device info, with homeassistant url
|
||||||
|
MockEntity(
|
||||||
|
unique_id="qwer",
|
||||||
|
device_info={
|
||||||
|
"identifiers": {("mqtt", "1234")},
|
||||||
|
"configuration_url": "homeassistant://config/mqtt",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
return True
|
||||||
|
|
||||||
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
|
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
||||||
|
entity_platform = MockEntityPlatform(
|
||||||
|
hass, platform_name=config_entry.domain, platform=platform
|
||||||
|
)
|
||||||
|
|
||||||
|
assert await entity_platform.async_setup_entry(config_entry)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(hass.states.async_entity_ids()) == 1
|
||||||
|
|
||||||
|
device = registry.async_get_device({("mqtt", "1234")})
|
||||||
|
assert device is not None
|
||||||
|
assert device.identifiers == {("mqtt", "1234")}
|
||||||
|
assert device.configuration_url == "homeassistant://config/mqtt"
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_disabled_by_integration(hass):
|
async def test_entity_disabled_by_integration(hass):
|
||||||
"""Test entity disabled by integration."""
|
"""Test entity disabled by integration."""
|
||||||
component = EntityComponent(_LOGGER, DOMAIN, hass, timedelta(seconds=20))
|
component = EntityComponent(_LOGGER, DOMAIN, hass, timedelta(seconds=20))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue