mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-09 18:36:35 +00:00
Type check as part of lint (#1780)
* Type check as part of lint * Lint * Validate service exist for call-service action * Fix for of
This commit is contained in:
parent
5774d913af
commit
e7a49192bd
@ -8,7 +8,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "script/build_frontend",
|
"build": "script/build_frontend",
|
||||||
"lint": "eslint src hassio/src gallery/src test-mocha && tslint -c tslint.json 'src/**/*.ts' 'hassio/src/**/*.ts' 'gallery/src/**/*.ts' 'test-mocha/**/*.ts' && polymer lint",
|
"lint": "eslint src hassio/src gallery/src test-mocha && tslint -c tslint.json 'src/**/*.ts' 'hassio/src/**/*.ts' 'gallery/src/**/*.ts' 'test-mocha/**/*.ts' && polymer lint && tsc",
|
||||||
"mocha": "node_modules/.bin/mocha --opts test-mocha/mocha.opts",
|
"mocha": "node_modules/.bin/mocha --opts test-mocha/mocha.opts",
|
||||||
"test": "npm run lint && npm run mocha",
|
"test": "npm run lint && npm run mocha",
|
||||||
"docker_build": "sh ./script/docker_run.sh build $npm_package_version",
|
"docker_build": "sh ./script/docker_run.sh build $npm_package_version",
|
||||||
|
@ -16,8 +16,8 @@ export const HassLocalizeLitMixin = (
|
|||||||
): Constructor<LitElement & LocalizeMixin> =>
|
): Constructor<LitElement & LocalizeMixin> =>
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
class extends LocalizeBaseMixin(superClass) {
|
class extends LocalizeBaseMixin(superClass) {
|
||||||
protected hass: HomeAssistant;
|
protected hass?: HomeAssistant;
|
||||||
protected localize: LocalizeFunc;
|
protected localize?: LocalizeFunc;
|
||||||
|
|
||||||
static get properties(): PropertyDeclarations {
|
static get properties(): PropertyDeclarations {
|
||||||
return {
|
return {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { dedupingMixin } from "@polymer/polymer/lib/utils/mixin.js";
|
|
||||||
import IntlMessageFormat from "intl-messageformat/src/main.js";
|
import IntlMessageFormat from "intl-messageformat/src/main.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,9 +42,9 @@ class HuiGlanceCard extends HassLocalizeLitMixin(LitElement)
|
|||||||
hass: {},
|
hass: {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
protected hass: HomeAssistant;
|
protected hass?: HomeAssistant;
|
||||||
protected config: Config;
|
protected config?: Config;
|
||||||
protected configEntities: EntityConfig[];
|
protected configEntities?: EntityConfig[];
|
||||||
|
|
||||||
public getCardSize() {
|
public getCardSize() {
|
||||||
return 3;
|
return 3;
|
||||||
@ -52,6 +52,16 @@ class HuiGlanceCard extends HassLocalizeLitMixin(LitElement)
|
|||||||
|
|
||||||
public setConfig(config: Config) {
|
public setConfig(config: Config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
const entities = processConfigEntities(config.entities);
|
||||||
|
|
||||||
|
for (const entity of entities) {
|
||||||
|
if (entity.tap_action === "call-service" && !entity.service) {
|
||||||
|
throw new Error(
|
||||||
|
'Missing required property "service" when tap_action is call-service'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.style.setProperty(
|
this.style.setProperty(
|
||||||
"--glance-column-width",
|
"--glance-column-width",
|
||||||
config.column_width || "20%"
|
config.column_width || "20%"
|
||||||
@ -64,19 +74,20 @@ class HuiGlanceCard extends HassLocalizeLitMixin(LitElement)
|
|||||||
this.classList.add(`theme-${config.theming}`);
|
this.classList.add(`theme-${config.theming}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.configEntities = processConfigEntities(config.entities);
|
this.configEntities = entities;
|
||||||
|
|
||||||
if (this.hass) {
|
if (this.hass) {
|
||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (!this.config) {
|
if (!this.config || !this.hass) {
|
||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
const { title } = this.config;
|
const { title } = this.config;
|
||||||
const states = this.hass.states;
|
const states = this.hass.states;
|
||||||
const entities = this.configEntities.filter(
|
const entities = this.configEntities!.filter(
|
||||||
(conf) => conf.entity in states
|
(conf) => conf.entity in states
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -138,7 +149,7 @@ class HuiGlanceCard extends HassLocalizeLitMixin(LitElement)
|
|||||||
}
|
}
|
||||||
|
|
||||||
private renderEntity(entityConf) {
|
private renderEntity(entityConf) {
|
||||||
const stateObj = this.hass.states[entityConf.entity];
|
const stateObj = this.hass!.states[entityConf.entity];
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<div
|
<div
|
||||||
@ -147,7 +158,7 @@ class HuiGlanceCard extends HassLocalizeLitMixin(LitElement)
|
|||||||
@click="${this.handleClick}"
|
@click="${this.handleClick}"
|
||||||
>
|
>
|
||||||
${
|
${
|
||||||
this.config.show_name !== false
|
this.config!.show_name !== false
|
||||||
? html`<div class="name">${
|
? html`<div class="name">${
|
||||||
"name" in entityConf
|
"name" in entityConf
|
||||||
? entityConf.name
|
? entityConf.name
|
||||||
@ -160,7 +171,7 @@ class HuiGlanceCard extends HassLocalizeLitMixin(LitElement)
|
|||||||
.overrideIcon="${entityConf.icon}"
|
.overrideIcon="${entityConf.icon}"
|
||||||
></state-badge>
|
></state-badge>
|
||||||
${
|
${
|
||||||
this.config.show_state !== false
|
this.config!.show_state !== false
|
||||||
? html`<div>${computeStateDisplay(this.localize, stateObj)}</div>`
|
? html`<div>${computeStateDisplay(this.localize, stateObj)}</div>`
|
||||||
: ""
|
: ""
|
||||||
}
|
}
|
||||||
@ -176,9 +187,9 @@ class HuiGlanceCard extends HassLocalizeLitMixin(LitElement)
|
|||||||
toggleEntity(this.hass, entityId);
|
toggleEntity(this.hass, entityId);
|
||||||
break;
|
break;
|
||||||
case "call-service": {
|
case "call-service": {
|
||||||
const [domain, service] = config.service.split(".", 2);
|
const [domain, service] = config.service!.split(".", 2);
|
||||||
const serviceData = { entity_id: entityId, ...config.service_data };
|
const serviceData = { entity_id: entityId, ...config.service_data };
|
||||||
this.hass.callService(domain, service, serviceData);
|
this.hass!.callService(domain, service, serviceData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user