Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions hassio/src/addon-view/hassio-addon-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,15 @@ class HassioAddonInfo extends LitElement {
<ha-switch
@change=${this._startOnBootToggled}
.checked=${this.addon.boot === "auto"}
haptic
></ha-switch>
</div>
<div class="state">
<div>Auto update</div>
<ha-switch
@change=${this._autoUpdateToggled}
.checked=${this.addon.auto_update}
haptic
></ha-switch>
</div>
${this.addon.ingress
Expand All @@ -336,6 +338,7 @@ class HassioAddonInfo extends LitElement {
@change=${this._panelToggled}
.checked=${this.addon.ingress_panel}
.disabled=${this._computeCannotIngressSidebar}
haptic
></ha-switch>
${this._computeCannotIngressSidebar
? html`
Expand Down Expand Up @@ -363,6 +366,7 @@ class HassioAddonInfo extends LitElement {
<ha-switch
@change=${this._protectionToggled}
.checked=${this.addon.protected}
haptic
></ha-switch>
</div>
`
Expand Down
9 changes: 8 additions & 1 deletion hassio/src/hassio-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class HassioMain extends ProvideHassLitMixin(HassRouterPage) {
},
},
};

@property() private _supervisorInfo: HassioSupervisorInfo;
@property() private _hostInfo: HassioHostInfo;
@property() private _hassOsInfo?: HassioHassOSInfo;
Expand Down Expand Up @@ -107,6 +106,14 @@ class HassioMain extends ProvideHassLitMixin(HassRouterPage) {
})
);

// Forward haptic events to parent window.
window.addEventListener("haptic", (ev) => {
// @ts-ignore
fireEvent(window.parent, ev.type, ev.detail, {
bubbles: false,
});
});

makeDialogManager(this, document.body);
}

Expand Down
12 changes: 11 additions & 1 deletion src/components/ha-switch.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { customElement, CSSResult, css, query } from "lit-element";
import { customElement, CSSResult, css, query, property } from "lit-element";
import "@material/mwc-switch";
import { style } from "@material/mwc-switch/mwc-switch-css";
// tslint:disable-next-line
import { Switch } from "@material/mwc-switch";
import { Constructor } from "../types";
import { forwardHaptic } from "../data/haptics";
// tslint:disable-next-line
const MwcSwitch = customElements.get("mwc-switch") as Constructor<Switch>;

@customElement("ha-switch")
export class HaSwitch extends MwcSwitch {
// Generate a haptic vibration.
// Only set to true if the new value of the switch is applied right away when toggling.
// Do not add haptic when a user is required to press save.
@property({ type: Boolean }) public haptic = false;
@query("slot") private _slot!: HTMLSlotElement;

protected firstUpdated() {
Expand All @@ -22,6 +27,11 @@ export class HaSwitch extends MwcSwitch {
Boolean(this._slot.assignedNodes().length)
);
this._slot.addEventListener("click", () => (this.checked = !this.checked));
this.addEventListener("change", () => {
if (this.haptic) {
forwardHaptic("light");
}
});
}

protected static get styles(): CSSResult[] {
Expand Down