mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Add device name fallback if no hostname in PrusaLink (#90831)
Device name fallback if no hostname in PrusaLink
This commit is contained in:
parent
49468ef5d0
commit
71697df3c2
@ -12,6 +12,7 @@ from pyprusalink import InvalidAuth, PrusaLink
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
from homeassistant.const import CONF_API_KEY, CONF_HOST
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
@ -24,8 +25,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
STEP_USER_DATA_SCHEMA = vol.Schema(
|
STEP_USER_DATA_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required("host"): str,
|
vol.Required(CONF_HOST): str,
|
||||||
vol.Required("api_key"): str,
|
vol.Required(CONF_API_KEY): str,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, str]) -> dict[str,
|
|||||||
|
|
||||||
Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
|
Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
|
||||||
"""
|
"""
|
||||||
api = PrusaLink(async_get_clientsession(hass), data["host"], data["api_key"])
|
api = PrusaLink(async_get_clientsession(hass), data[CONF_HOST], data[CONF_API_KEY])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with async_timeout.timeout(5):
|
async with async_timeout.timeout(5):
|
||||||
@ -51,7 +52,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, str]) -> dict[str,
|
|||||||
except AwesomeVersionException as err:
|
except AwesomeVersionException as err:
|
||||||
raise NotSupported from err
|
raise NotSupported from err
|
||||||
|
|
||||||
return {"title": version["hostname"]}
|
return {"title": version["hostname"] or version["text"]}
|
||||||
|
|
||||||
|
|
||||||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
@ -68,13 +69,13 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
step_id="user", data_schema=STEP_USER_DATA_SCHEMA
|
step_id="user", data_schema=STEP_USER_DATA_SCHEMA
|
||||||
)
|
)
|
||||||
|
|
||||||
host = user_input["host"].rstrip("/")
|
host = user_input[CONF_HOST].rstrip("/")
|
||||||
if not host.startswith(("http://", "https://")):
|
if not host.startswith(("http://", "https://")):
|
||||||
host = f"http://{host}"
|
host = f"http://{host}"
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"host": host,
|
CONF_HOST: host,
|
||||||
"api_key": user_input["api_key"],
|
CONF_API_KEY: user_input[CONF_API_KEY],
|
||||||
}
|
}
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user