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: 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="20181207.0",
version="20181210.0",
description="The Home Assistant frontend",
url="https://github.com/home-assistant/home-assistant-polymer",
author="The Home Assistant Authors",
Expand Down
3 changes: 3 additions & 0 deletions src/common/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
/** Icon to use when no icon specified for domain. */
export const DEFAULT_DOMAIN_ICON = "hass:bookmark";

/** Panel to show when no panel is picked. */
export const DEFAULT_PANEL = "states";

/** Domains that have a state card. */
export const DOMAINS_WITH_CARD = [
"climate",
Expand Down
93 changes: 5 additions & 88 deletions src/data/lovelace.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { HomeAssistant } from "../types";

export interface LovelaceConfig {
_frontendAuto: boolean;
title?: string;
views: LovelaceViewConfig[];
}

export interface LovelaceViewConfig {
index?: number;
title?: string;
badges?: string[];
cards?: LovelaceCardConfig[];
id?: string;
path?: string;
icon?: string;
theme?: string;
}

export interface LovelaceCardConfig {
id?: string;
index?: number;
view_index?: number;
type: string;
[key: string]: any;
}
Expand Down Expand Up @@ -60,95 +61,11 @@ export const fetchConfig = (
force,
});

export const migrateConfig = (hass: HomeAssistant): Promise<void> =>
hass.callWS({
type: "lovelace/config/migrate",
});

export const saveConfig = (
hass: HomeAssistant,
config: LovelaceConfig | string,
format: "json" | "yaml"
config: LovelaceConfig
): Promise<void> =>
hass.callWS({
type: "lovelace/config/save",
config,
format,
});

export const getCardConfig = (
hass: HomeAssistant,
cardId: string
): Promise<string> =>
hass.callWS({
type: "lovelace/config/card/get",
card_id: cardId,
});

export const updateCardConfig = (
hass: HomeAssistant,
cardId: string,
config: LovelaceCardConfig | string,
format: "json" | "yaml"
): Promise<void> =>
hass.callWS({
type: "lovelace/config/card/update",
card_id: cardId,
card_config: config,
format,
});

export const deleteCard = (
hass: HomeAssistant,
cardId: string
): Promise<void> =>
hass.callWS({
type: "lovelace/config/card/delete",
card_id: cardId,
});

export const addCard = (
hass: HomeAssistant,
viewId: string,
config: LovelaceCardConfig | string,
format: "json" | "yaml"
): Promise<void> =>
hass.callWS({
type: "lovelace/config/card/add",
view_id: viewId,
card_config: config,
format,
});

export const updateViewConfig = (
hass: HomeAssistant,
viewId: string,
config: LovelaceViewConfig | string,
format: "json" | "yaml"
): Promise<void> =>
hass.callWS({
type: "lovelace/config/view/update",
view_id: viewId,
view_config: config,
format,
});

export const deleteView = (
hass: HomeAssistant,
viewId: string
): Promise<void> =>
hass.callWS({
type: "lovelace/config/view/delete",
view_id: viewId,
});

export const addView = (
hass: HomeAssistant,
config: LovelaceViewConfig | string,
format: "json" | "yaml"
): Promise<void> =>
hass.callWS({
type: "lovelace/config/view/add",
view_config: config,
format,
});
3 changes: 2 additions & 1 deletion src/layouts/app/home-assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "../home-assistant-main";
import "../ha-init-page";
import "../../resources/ha-style";
import registerServiceWorker from "../../util/register-service-worker";
import { DEFAULT_PANEL } from "../../common/const";

import HassBaseMixin from "./hass-base-mixin";
import AuthMixin from "./auth-mixin";
Expand Down Expand Up @@ -94,7 +95,7 @@ class HomeAssistant extends ext(PolymerElement, [
}

computePanelUrl(routeData) {
return (routeData && routeData.panel) || "lovelace";
return (routeData && routeData.panel) || DEFAULT_PANEL;
}

panelUrlChanged(newPanelUrl) {
Expand Down
5 changes: 3 additions & 2 deletions src/layouts/home-assistant-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "./partial-panel-resolver";
import EventsMixin from "../mixins/events-mixin";
import NavigateMixin from "../mixins/navigate-mixin";
import { computeRTL } from "../common/util/compute_rtl";
import { DEFAULT_PANEL } from "../common/const";

import(/* webpackChunkName: "ha-sidebar" */ "../components/ha-sidebar");
import(/* webpackChunkName: "voice-command-dialog" */ "../dialogs/ha-voice-command-dialog");
Expand Down Expand Up @@ -98,7 +99,7 @@ class HomeAssistantMain extends NavigateMixin(EventsMixin(PolymerElement)) {

ready() {
super.ready();
this._defaultPage = localStorage.defaultPage || "lovelace";
this._defaultPage = localStorage.defaultPage || DEFAULT_PANEL;
this.addEventListener("hass-open-menu", () => this.handleOpenMenu());
this.addEventListener("hass-close-menu", () => this.handleCloseMenu());
this.addEventListener("hass-start-voice", (ev) =>
Expand Down Expand Up @@ -135,7 +136,7 @@ class HomeAssistantMain extends NavigateMixin(EventsMixin(PolymerElement)) {
connectedCallback() {
super.connectedCallback();
if (document.location.pathname === "/") {
this.navigate(`/${localStorage.defaultPage || "lovelace"}`, true);
this.navigate(`/${localStorage.defaultPage || DEFAULT_PANEL}`, true);
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/panels/dev-info/ha-panel-dev-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import formatTime from "../../common/datetime/format_time";
import EventsMixin from "../../mixins/events-mixin";
import LocalizeMixin from "../../mixins/localize-mixin";

const OPT_IN_PANEL = "lovelace";
let registeredDialog = false;

class HaPanelDevInfo extends EventsMixin(LocalizeMixin(PolymerElement)) {
Expand Down Expand Up @@ -164,7 +165,7 @@ class HaPanelDevInfo extends EventsMixin(LocalizeMixin(PolymerElement)) {
</template>
</p>
<p>
<a href='/states'>Go back to the old states page</a>
<a href='/lovelace'>Try out the new Lovelace UI</a>
<div id="love" style="cursor:pointer;" on-click="_toggleDefaultPage">[[_defaultPageText()]]</div
</p>
</div>
Expand Down Expand Up @@ -364,15 +365,15 @@ class HaPanelDevInfo extends EventsMixin(LocalizeMixin(PolymerElement)) {

_defaultPageText() {
return `>> ${
localStorage.defaultPage === "states" ? "Remove" : "Set"
} the old states as default page on this device <<`;
localStorage.defaultPage === OPT_IN_PANEL ? "Remove" : "Set"
} ${OPT_IN_PANEL} as default page on this device <<`;
}

_toggleDefaultPage() {
if (localStorage.defaultPage === "states") {
if (localStorage.defaultPage === OPT_IN_PANEL) {
delete localStorage.defaultPage;
} else {
localStorage.defaultPage = "states";
localStorage.defaultPage = OPT_IN_PANEL;
}
this.$.love.innerText = this._defaultPageText();
}
Expand Down
18 changes: 15 additions & 3 deletions src/panels/lovelace/cards/hui-light-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,14 @@ export class HuiLightCard extends hassLocalizeLitMixin(LitElement)
this._roundSliderStyle = loaded.roundSliderStyle;
this._jQuery = loaded.jQuery;

const brightness = this.hass!.states[this._config!.entity].attributes
.brightness;
const stateObj = this.hass!.states[this._config!.entity] as LightEntity;

if (!stateObj) {
return;
}

const brightness = stateObj.attributes.brightness || 0;

this._jQuery("#light", this.shadowRoot).roundSlider({
...lightConfig,
change: (value) => this._setBrightness(value),
Expand All @@ -152,7 +158,13 @@ export class HuiLightCard extends hassLocalizeLitMixin(LitElement)
return;
}

const attrs = this.hass!.states[this._config!.entity].attributes;
const stateObj = this.hass!.states[this._config!.entity];

if (!stateObj) {
return;
}

const attrs = stateObj.attributes;

this._jQuery("#light", this.shadowRoot).roundSlider({
value: Math.round((attrs.brightness / 254) * 100) || 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ class LongPress extends HTMLElement implements LongPress {
const clickEnd = (ev: Event) => {
if (
this.cooldownEnd ||
(ev instanceof TouchEvent && this.timer === undefined)
(["touchend", "touchcancel"].includes(ev.type) &&
this.timer === undefined)
) {
return;
}
Expand Down
5 changes: 2 additions & 3 deletions src/panels/lovelace/common/generate-lovelace-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const computeDefaultViewStates = (hass: HomeAssistant): HassEntities => {

const generateViewConfig = (
localize: LocalizeFunc,
id: string,
path: string,
title: string | undefined,
icon: string | undefined,
entities: HassEntities,
Expand Down Expand Up @@ -158,7 +158,7 @@ const generateViewConfig = (
});

return {
id,
path,
title,
icon,
badges,
Expand Down Expand Up @@ -228,7 +228,6 @@ export const generateLovelaceConfig = (
}

return {
_frontendAuto: true,
title,
views,
};
Expand Down
Loading