mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-09 02:49:51 +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) {
|
||||
return;
|
||||
}
|
||||
forwardHaptic("light");
|
||||
forwardHaptic(this, "light");
|
||||
const stateDomain = computeStateDomain(this.stateObj);
|
||||
let serviceDomain;
|
||||
let service;
|
||||
|
||||
@@ -15,7 +15,7 @@ export class HaSwitch extends SwitchBase {
|
||||
super.firstUpdated();
|
||||
this.addEventListener("change", () => {
|
||||
if (this.haptic) {
|
||||
forwardHaptic("light");
|
||||
forwardHaptic(this, "light");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1087,7 +1087,7 @@ ${rejected
|
||||
name: computeStateName(scene),
|
||||
}),
|
||||
});
|
||||
forwardHaptic("light");
|
||||
forwardHaptic(this, "light");
|
||||
};
|
||||
|
||||
private _deleteConfirm(scene: SceneEntity): void {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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!);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ class HuiInputSelectEntityRow extends LitElement implements LovelaceRow {
|
||||
return;
|
||||
}
|
||||
|
||||
forwardHaptic("light");
|
||||
forwardHaptic(this, "light");
|
||||
|
||||
setInputSelectOption(this.hass!, stateObj.entity_id, option);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ class HuiSelectEntityRow extends LitElement implements LovelaceRow {
|
||||
return;
|
||||
}
|
||||
|
||||
forwardHaptic("light");
|
||||
forwardHaptic(this, "light");
|
||||
|
||||
setSelectOption(this.hass!, stateObj.entity_id, option);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class HaSetVibrateRow extends LitElement {
|
||||
fireEvent(this, "hass-vibrate", {
|
||||
vibrate,
|
||||
});
|
||||
forwardHaptic("light");
|
||||
forwardHaptic(this, "light");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user