forwardHaptic on node rather than window. (#27251)

forwardHaptic on node rather than window. Allows for capturing for custom cards.
This commit is contained in:
dcapslock
2025-09-30 14:49:32 +10:00
committed by GitHub
parent 60e07075bc
commit 1e1514e7da
21 changed files with 32 additions and 32 deletions

View File

@@ -112,7 +112,7 @@ export class HaEntityToggle extends LitElement {
if (!this.hass || !this.stateObj) {
return;
}
forwardHaptic("light");
forwardHaptic(this, "light");
const stateDomain = computeStateDomain(this.stateObj);
let serviceDomain;
let service;

View File

@@ -15,7 +15,7 @@ export class HaSwitch extends SwitchBase {
super.firstUpdated();
this.addEventListener("change", () => {
if (this.haptic) {
forwardHaptic("light");
forwardHaptic(this, "light");
}
});
}

View File

@@ -28,6 +28,6 @@ declare global {
}
}
export const forwardHaptic = (hapticType: HapticType) => {
fireEvent(window, "haptic", hapticType);
export const forwardHaptic = (node: HTMLElement, hapticType: HapticType) => {
fireEvent(node, "haptic", hapticType);
};

View File

@@ -42,7 +42,7 @@ class MoreInfoFan extends LitElement {
private _toggle = () => {
const service = this.stateObj?.state === "on" ? "turn_off" : "turn_on";
forwardHaptic("light");
forwardHaptic(this, "light");
this.hass.callService("fan", service, {
entity_id: this.stateObj!.entity_id,
});

View File

@@ -310,7 +310,7 @@ class MoreInfoLight extends LitElement {
private _toggle = () => {
const service = this.stateObj?.state === "on" ? "turn_off" : "turn_on";
forwardHaptic("light");
forwardHaptic(this, "light");
this.hass.callService("light", service, {
entity_id: this.stateObj!.entity_id,
});

View File

@@ -210,10 +210,10 @@ export class ZHAClusterAttributes extends LitElement {
this._readingAttribute = true;
try {
this._attributeValue = await readAttributeValue(this.hass, data);
forwardHaptic("success");
forwardHaptic(this, "success");
button.actionSuccess();
} catch (_err: any) {
forwardHaptic("failure");
forwardHaptic(this, "failure");
button.actionError();
} finally {
this._readingAttribute = false;

View File

@@ -1087,7 +1087,7 @@ ${rejected
name: computeStateName(scene),
}),
});
forwardHaptic("light");
forwardHaptic(this, "light");
};
private _deleteConfirm(scene: SceneEntity): void {

View File

@@ -443,7 +443,7 @@ class HaPanelDevAction extends LitElement {
const button = ev.currentTarget as HaProgressButton;
if (this._yamlMode && !this._yamlValid) {
forwardHaptic("failure");
forwardHaptic(this, "failure");
button.actionError();
this._error = this.hass.localize(
"ui.panel.developer-tools.tabs.actions.errors.yaml.invalid_yaml"
@@ -465,7 +465,7 @@ class HaPanelDevAction extends LitElement {
);
if (this._error !== undefined) {
forwardHaptic("failure");
forwardHaptic(this, "failure");
button.actionError();
return;
}
@@ -534,7 +534,7 @@ class HaPanelDevAction extends LitElement {
) {
return;
}
forwardHaptic("failure");
forwardHaptic(this, "failure");
button.actionError();
let localizedErrorMessage: string | undefined;

View File

@@ -177,7 +177,7 @@ class HuiAreaControlsCardFeature
.map((entityId) => this.hass!.states[entityId] as HassEntity | undefined)
.filter((v): v is HassEntity => Boolean(v));
forwardHaptic("light");
forwardHaptic(this, "light");
toggleGroupEntities(this.hass, entities);
}

View File

@@ -69,7 +69,7 @@ class HuiLockCommandsCardFeature
if (!this.hass || !this._stateObj || !service) {
return;
}
forwardHaptic("light");
forwardHaptic(this, "light");
callProtectedLockService(this, this.hass, this._stateObj, service);
}

View File

@@ -112,7 +112,7 @@ class HuiToggleCardFeature extends LitElement implements LovelaceCardFeature {
if (!this.hass || !this._stateObj) {
return;
}
forwardHaptic("light");
forwardHaptic(this, "light");
const stateDomain = computeDomain(this._stateObj.entity_id);
const serviceDomain = stateDomain;
const service = turnOn ? "turn_on" : "turn_off";

View File

@@ -53,7 +53,7 @@ export const handleAction = async (
(e) => e.user === hass!.user?.id
))
) {
forwardHaptic("warning");
forwardHaptic(node, "warning");
let serviceName;
if (
@@ -107,7 +107,7 @@ export const handleAction = async (
"ui.panel.lovelace.cards.actions.no_entity_more_info"
),
});
forwardHaptic("failure");
forwardHaptic(node, "failure");
}
break;
}
@@ -122,7 +122,7 @@ export const handleAction = async (
"ui.panel.lovelace.cards.actions.no_navigation_path"
),
});
forwardHaptic("failure");
forwardHaptic(node, "failure");
}
break;
case "url": {
@@ -132,21 +132,21 @@ export const handleAction = async (
showToast(node, {
message: hass.localize("ui.panel.lovelace.cards.actions.no_url"),
});
forwardHaptic("failure");
forwardHaptic(node, "failure");
}
break;
}
case "toggle": {
if (config.entity) {
toggleEntity(hass, config.entity!);
forwardHaptic("light");
forwardHaptic(node, "light");
} else {
showToast(node, {
message: hass.localize(
"ui.panel.lovelace.cards.actions.no_entity_toggle"
),
});
forwardHaptic("failure");
forwardHaptic(node, "failure");
}
break;
}
@@ -156,7 +156,7 @@ export const handleAction = async (
showToast(node, {
message: hass.localize("ui.panel.lovelace.cards.actions.no_action"),
});
forwardHaptic("failure");
forwardHaptic(node, "failure");
return;
}
const [domain, service] = (actionConfig.perform_action ||
@@ -167,7 +167,7 @@ export const handleAction = async (
actionConfig.data ?? actionConfig.service_data,
actionConfig.target
);
forwardHaptic("light");
forwardHaptic(node, "light");
break;
}
case "assist": {

View File

@@ -58,7 +58,7 @@ class HuiEntitiesToggle extends LitElement {
`;
private _callService(ev: MouseEvent): void {
forwardHaptic("light");
forwardHaptic(this, "light");
const turnOn = (ev.target as HaSwitch).checked;
turnOnOffEntities(this.hass!, this._toggleEntities!, turnOn!);
}

View File

@@ -103,7 +103,7 @@ class HuiInputSelectEntityRow extends LitElement implements LovelaceRow {
return;
}
forwardHaptic("light");
forwardHaptic(this, "light");
setInputSelectOption(this.hass!, stateObj.entity_id, option);
}

View File

@@ -104,7 +104,7 @@ class HuiSelectEntityRow extends LitElement implements LovelaceRow {
return;
}
forwardHaptic("light");
forwardHaptic(this, "light");
setSelectOption(this.hass!, stateObj.entity_id, option);
}

View File

@@ -39,7 +39,7 @@ class HaSetVibrateRow extends LitElement {
fireEvent(this, "hass-vibrate", {
vibrate,
});
forwardHaptic("light");
forwardHaptic(this, "light");
}
}

View File

@@ -40,7 +40,7 @@ export class HaStateControlCoverToggle extends LitElement {
if (!this.hass || !this.stateObj) {
return;
}
forwardHaptic("light");
forwardHaptic(this, "light");
await this.hass.callService(
"cover",

View File

@@ -46,7 +46,7 @@ export class HaStateControlToggle extends LitElement {
if (!this.hass || !this.stateObj) {
return;
}
forwardHaptic("light");
forwardHaptic(this, "light");
const stateDomain = computeDomain(this.stateObj.entity_id);
let serviceDomain;
let service;

View File

@@ -68,7 +68,7 @@ export class HaStateControlLockToggle extends LitElement {
if (!this.hass || !this.stateObj) {
return;
}
forwardHaptic("light");
forwardHaptic(this, "light");
fireEvent(this, "lock-service-called");
callProtectedLockService(
this,

View File

@@ -40,7 +40,7 @@ export class HaStateControlValveToggle extends LitElement {
if (!this.hass || !this.stateObj) {
return;
}
forwardHaptic("light");
forwardHaptic(this, "light");
await this.hass.callService(
"valve",

View File

@@ -127,7 +127,7 @@ export const connectionMixin = <T extends Constructor<HassBaseEl>>(
);
}
if (notifyOnError) {
forwardHaptic("failure");
forwardHaptic(this, "failure");
const lokalize = await this.hass!.loadBackendTranslation(
"exceptions",
err.translation_domain