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
2 changes: 2 additions & 0 deletions demo/src/ha-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { mockTemplate } from "./stubs/template";
import { mockEvents } from "./stubs/events";
import { mockMediaPlayer } from "./stubs/media_player";
import { HomeAssistant } from "../../src/types";
import { mockFrontend } from "./stubs/frontend";

class HaDemo extends HomeAssistantAppEl {
protected async _handleConnProm() {
Expand All @@ -35,6 +36,7 @@ class HaDemo extends HomeAssistantAppEl {
mockTemplate(hass);
mockEvents(hass);
mockMediaPlayer(hass);
mockFrontend(hass);
selectedDemoConfig.then((conf) => {
hass.addEntities(conf.entities());
if (conf.theme) {
Expand Down
7 changes: 7 additions & 0 deletions demo/src/stubs/frontend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { MockHomeAssistant } from "../../../src/fake_data/provide_hass";

export const mockFrontend = (hass: MockHomeAssistant) => {
hass.mockWS("frontend/get_user_data", () => ({
value: null,
}));
};
8 changes: 1 addition & 7 deletions hassio/src/addon-view/hassio-addon-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ class HassioAddonView extends PolymerElement {
<app-header-layout has-scrolling-region="">
<app-header fixed="" slot="header">
<app-toolbar>
<ha-menu-button
hassio
narrow="[[narrow]]"
show-menu="[[showMenu]]"
></ha-menu-button>
<ha-menu-button hassio></ha-menu-button>
<paper-icon-button
icon="hassio:arrow-left"
on-click="backTapped"
Expand Down Expand Up @@ -119,8 +115,6 @@ class HassioAddonView extends PolymerElement {
static get properties() {
return {
hass: Object,
showMenu: Boolean,
narrow: Boolean,
route: Object,
routeData: {
type: Object,
Expand Down
18 changes: 4 additions & 14 deletions hassio/src/hassio-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@ class HassioApp extends PolymerElement {
static get template() {
return html`
<template is="dom-if" if="[[hass]]">
<hassio-main
hass="[[hass]]"
narrow="[[narrow]]"
show-menu="[[showMenu]]"
route="[[route]]"
></hassio-main>
<hassio-main hass="[[hass]]" route="[[route]]"></hassio-main>
</template>
`;
}

static get properties() {
return {
hass: Object,
narrow: Boolean,
showMenu: Boolean,
route: Object,
hassioPanel: {
type: Object,
Expand All @@ -35,12 +28,9 @@ class HassioApp extends PolymerElement {
super.ready();
window.setProperties = this.setProperties.bind(this);
this.addEventListener("location-changed", () => this._locationChanged());
this.addEventListener("hass-open-menu", () => this._menuEvent(true));
this.addEventListener("hass-close-menu", () => this._menuEvent(false));
}

_menuEvent(shouldOpen) {
this.hassioPanel.fire(shouldOpen ? "hass-open-menu" : "hass-close-menu");
this.addEventListener("hass-toggle-menu", (ev) =>
this.hassioPanel.fire("hass-toggle-menu", ev.detail)
);
}

_locationChanged() {
Expand Down
11 changes: 1 addition & 10 deletions hassio/src/hassio-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,13 @@ class HassioMain extends EventsMixin(NavigateMixin(PolymerElement)) {
></hassio-data>

<template is="dom-if" if="[[!loaded]]">
<hass-loading-screen
narrow="[[narrow]]"
show-menu="[[showMenu]]"
></hass-loading-screen>
<hass-loading-screen></hass-loading-screen>
</template>

<template is="dom-if" if="[[loaded]]">
<template is="dom-if" if="[[!equalsAddon(routeData.page)]]">
<hassio-pages-with-tabs
hass="[[hass]]"
narrow="[[narrow]]"
show-menu="[[showMenu]]"
page="[[routeData.page]]"
supervisor-info="[[supervisorInfo]]"
hass-info="[[hassInfo]]"
Expand All @@ -49,8 +44,6 @@ class HassioMain extends EventsMixin(NavigateMixin(PolymerElement)) {
<template is="dom-if" if="[[equalsAddon(routeData.page)]]">
<hassio-addon-view
hass="[[hass]]"
narrow="[[narrow]]"
show-menu="[[showMenu]]"
route="[[route]]"
></hassio-addon-view>
</template>
Expand All @@ -61,8 +54,6 @@ class HassioMain extends EventsMixin(NavigateMixin(PolymerElement)) {
static get properties() {
return {
hass: Object,
narrow: Boolean,
showMenu: Boolean,
route: {
type: Object,
// Fake route object
Expand Down
8 changes: 1 addition & 7 deletions hassio/src/hassio-pages-with-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ class HassioPagesWithTabs extends NavigateMixin(PolymerElement) {
<app-header-layout id="layout" has-scrolling-region>
<app-header fixed slot="header">
<app-toolbar>
<ha-menu-button
hassio
narrow="[[narrow]]"
show-menu="[[showMenu]]"
></ha-menu-button>
<ha-menu-button hassio></ha-menu-button>
<div main-title>Hass.io</div>
<template is="dom-if" if="[[showRefreshButton(page)]]">
<paper-icon-button
Expand Down Expand Up @@ -107,8 +103,6 @@ class HassioPagesWithTabs extends NavigateMixin(PolymerElement) {
static get properties() {
return {
hass: Object,
showMenu: Boolean,
narrow: Boolean,
page: String,
supervisorInfo: Object,
hostInfo: Object,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="home-assistant-frontend",
version="20190313.0",
version="20190315.0",
description="The Home Assistant frontend",
url="https://github.com/home-assistant/home-assistant-polymer",
author="The Home Assistant Authors",
Expand Down
2 changes: 1 addition & 1 deletion src/auth/ha-authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
protected render() {
if (!this._authProviders) {
return html`
<p>[[localize('ui.panel.page-authorize.initializing')]]</p>
<p>${this.localize("ui.panel.page-authorize.initializing")}</p>
`;
}

Expand Down
16 changes: 16 additions & 0 deletions src/common/dom/media_query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Attach a media query. Listener is called right away and when it matches.
* @param mediaQuery media query to match.
* @param listener listener to call when media query changes between match/unmatch
* @returns function to remove the listener.
*/
export const listenMediaQuery = (
mediaQuery: string,
matchesChanged: (matches: boolean) => void
) => {
const mql = matchMedia(mediaQuery);
const listener = (e) => matchesChanged(e.matches);
mql.addListener(listener);
matchesChanged(mql.matches);
return () => mql.removeListener(listener);
};
22 changes: 22 additions & 0 deletions src/common/translations/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,25 @@ export const computeLocalize = (
}
};
};

/**
* Silly helper function that converts an object of placeholders to array so we
* can convert it back to an object again inside the localize func.
* @param localize
* @param key
* @param placeholders
*/
export const localizeKey = (
localize: LocalizeFunc,
key: string,
placeholders?: { [key: string]: string }
) => {
const args: [string, ...string[]] = [key];
if (placeholders) {
Object.keys(placeholders).forEach((placeholderKey) => {
args.push(placeholderKey);
args.push(placeholders[placeholderKey]);
});
}
return localize(...args);
};
2 changes: 1 addition & 1 deletion src/components/entity/state-badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class StateBadge extends LitElement {
}

protected updated(changedProps: PropertyValues) {
if (!changedProps.has("stateObj")) {
if (!changedProps.has("stateObj") || !this.stateObj) {
return;
}
const stateObj = this.stateObj;
Expand Down
5 changes: 1 addition & 4 deletions src/components/ha-menu-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import { fireEvent } from "../common/dom/fire_event";

@customElement("ha-menu-button")
class HaMenuButton extends LitElement {
@property({ type: Boolean })
public showMenu = false;

@property({ type: Boolean })
public hassio = false;

Expand All @@ -33,7 +30,7 @@ class HaMenuButton extends LitElement {
}

private _toggleMenu(): void {
fireEvent(this, this.showMenu ? "hass-close-menu" : "hass-open-menu");
fireEvent(this, "hass-toggle-menu");
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/data/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export interface CloudWebhook {
managed?: boolean;
}

export const fetchCloudStatus = (hass: HomeAssistant) =>
hass.callWS<CloudStatus>({ type: "cloud/status" });

export const createCloudhook = (hass: HomeAssistant, webhookId: string) =>
hass.callWS<CloudWebhook>({
type: "cloud/cloudhook/create",
Expand Down
3 changes: 2 additions & 1 deletion src/data/config_entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export interface ConfigFlowStepCreateEntry {
flow_id: string;
handler: string;
title: string;
data: any;
// Config entry ID
result: string;
description: string;
description_placeholders: { [key: string]: string };
}
Expand Down
Loading