mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-30 16:27:21 +00:00
Convert compute functions to TypeScript (#2055)
* Convert compute functions to TypeScript * Address review comment * Address Travis complaint * Attempt to not be dumb :)
This commit is contained in:
parent
b1a50aa0e0
commit
f92f89e8e8
@ -1,5 +1,5 @@
|
|||||||
import computeCardSize from "../common/compute-card-size";
|
|
||||||
import createCardElement from "../common/create-card-element";
|
import createCardElement from "../common/create-card-element";
|
||||||
|
import { computeCardSize } from "../common/compute-card-size";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { LovelaceCard, LovelaceConfig } from "../types";
|
import { LovelaceCard, LovelaceConfig } from "../types";
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ class HuiConditionalCard extends HTMLElement implements LovelaceCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getCardSize() {
|
public getCardSize() {
|
||||||
return computeCardSize(this._card);
|
return computeCardSize(this._card!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import { html } from "@polymer/lit-element";
|
import { html } from "@polymer/lit-element";
|
||||||
import { TemplateResult } from "lit-html";
|
import { TemplateResult } from "lit-html";
|
||||||
|
|
||||||
import computeCardSize from "../common/compute-card-size";
|
import { computeCardSize } from "../common/compute-card-size";
|
||||||
|
|
||||||
import { HuiStackCard } from "./hui-stack-card";
|
import { HuiStackCard } from "./hui-stack-card";
|
||||||
|
|
||||||
class HuiHorizontalStackCard extends HuiStackCard {
|
class HuiHorizontalStackCard extends HuiStackCard {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { html } from "@polymer/lit-element";
|
import { html } from "@polymer/lit-element";
|
||||||
|
|
||||||
import computeCardSize from "../common/compute-card-size";
|
import { computeCardSize } from "../common/compute-card-size";
|
||||||
|
|
||||||
import { HuiStackCard } from "./hui-stack-card";
|
import { HuiStackCard } from "./hui-stack-card";
|
||||||
import { TemplateResult } from "lit-html";
|
import { TemplateResult } from "lit-html";
|
||||||
|
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
export default function computeCardSize(element) {
|
|
||||||
return typeof element.getCardSize === "function" ? element.getCardSize() : 1;
|
|
||||||
}
|
|
5
src/panels/lovelace/common/compute-card-size.ts
Normal file
5
src/panels/lovelace/common/compute-card-size.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { LovelaceCard } from "../types";
|
||||||
|
|
||||||
|
export const computeCardSize = (card: LovelaceCard): number => {
|
||||||
|
return typeof card.getCardSize === "function" ? card.getCardSize() : 1;
|
||||||
|
};
|
@ -1,7 +1,9 @@
|
|||||||
|
import { HassEntities, HassEntity } from "home-assistant-js-websocket";
|
||||||
|
|
||||||
import computeDomain from "../../../common/entity/compute_domain";
|
import computeDomain from "../../../common/entity/compute_domain";
|
||||||
|
|
||||||
export default function computeNotifications(states) {
|
export const computeNotifications = (states: HassEntities): HassEntity[] => {
|
||||||
return Object.keys(states)
|
return Object.keys(states)
|
||||||
.filter((entityId) => computeDomain(entityId) === "configurator")
|
.filter((entityId) => computeDomain(entityId) === "configurator")
|
||||||
.map((entityId) => states[entityId]);
|
.map((entityId) => states[entityId]);
|
||||||
}
|
};
|
@ -23,6 +23,7 @@ import "../../components/ha-start-voice-button";
|
|||||||
import "../../components/ha-icon";
|
import "../../components/ha-icon";
|
||||||
import { loadModule, loadCSS, loadJS } from "../../common/dom/load_resource";
|
import { loadModule, loadCSS, loadJS } from "../../common/dom/load_resource";
|
||||||
import { subscribeNotifications } from "../../data/ws-notifications";
|
import { subscribeNotifications } from "../../data/ws-notifications";
|
||||||
|
import { computeNotifications } from "./common/compute-notifications";
|
||||||
import "./components/notifications/hui-notification-drawer";
|
import "./components/notifications/hui-notification-drawer";
|
||||||
import "./components/notifications/hui-notifications-button";
|
import "./components/notifications/hui-notifications-button";
|
||||||
import "./hui-unused-entities";
|
import "./hui-unused-entities";
|
||||||
@ -30,7 +31,6 @@ import "./hui-view";
|
|||||||
import debounce from "../../common/util/debounce";
|
import debounce from "../../common/util/debounce";
|
||||||
|
|
||||||
import createCardElement from "./common/create-card-element";
|
import createCardElement from "./common/create-card-element";
|
||||||
import computeNotifications from "./common/compute-notifications";
|
|
||||||
|
|
||||||
// CSS and JS should only be imported once. Modules and HTML are safe.
|
// CSS and JS should only be imported once. Modules and HTML are safe.
|
||||||
const CSS_CACHE = {};
|
const CSS_CACHE = {};
|
||||||
|
@ -7,7 +7,7 @@ import "./components/hui-card-options.ts";
|
|||||||
import applyThemesOnElement from "../../common/dom/apply_themes_on_element";
|
import applyThemesOnElement from "../../common/dom/apply_themes_on_element";
|
||||||
|
|
||||||
import createCardElement from "./common/create-card-element";
|
import createCardElement from "./common/create-card-element";
|
||||||
import computeCardSize from "./common/compute-card-size";
|
import { computeCardSize } from "./common/compute-card-size";
|
||||||
|
|
||||||
class HUIView extends PolymerElement {
|
class HUIView extends PolymerElement {
|
||||||
static get template() {
|
static get template() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user