mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-09 10:59:50 +00:00
forwardHaptic on node rather than window. (#27251)
forwardHaptic on node rather than window. Allows for capturing for custom cards.
This commit is contained in:
@@ -112,7 +112,7 @@ export class HaEntityToggle extends LitElement {
|
|||||||
if (!this.hass || !this.stateObj) {
|
if (!this.hass || !this.stateObj) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
forwardHaptic("light");
|
forwardHaptic(this, "light");
|
||||||
const stateDomain = computeStateDomain(this.stateObj);
|
const stateDomain = computeStateDomain(this.stateObj);
|
||||||
let serviceDomain;
|
let serviceDomain;
|
||||||
let service;
|
let service;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export class HaSwitch extends SwitchBase {
|
|||||||
super.firstUpdated();
|
super.firstUpdated();
|
||||||
this.addEventListener("change", () => {
|
this.addEventListener("change", () => {
|
||||||
if (this.haptic) {
|
if (this.haptic) {
|
||||||
forwardHaptic("light");
|
forwardHaptic(this, "light");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,6 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const forwardHaptic = (hapticType: HapticType) => {
|
export const forwardHaptic = (node: HTMLElement, hapticType: HapticType) => {
|
||||||
fireEvent(window, "haptic", hapticType);
|
fireEvent(node, "haptic", hapticType);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class MoreInfoFan extends LitElement {
|
|||||||
|
|
||||||
private _toggle = () => {
|
private _toggle = () => {
|
||||||
const service = this.stateObj?.state === "on" ? "turn_off" : "turn_on";
|
const service = this.stateObj?.state === "on" ? "turn_off" : "turn_on";
|
||||||
forwardHaptic("light");
|
forwardHaptic(this, "light");
|
||||||
this.hass.callService("fan", service, {
|
this.hass.callService("fan", service, {
|
||||||
entity_id: this.stateObj!.entity_id,
|
entity_id: this.stateObj!.entity_id,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ class MoreInfoLight extends LitElement {
|
|||||||
|
|
||||||
private _toggle = () => {
|
private _toggle = () => {
|
||||||
const service = this.stateObj?.state === "on" ? "turn_off" : "turn_on";
|
const service = this.stateObj?.state === "on" ? "turn_off" : "turn_on";
|
||||||
forwardHaptic("light");
|
forwardHaptic(this, "light");
|
||||||
this.hass.callService("light", service, {
|
this.hass.callService("light", service, {
|
||||||
entity_id: this.stateObj!.entity_id,
|
entity_id: this.stateObj!.entity_id,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -210,10 +210,10 @@ export class ZHAClusterAttributes extends LitElement {
|
|||||||
this._readingAttribute = true;
|
this._readingAttribute = true;
|
||||||
try {
|
try {
|
||||||
this._attributeValue = await readAttributeValue(this.hass, data);
|
this._attributeValue = await readAttributeValue(this.hass, data);
|
||||||
forwardHaptic("success");
|
forwardHaptic(this, "success");
|
||||||
button.actionSuccess();
|
button.actionSuccess();
|
||||||
} catch (_err: any) {
|
} catch (_err: any) {
|
||||||
forwardHaptic("failure");
|
forwardHaptic(this, "failure");
|
||||||
button.actionError();
|
button.actionError();
|
||||||
} finally {
|
} finally {
|
||||||
this._readingAttribute = false;
|
this._readingAttribute = false;
|
||||||
|
|||||||
@@ -1087,7 +1087,7 @@ ${rejected
|
|||||||
name: computeStateName(scene),
|
name: computeStateName(scene),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
forwardHaptic("light");
|
forwardHaptic(this, "light");
|
||||||
};
|
};
|
||||||
|
|
||||||
private _deleteConfirm(scene: SceneEntity): void {
|
private _deleteConfirm(scene: SceneEntity): void {
|
||||||
|
|||||||
@@ -443,7 +443,7 @@ class HaPanelDevAction extends LitElement {
|
|||||||
const button = ev.currentTarget as HaProgressButton;
|
const button = ev.currentTarget as HaProgressButton;
|
||||||
|
|
||||||
if (this._yamlMode && !this._yamlValid) {
|
if (this._yamlMode && !this._yamlValid) {
|
||||||
forwardHaptic("failure");
|
forwardHaptic(this, "failure");
|
||||||
button.actionError();
|
button.actionError();
|
||||||
this._error = this.hass.localize(
|
this._error = this.hass.localize(
|
||||||
"ui.panel.developer-tools.tabs.actions.errors.yaml.invalid_yaml"
|
"ui.panel.developer-tools.tabs.actions.errors.yaml.invalid_yaml"
|
||||||
@@ -465,7 +465,7 @@ class HaPanelDevAction extends LitElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (this._error !== undefined) {
|
if (this._error !== undefined) {
|
||||||
forwardHaptic("failure");
|
forwardHaptic(this, "failure");
|
||||||
button.actionError();
|
button.actionError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -534,7 +534,7 @@ class HaPanelDevAction extends LitElement {
|
|||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
forwardHaptic("failure");
|
forwardHaptic(this, "failure");
|
||||||
button.actionError();
|
button.actionError();
|
||||||
|
|
||||||
let localizedErrorMessage: string | undefined;
|
let localizedErrorMessage: string | undefined;
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ class HuiAreaControlsCardFeature
|
|||||||
.map((entityId) => this.hass!.states[entityId] as HassEntity | undefined)
|
.map((entityId) => this.hass!.states[entityId] as HassEntity | undefined)
|
||||||
.filter((v): v is HassEntity => Boolean(v));
|
.filter((v): v is HassEntity => Boolean(v));
|
||||||
|
|
||||||
forwardHaptic("light");
|
forwardHaptic(this, "light");
|
||||||
toggleGroupEntities(this.hass, entities);
|
toggleGroupEntities(this.hass, entities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class HuiLockCommandsCardFeature
|
|||||||
if (!this.hass || !this._stateObj || !service) {
|
if (!this.hass || !this._stateObj || !service) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
forwardHaptic("light");
|
forwardHaptic(this, "light");
|
||||||
callProtectedLockService(this, this.hass, this._stateObj, service);
|
callProtectedLockService(this, this.hass, this._stateObj, service);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ class HuiToggleCardFeature extends LitElement implements LovelaceCardFeature {
|
|||||||
if (!this.hass || !this._stateObj) {
|
if (!this.hass || !this._stateObj) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
forwardHaptic("light");
|
forwardHaptic(this, "light");
|
||||||
const stateDomain = computeDomain(this._stateObj.entity_id);
|
const stateDomain = computeDomain(this._stateObj.entity_id);
|
||||||
const serviceDomain = stateDomain;
|
const serviceDomain = stateDomain;
|
||||||
const service = turnOn ? "turn_on" : "turn_off";
|
const service = turnOn ? "turn_on" : "turn_off";
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export const handleAction = async (
|
|||||||
(e) => e.user === hass!.user?.id
|
(e) => e.user === hass!.user?.id
|
||||||
))
|
))
|
||||||
) {
|
) {
|
||||||
forwardHaptic("warning");
|
forwardHaptic(node, "warning");
|
||||||
|
|
||||||
let serviceName;
|
let serviceName;
|
||||||
if (
|
if (
|
||||||
@@ -107,7 +107,7 @@ export const handleAction = async (
|
|||||||
"ui.panel.lovelace.cards.actions.no_entity_more_info"
|
"ui.panel.lovelace.cards.actions.no_entity_more_info"
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
forwardHaptic("failure");
|
forwardHaptic(node, "failure");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -122,7 +122,7 @@ export const handleAction = async (
|
|||||||
"ui.panel.lovelace.cards.actions.no_navigation_path"
|
"ui.panel.lovelace.cards.actions.no_navigation_path"
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
forwardHaptic("failure");
|
forwardHaptic(node, "failure");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "url": {
|
case "url": {
|
||||||
@@ -132,21 +132,21 @@ export const handleAction = async (
|
|||||||
showToast(node, {
|
showToast(node, {
|
||||||
message: hass.localize("ui.panel.lovelace.cards.actions.no_url"),
|
message: hass.localize("ui.panel.lovelace.cards.actions.no_url"),
|
||||||
});
|
});
|
||||||
forwardHaptic("failure");
|
forwardHaptic(node, "failure");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "toggle": {
|
case "toggle": {
|
||||||
if (config.entity) {
|
if (config.entity) {
|
||||||
toggleEntity(hass, config.entity!);
|
toggleEntity(hass, config.entity!);
|
||||||
forwardHaptic("light");
|
forwardHaptic(node, "light");
|
||||||
} else {
|
} else {
|
||||||
showToast(node, {
|
showToast(node, {
|
||||||
message: hass.localize(
|
message: hass.localize(
|
||||||
"ui.panel.lovelace.cards.actions.no_entity_toggle"
|
"ui.panel.lovelace.cards.actions.no_entity_toggle"
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
forwardHaptic("failure");
|
forwardHaptic(node, "failure");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -156,7 +156,7 @@ export const handleAction = async (
|
|||||||
showToast(node, {
|
showToast(node, {
|
||||||
message: hass.localize("ui.panel.lovelace.cards.actions.no_action"),
|
message: hass.localize("ui.panel.lovelace.cards.actions.no_action"),
|
||||||
});
|
});
|
||||||
forwardHaptic("failure");
|
forwardHaptic(node, "failure");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const [domain, service] = (actionConfig.perform_action ||
|
const [domain, service] = (actionConfig.perform_action ||
|
||||||
@@ -167,7 +167,7 @@ export const handleAction = async (
|
|||||||
actionConfig.data ?? actionConfig.service_data,
|
actionConfig.data ?? actionConfig.service_data,
|
||||||
actionConfig.target
|
actionConfig.target
|
||||||
);
|
);
|
||||||
forwardHaptic("light");
|
forwardHaptic(node, "light");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "assist": {
|
case "assist": {
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class HuiEntitiesToggle extends LitElement {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
private _callService(ev: MouseEvent): void {
|
private _callService(ev: MouseEvent): void {
|
||||||
forwardHaptic("light");
|
forwardHaptic(this, "light");
|
||||||
const turnOn = (ev.target as HaSwitch).checked;
|
const turnOn = (ev.target as HaSwitch).checked;
|
||||||
turnOnOffEntities(this.hass!, this._toggleEntities!, turnOn!);
|
turnOnOffEntities(this.hass!, this._toggleEntities!, turnOn!);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ class HuiInputSelectEntityRow extends LitElement implements LovelaceRow {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
forwardHaptic("light");
|
forwardHaptic(this, "light");
|
||||||
|
|
||||||
setInputSelectOption(this.hass!, stateObj.entity_id, option);
|
setInputSelectOption(this.hass!, stateObj.entity_id, option);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class HuiSelectEntityRow extends LitElement implements LovelaceRow {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
forwardHaptic("light");
|
forwardHaptic(this, "light");
|
||||||
|
|
||||||
setSelectOption(this.hass!, stateObj.entity_id, option);
|
setSelectOption(this.hass!, stateObj.entity_id, option);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class HaSetVibrateRow extends LitElement {
|
|||||||
fireEvent(this, "hass-vibrate", {
|
fireEvent(this, "hass-vibrate", {
|
||||||
vibrate,
|
vibrate,
|
||||||
});
|
});
|
||||||
forwardHaptic("light");
|
forwardHaptic(this, "light");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export class HaStateControlCoverToggle extends LitElement {
|
|||||||
if (!this.hass || !this.stateObj) {
|
if (!this.hass || !this.stateObj) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
forwardHaptic("light");
|
forwardHaptic(this, "light");
|
||||||
|
|
||||||
await this.hass.callService(
|
await this.hass.callService(
|
||||||
"cover",
|
"cover",
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export class HaStateControlToggle extends LitElement {
|
|||||||
if (!this.hass || !this.stateObj) {
|
if (!this.hass || !this.stateObj) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
forwardHaptic("light");
|
forwardHaptic(this, "light");
|
||||||
const stateDomain = computeDomain(this.stateObj.entity_id);
|
const stateDomain = computeDomain(this.stateObj.entity_id);
|
||||||
let serviceDomain;
|
let serviceDomain;
|
||||||
let service;
|
let service;
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export class HaStateControlLockToggle extends LitElement {
|
|||||||
if (!this.hass || !this.stateObj) {
|
if (!this.hass || !this.stateObj) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
forwardHaptic("light");
|
forwardHaptic(this, "light");
|
||||||
fireEvent(this, "lock-service-called");
|
fireEvent(this, "lock-service-called");
|
||||||
callProtectedLockService(
|
callProtectedLockService(
|
||||||
this,
|
this,
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export class HaStateControlValveToggle extends LitElement {
|
|||||||
if (!this.hass || !this.stateObj) {
|
if (!this.hass || !this.stateObj) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
forwardHaptic("light");
|
forwardHaptic(this, "light");
|
||||||
|
|
||||||
await this.hass.callService(
|
await this.hass.callService(
|
||||||
"valve",
|
"valve",
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ export const connectionMixin = <T extends Constructor<HassBaseEl>>(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (notifyOnError) {
|
if (notifyOnError) {
|
||||||
forwardHaptic("failure");
|
forwardHaptic(this, "failure");
|
||||||
const lokalize = await this.hass!.loadBackendTranslation(
|
const lokalize = await this.hass!.loadBackendTranslation(
|
||||||
"exceptions",
|
"exceptions",
|
||||||
err.translation_domain
|
err.translation_domain
|
||||||
|
|||||||
Reference in New Issue
Block a user