Update of core or OS will disconnect (#17170)

This commit is contained in:
Bram Kragten 2023-07-05 16:49:35 +02:00 committed by GitHub
parent 1b0423eb42
commit 507f22a5cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -10,5 +10,15 @@ export const callExecuteScript = (
sequence, sequence,
}); });
export const serviceCallWillDisconnect = (domain: string, service: string) => export const serviceCallWillDisconnect = (
domain === "homeassistant" && ["restart", "stop"].includes(service); domain: string,
service: string,
serviceData?: Record<string, any>
) =>
(domain === "homeassistant" && ["restart", "stop"].includes(service)) ||
(domain === "update" &&
service === "install" &&
[
"update.home_assistant_core_update",
"update.home_assistant_operating_system_update",
].includes(serviceData?.entity_id));

View File

@ -100,7 +100,7 @@ export const connectionMixin = <T extends Constructor<HassBaseEl>>(
} catch (err: any) { } catch (err: any) {
if ( if (
err.error?.code === ERR_CONNECTION_LOST && err.error?.code === ERR_CONNECTION_LOST &&
serviceCallWillDisconnect(domain, service) serviceCallWillDisconnect(domain, service, serviceData)
) { ) {
return { context: { id: "" } }; return { context: { id: "" } };
} }
@ -121,7 +121,12 @@ export const connectionMixin = <T extends Constructor<HassBaseEl>>(
"ui.notification_toast.service_call_failed", "ui.notification_toast.service_call_failed",
"service", "service",
`${domain}/${service}` `${domain}/${service}`
) + ` ${err.message}`; ) +
` ${
err.message || err.error?.code === ERR_CONNECTION_LOST
? "connection lost"
: "unknown error"
}`;
fireEvent(this as any, "hass-notification", { message }); fireEvent(this as any, "hass-notification", { message });
throw err; throw err;
} }