mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-16 13:56:35 +00:00
Some code improvements (#10156)
This commit is contained in:
parent
c44624282c
commit
25c1156c88
@ -1,9 +1,6 @@
|
|||||||
const gulp = require("gulp");
|
const gulp = require("gulp");
|
||||||
const fs = require("fs");
|
|
||||||
const path = require("path");
|
|
||||||
|
|
||||||
const env = require("../env");
|
const env = require("../env");
|
||||||
const paths = require("../paths");
|
|
||||||
|
|
||||||
require("./clean.js");
|
require("./clean.js");
|
||||||
require("./gen-icons-json.js");
|
require("./gen-icons-json.js");
|
||||||
|
@ -4,9 +4,6 @@ const del = require("del");
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const gulp = require("gulp");
|
const gulp = require("gulp");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const merge = require("gulp-merge-json");
|
|
||||||
const rename = require("gulp-rename");
|
|
||||||
const transform = require("gulp-json-transform");
|
|
||||||
const paths = require("../paths");
|
const paths = require("../paths");
|
||||||
|
|
||||||
const outDir = "build/locale-data";
|
const outDir = "build/locale-data";
|
||||||
|
@ -115,7 +115,7 @@ export const applyThemesOnElement = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newTheme =
|
const newTheme =
|
||||||
themeRules && cacheKey
|
Object.keys(themeRules).length && cacheKey
|
||||||
? PROCESSED_THEMES[cacheKey] || processTheme(cacheKey, themeRules)
|
? PROCESSED_THEMES[cacheKey] || processTheme(cacheKey, themeRules)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
@ -180,10 +180,10 @@ export function fuzzyScore(
|
|||||||
wordLow
|
wordLow
|
||||||
);
|
);
|
||||||
|
|
||||||
let row = 1;
|
let row: number;
|
||||||
let column = 1;
|
let column = 1;
|
||||||
let patternPos = patternStart;
|
let patternPos: number;
|
||||||
let wordPos = wordStart;
|
let wordPos: number;
|
||||||
|
|
||||||
const hasStrongFirstMatch = [false];
|
const hasStrongFirstMatch = [false];
|
||||||
|
|
||||||
|
@ -511,18 +511,16 @@ export class HaAutomationTracer extends LitElement {
|
|||||||
className: isError ? "error" : undefined,
|
className: isError ? "error" : undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// null means it was stopped by a condition
|
|
||||||
if (entry) {
|
entries.push(html`
|
||||||
entries.push(html`
|
<ha-timeline
|
||||||
<ha-timeline
|
lastItem
|
||||||
lastItem
|
.icon=${entry.icon}
|
||||||
.icon=${entry.icon}
|
class=${ifDefined(entry.className)}
|
||||||
class=${ifDefined(entry.className)}
|
>
|
||||||
>
|
${entry.description}
|
||||||
${entry.description}
|
</ha-timeline>
|
||||||
</ha-timeline>
|
`);
|
||||||
`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return html`${entries}`;
|
return html`${entries}`;
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ export class QuickBar extends LitElement {
|
|||||||
: this._entityItems;
|
: this._entityItems;
|
||||||
|
|
||||||
if (items && this._filter && this._filter !== " ") {
|
if (items && this._filter && this._filter !== " ") {
|
||||||
items = this._filterItems(items || [], this._filter);
|
items = this._filterItems(items, this._filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
|
@ -99,16 +99,12 @@ export class CloudRemotePref extends LitElement {
|
|||||||
)}</mwc-button
|
)}</mwc-button
|
||||||
>
|
>
|
||||||
</a>
|
</a>
|
||||||
${remote_certificate
|
<div class="spacer"></div>
|
||||||
? html`
|
<mwc-button @click=${this._openCertInfo}>
|
||||||
<div class="spacer"></div>
|
${this.hass.localize(
|
||||||
<mwc-button @click=${this._openCertInfo}>
|
"ui.panel.config.cloud.account.remote.certificate_info"
|
||||||
${this.hass.localize(
|
)}
|
||||||
"ui.panel.config.cloud.account.remote.certificate_info"
|
</mwc-button>
|
||||||
)}
|
|
||||||
</mwc-button>
|
|
||||||
`
|
|
||||||
: ""}
|
|
||||||
</div>
|
</div>
|
||||||
</ha-card>
|
</ha-card>
|
||||||
`;
|
`;
|
||||||
|
@ -36,7 +36,7 @@ export class DialogEnergyBatterySettings
|
|||||||
this._params = params;
|
this._params = params;
|
||||||
this._source = params.source
|
this._source = params.source
|
||||||
? { ...params.source }
|
? { ...params.source }
|
||||||
: (this._source = emptyBatteryEnergyPreference());
|
: emptyBatteryEnergyPreference();
|
||||||
}
|
}
|
||||||
|
|
||||||
public closeDialog(): void {
|
public closeDialog(): void {
|
||||||
|
@ -42,7 +42,7 @@ export class DialogEnergyGasSettings
|
|||||||
this._params = params;
|
this._params = params;
|
||||||
this._source = params.source
|
this._source = params.source
|
||||||
? { ...params.source }
|
? { ...params.source }
|
||||||
: (this._source = emptyGasEnergyPreference());
|
: emptyGasEnergyPreference();
|
||||||
this._costs = this._source.entity_energy_price
|
this._costs = this._source.entity_energy_price
|
||||||
? "entity"
|
? "entity"
|
||||||
: this._source.number_energy_price
|
: this._source.number_energy_price
|
||||||
|
@ -46,10 +46,9 @@ export class DialogEnergyGridFlowSettings
|
|||||||
this._params = params;
|
this._params = params;
|
||||||
this._source = params.source
|
this._source = params.source
|
||||||
? { ...params.source }
|
? { ...params.source }
|
||||||
: (this._source =
|
: params.direction === "from"
|
||||||
params.direction === "from"
|
? emptyFlowFromGridSourceEnergyPreference()
|
||||||
? emptyFlowFromGridSourceEnergyPreference()
|
: emptyFlowToGridSourceEnergyPreference();
|
||||||
: emptyFlowToGridSourceEnergyPreference());
|
|
||||||
this._costs = this._source.entity_energy_price
|
this._costs = this._source.entity_energy_price
|
||||||
? "entity"
|
? "entity"
|
||||||
: this._source.number_energy_price
|
: this._source.number_energy_price
|
||||||
|
@ -49,7 +49,7 @@ export class DialogEnergySolarSettings
|
|||||||
this._fetchSolarForecastConfigEntries();
|
this._fetchSolarForecastConfigEntries();
|
||||||
this._source = params.source
|
this._source = params.source
|
||||||
? { ...params.source }
|
? { ...params.source }
|
||||||
: (this._source = emptySolarEnergyPreference());
|
: emptySolarEnergyPreference();
|
||||||
this._forecast = this._source.config_entry_solar_forecast !== null;
|
this._forecast = this._source.config_entry_solar_forecast !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,7 +493,9 @@ class HaConfigZwave extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
computeEntities(selectedNode) {
|
computeEntities(selectedNode) {
|
||||||
if (!this.nodes || selectedNode === -1) return -1;
|
if (!this.nodes || selectedNode === -1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
const nodeid = this.nodes[this.selectedNode].attributes.node_id;
|
const nodeid = this.nodes[this.selectedNode].attributes.node_id;
|
||||||
const hass = this.hass;
|
const hass = this.hass;
|
||||||
return Object.keys(this.hass.states)
|
return Object.keys(this.hass.states)
|
||||||
@ -512,7 +514,9 @@ class HaConfigZwave extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
selectedNodeChanged(selectedNode) {
|
selectedNodeChanged(selectedNode) {
|
||||||
if (selectedNode === -1) return;
|
if (selectedNode === -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.selectedEntity = -1;
|
this.selectedEntity = -1;
|
||||||
|
|
||||||
this.hass
|
this.hass
|
||||||
@ -573,7 +577,9 @@ class HaConfigZwave extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
selectedEntityChanged(selectedEntity) {
|
selectedEntityChanged(selectedEntity) {
|
||||||
if (selectedEntity === -1) return;
|
if (selectedEntity === -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.hass
|
this.hass
|
||||||
.callApi(
|
.callApi(
|
||||||
"GET",
|
"GET",
|
||||||
@ -640,12 +646,16 @@ class HaConfigZwave extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
computeRefreshEntityServiceData(selectedEntity) {
|
computeRefreshEntityServiceData(selectedEntity) {
|
||||||
if (selectedEntity === -1) return -1;
|
if (selectedEntity === -1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return { entity_id: this.entities[selectedEntity].entity_id };
|
return { entity_id: this.entities[selectedEntity].entity_id };
|
||||||
}
|
}
|
||||||
|
|
||||||
computePollIntensityServiceData(entityPollingIntensity) {
|
computePollIntensityServiceData(entityPollingIntensity) {
|
||||||
if (!this.selectedNode === -1 || this.selectedEntity === -1) return -1;
|
if (this.selectedNode === -1 || this.selectedEntity === -1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
node_id: this.nodes[this.selectedNode].attributes.node_id,
|
node_id: this.nodes[this.selectedNode].attributes.node_id,
|
||||||
value_id: this.entities[this.selectedEntity].attributes.value_id,
|
value_id: this.entities[this.selectedEntity].attributes.value_id,
|
||||||
|
@ -300,12 +300,13 @@ class ZwaveGroups extends LocalizeMixin(PolymerElement) {
|
|||||||
|
|
||||||
_computeAssocServiceData(selectedGroup, type) {
|
_computeAssocServiceData(selectedGroup, type) {
|
||||||
if (
|
if (
|
||||||
!this.groups === -1 ||
|
!this.groups ||
|
||||||
selectedGroup === -1 ||
|
selectedGroup === -1 ||
|
||||||
this.selectedNode === -1 ||
|
this.selectedNode === -1 ||
|
||||||
this._selectedTargetNode === -1
|
this._selectedTargetNode === -1
|
||||||
)
|
) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
node_id: this.nodes[this.selectedNode].attributes.node_id,
|
node_id: this.nodes[this.selectedNode].attributes.node_id,
|
||||||
association: type,
|
association: type,
|
||||||
|
@ -65,7 +65,7 @@ class DialogSystemLogDetail extends LitElement {
|
|||||||
this._manifest &&
|
this._manifest &&
|
||||||
(this._manifest.is_built_in ||
|
(this._manifest.is_built_in ||
|
||||||
// Custom components with our offical docs should not link to our docs
|
// Custom components with our offical docs should not link to our docs
|
||||||
!this._manifest.documentation.includes("www.home-assistant.io"));
|
!this._manifest.documentation.includes("://www.home-assistant.io"));
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-dialog open @closed=${this.closeDialog} hideActions .heading=${true}>
|
<ha-dialog open @closed=${this.closeDialog} hideActions .heading=${true}>
|
||||||
|
@ -164,21 +164,6 @@ export class HuiEnergyDevicesGraphCard
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const statisticsData = Object.values(this._data!);
|
|
||||||
let endTime: Date;
|
|
||||||
|
|
||||||
endTime = new Date(
|
|
||||||
Math.max(
|
|
||||||
...statisticsData.map((stats) =>
|
|
||||||
stats.length ? new Date(stats[stats.length - 1].start).getTime() : 0
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!endTime || endTime > new Date()) {
|
|
||||||
endTime = new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
const data: Array<ChartDataset<"bar", ParsedDataType<"bar">>["data"]> = [];
|
const data: Array<ChartDataset<"bar", ParsedDataType<"bar">>["data"]> = [];
|
||||||
const borderColor: string[] = [];
|
const borderColor: string[] = [];
|
||||||
const backgroundColor: string[] = [];
|
const backgroundColor: string[] = [];
|
||||||
|
@ -220,21 +220,7 @@ export class HuiEnergyGasGraphCard
|
|||||||
|
|
||||||
this._unit = getEnergyGasUnit(this.hass, energyData.prefs) || "m³";
|
this._unit = getEnergyGasUnit(this.hass, energyData.prefs) || "m³";
|
||||||
|
|
||||||
const statisticsData = Object.values(energyData.stats);
|
|
||||||
const datasets: ChartDataset<"bar">[] = [];
|
const datasets: ChartDataset<"bar">[] = [];
|
||||||
let endTime: Date;
|
|
||||||
|
|
||||||
endTime = new Date(
|
|
||||||
Math.max(
|
|
||||||
...statisticsData.map((stats) =>
|
|
||||||
stats.length ? new Date(stats[stats.length - 1].start).getTime() : 0
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!endTime || endTime > new Date()) {
|
|
||||||
endTime = new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
const computedStyles = getComputedStyle(this);
|
const computedStyles = getComputedStyle(this);
|
||||||
const gasColor = computedStyles
|
const gasColor = computedStyles
|
||||||
|
@ -226,21 +226,7 @@ export class HuiEnergySolarGraphCard
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const statisticsData = Object.values(energyData.stats);
|
|
||||||
const datasets: ChartDataset<"bar">[] = [];
|
const datasets: ChartDataset<"bar">[] = [];
|
||||||
let endTime: Date;
|
|
||||||
|
|
||||||
endTime = new Date(
|
|
||||||
Math.max(
|
|
||||||
...statisticsData.map((stats) =>
|
|
||||||
stats.length ? new Date(stats[stats.length - 1].start).getTime() : 0
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!endTime || endTime > new Date()) {
|
|
||||||
endTime = new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
const computedStyles = getComputedStyle(this);
|
const computedStyles = getComputedStyle(this);
|
||||||
const solarColor = computedStyles
|
const solarColor = computedStyles
|
||||||
|
@ -88,7 +88,7 @@ export class HuiEnergyUsageGraphCard
|
|||||||
)}
|
)}
|
||||||
chart-type="bar"
|
chart-type="bar"
|
||||||
></ha-chart-base>
|
></ha-chart-base>
|
||||||
${!this._chartData.datasets.length
|
${!this._chartData.datasets.some((dataset) => dataset.data.length)
|
||||||
? html`<div class="no-data">
|
? html`<div class="no-data">
|
||||||
${isToday(this._start)
|
${isToday(this._start)
|
||||||
? "There is no data to show. It can take up to 2 hours for new data to arrive after you configure your energy dashboard."
|
? "There is no data to show. It can take up to 2 hours for new data to arrive after you configure your energy dashboard."
|
||||||
@ -228,6 +228,8 @@ export class HuiEnergyUsageGraphCard
|
|||||||
);
|
);
|
||||||
|
|
||||||
private async _getStatistics(energyData: EnergyData): Promise<void> {
|
private async _getStatistics(energyData: EnergyData): Promise<void> {
|
||||||
|
const datasets: ChartDataset<"bar">[] = [];
|
||||||
|
|
||||||
const statistics: {
|
const statistics: {
|
||||||
to_grid?: string[];
|
to_grid?: string[];
|
||||||
from_grid?: string[];
|
from_grid?: string[];
|
||||||
@ -283,33 +285,9 @@ export class HuiEnergyUsageGraphCard
|
|||||||
energyData.start
|
energyData.start
|
||||||
);
|
);
|
||||||
|
|
||||||
const statisticsData = Object.values(energyData.stats);
|
|
||||||
|
|
||||||
const datasets: ChartDataset<"bar">[] = [];
|
|
||||||
let endTime: Date;
|
|
||||||
|
|
||||||
this._start = energyData.start;
|
this._start = energyData.start;
|
||||||
this._end = energyData.end || endOfToday();
|
this._end = energyData.end || endOfToday();
|
||||||
|
|
||||||
if (statisticsData.length === 0) {
|
|
||||||
this._chartData = {
|
|
||||||
datasets,
|
|
||||||
};
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
endTime = new Date(
|
|
||||||
Math.max(
|
|
||||||
...statisticsData.map((stats) =>
|
|
||||||
stats.length ? new Date(stats[stats.length - 1].start).getTime() : 0
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (endTime > new Date()) {
|
|
||||||
endTime = new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
const combinedData: {
|
const combinedData: {
|
||||||
to_grid?: { [statId: string]: { [start: string]: number } };
|
to_grid?: { [statId: string]: { [start: string]: number } };
|
||||||
to_battery?: { [statId: string]: { [start: string]: number } };
|
to_battery?: { [statId: string]: { [start: string]: number } };
|
||||||
|
@ -104,12 +104,7 @@ class HuiTimestampDisplay extends LitElement {
|
|||||||
this._relative =
|
this._relative =
|
||||||
this._format === "relative"
|
this._format === "relative"
|
||||||
? relativeTime(this.ts, this.hass!.locale)
|
? relativeTime(this.ts, this.hass!.locale)
|
||||||
: (this._relative = relativeTime(
|
: relativeTime(new Date(), this.hass!.locale, this.ts, false);
|
||||||
new Date(),
|
|
||||||
this.hass!.locale,
|
|
||||||
this.ts,
|
|
||||||
false
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ class HaPanelMy extends LitElement {
|
|||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (this._error) {
|
if (this._error) {
|
||||||
let error = "Unknown error";
|
let error: string;
|
||||||
switch (this._error) {
|
switch (this._error) {
|
||||||
case "not_supported":
|
case "not_supported":
|
||||||
error =
|
error =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user