mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 19:56:42 +00:00
Add vibration (#3588)
* Add vibration I don't have a device that supports vibrate, and can't find a list of patterns, maybe someone can make some nice patterns? * listen event * Mixin * move logic to mixin
This commit is contained in:
parent
2d8d6119bd
commit
11f917d5f8
28
src/state/haptic-mixin.ts
Normal file
28
src/state/haptic-mixin.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { Constructor, LitElement, PropertyValues } from "lit-element";
|
||||
import { HassBaseEl } from "./hass-base-mixin";
|
||||
|
||||
import { HapticType } from "../data/haptics";
|
||||
|
||||
const hapticPatterns = {
|
||||
success: [50, 50, 50],
|
||||
warning: [100, 50, 100],
|
||||
failure: [200, 100, 200],
|
||||
light: [50],
|
||||
medium: [100],
|
||||
heavy: [200],
|
||||
selection: [20],
|
||||
};
|
||||
|
||||
const handleHaptic = (hapticType: HapticType) => {
|
||||
navigator.vibrate(hapticPatterns[hapticType]);
|
||||
};
|
||||
|
||||
export const hapticMixin = (superClass: Constructor<LitElement & HassBaseEl>) =>
|
||||
class extends superClass {
|
||||
protected firstUpdated(changedProps: PropertyValues) {
|
||||
super.firstUpdated(changedProps);
|
||||
if (navigator.vibrate) {
|
||||
window.addEventListener("haptic", (e) => handleHaptic(e.detail));
|
||||
}
|
||||
}
|
||||
};
|
@ -9,6 +9,7 @@ import { dialogManagerMixin } from "./dialog-manager-mixin";
|
||||
import { connectionMixin } from "./connection-mixin";
|
||||
import NotificationMixin from "./notification-mixin";
|
||||
import DisconnectToastMixin from "./disconnect-toast-mixin";
|
||||
import { hapticMixin } from "./haptic-mixin";
|
||||
import { urlSyncMixin } from "./url-sync-mixin";
|
||||
import { LitElement } from "lit-element";
|
||||
|
||||
@ -27,4 +28,5 @@ export class HassElement extends ext(HassBaseMixin(LitElement), [
|
||||
dialogManagerMixin,
|
||||
urlSyncMixin,
|
||||
ZHADialogMixin,
|
||||
hapticMixin,
|
||||
]) {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user