mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 11:16:35 +00:00
Do not throw warnings when a service calls disconnects the websocket (#8932)
This commit is contained in:
parent
b518f4b03c
commit
519988326b
@ -6,3 +6,6 @@ export const callExecuteScript = (hass: HomeAssistant, sequence: Action[]) =>
|
|||||||
type: "execute_script",
|
type: "execute_script",
|
||||||
sequence,
|
sequence,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const serviceCallWillDisconnect = (domain: string, service: string) =>
|
||||||
|
domain === "homeassistant" && ["restart", "stop"].includes(service);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { ERR_CONNECTION_LOST } from "home-assistant-js-websocket";
|
||||||
import { safeLoad } from "js-yaml";
|
import { safeLoad } from "js-yaml";
|
||||||
import {
|
import {
|
||||||
css,
|
css,
|
||||||
@ -23,7 +24,11 @@ import "../../../components/ha-service-picker";
|
|||||||
import "../../../components/ha-yaml-editor";
|
import "../../../components/ha-yaml-editor";
|
||||||
import type { HaYamlEditor } from "../../../components/ha-yaml-editor";
|
import type { HaYamlEditor } from "../../../components/ha-yaml-editor";
|
||||||
import { ServiceAction } from "../../../data/script";
|
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 { haStyle } from "../../../resources/styles";
|
||||||
import "../../../styles/polymer-ha-style";
|
import "../../../styles/polymer-ha-style";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
@ -275,6 +280,14 @@ class HaPanelDevService extends LitElement {
|
|||||||
try {
|
try {
|
||||||
await callExecuteScript(this.hass, [this._serviceData]);
|
await callExecuteScript(this.hass, [this._serviceData]);
|
||||||
} catch (err) {
|
} 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, {
|
showToast(this, {
|
||||||
message:
|
message:
|
||||||
this.hass.localize(
|
this.hass.localize(
|
||||||
|
@ -3,6 +3,7 @@ import {
|
|||||||
callService,
|
callService,
|
||||||
Connection,
|
Connection,
|
||||||
ERR_INVALID_AUTH,
|
ERR_INVALID_AUTH,
|
||||||
|
ERR_CONNECTION_LOST,
|
||||||
HassConfig,
|
HassConfig,
|
||||||
subscribeConfig,
|
subscribeConfig,
|
||||||
subscribeEntities,
|
subscribeEntities,
|
||||||
@ -13,6 +14,7 @@ import { broadcastConnectionStatus } from "../data/connection-status";
|
|||||||
import { subscribeFrontendUserData } from "../data/frontend";
|
import { subscribeFrontendUserData } from "../data/frontend";
|
||||||
import { forwardHaptic } from "../data/haptics";
|
import { forwardHaptic } from "../data/haptics";
|
||||||
import { DEFAULT_PANEL } from "../data/panel";
|
import { DEFAULT_PANEL } from "../data/panel";
|
||||||
|
import { serviceCallWillDisconnect } from "../data/service";
|
||||||
import { NumberFormat } from "../data/translation";
|
import { NumberFormat } from "../data/translation";
|
||||||
import { subscribePanels } from "../data/ws-panels";
|
import { subscribePanels } from "../data/ws-panels";
|
||||||
import { translationMetadata } from "../resources/translations-metadata";
|
import { translationMetadata } from "../resources/translations-metadata";
|
||||||
@ -78,6 +80,12 @@ export const connectionMixin = <T extends Constructor<HassBaseEl>>(
|
|||||||
target
|
target
|
||||||
)) as Promise<ServiceCallResponse>;
|
)) as Promise<ServiceCallResponse>;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (
|
||||||
|
err.error.code === ERR_CONNECTION_LOST &&
|
||||||
|
serviceCallWillDisconnect(domain, service)
|
||||||
|
) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error(
|
console.error(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user