Do not throw warnings when a service calls disconnects the websocket (#8932)

This commit is contained in:
J. Nick Koston 2021-04-16 17:59:10 -10:00 committed by GitHub
parent b518f4b03c
commit 519988326b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View File

@ -6,3 +6,6 @@ export const callExecuteScript = (hass: HomeAssistant, sequence: Action[]) =>
type: "execute_script",
sequence,
});
export const serviceCallWillDisconnect = (domain: string, service: string) =>
domain === "homeassistant" && ["restart", "stop"].includes(service);

View File

@ -1,3 +1,4 @@
import { ERR_CONNECTION_LOST } from "home-assistant-js-websocket";
import { safeLoad } from "js-yaml";
import {
css,
@ -23,7 +24,11 @@ import "../../../components/ha-service-picker";
import "../../../components/ha-yaml-editor";
import type { HaYamlEditor } from "../../../components/ha-yaml-editor";
import { ServiceAction } from "../../../data/script";
import { callExecuteScript } from "../../../data/service";
import { forwardHaptic } from "../../../data/haptics";
import {
callExecuteScript,
serviceCallWillDisconnect,
} from "../../../data/service";
import { haStyle } from "../../../resources/styles";
import "../../../styles/polymer-ha-style";
import { HomeAssistant } from "../../../types";
@ -275,6 +280,14 @@ class HaPanelDevService extends LitElement {
try {
await callExecuteScript(this.hass, [this._serviceData]);
} catch (err) {
const [domain, service] = this._serviceData.service.split(".", 2);
if (
err.error.code === ERR_CONNECTION_LOST &&
serviceCallWillDisconnect(domain, service)
) {
return;
}
forwardHaptic("failure");
showToast(this, {
message:
this.hass.localize(

View File

@ -3,6 +3,7 @@ import {
callService,
Connection,
ERR_INVALID_AUTH,
ERR_CONNECTION_LOST,
HassConfig,
subscribeConfig,
subscribeEntities,
@ -13,6 +14,7 @@ import { broadcastConnectionStatus } from "../data/connection-status";
import { subscribeFrontendUserData } from "../data/frontend";
import { forwardHaptic } from "../data/haptics";
import { DEFAULT_PANEL } from "../data/panel";
import { serviceCallWillDisconnect } from "../data/service";
import { NumberFormat } from "../data/translation";
import { subscribePanels } from "../data/ws-panels";
import { translationMetadata } from "../resources/translations-metadata";
@ -78,6 +80,12 @@ export const connectionMixin = <T extends Constructor<HassBaseEl>>(
target
)) as Promise<ServiceCallResponse>;
} catch (err) {
if (
err.error.code === ERR_CONNECTION_LOST &&
serviceCallWillDisconnect(domain, service)
) {
throw err;
}
if (__DEV__) {
// eslint-disable-next-line no-console
console.error(