mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-13 20:36: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 fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const env = require("../env");
|
||||
const paths = require("../paths");
|
||||
|
||||
require("./clean.js");
|
||||
require("./gen-icons-json.js");
|
||||
|
@ -4,9 +4,6 @@ const del = require("del");
|
||||
const path = require("path");
|
||||
const gulp = require("gulp");
|
||||
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 outDir = "build/locale-data";
|
||||
|
@ -115,7 +115,7 @@ export const applyThemesOnElement = (
|
||||
}
|
||||
|
||||
const newTheme =
|
||||
themeRules && cacheKey
|
||||
Object.keys(themeRules).length && cacheKey
|
||||
? PROCESSED_THEMES[cacheKey] || processTheme(cacheKey, themeRules)
|
||||
: undefined;
|
||||
|
||||
|
@ -180,10 +180,10 @@ export function fuzzyScore(
|
||||
wordLow
|
||||
);
|
||||
|
||||
let row = 1;
|
||||
let row: number;
|
||||
let column = 1;
|
||||
let patternPos = patternStart;
|
||||
let wordPos = wordStart;
|
||||
let patternPos: number;
|
||||
let wordPos: number;
|
||||
|
||||
const hasStrongFirstMatch = [false];
|
||||
|
||||
|
@ -511,18 +511,16 @@ export class HaAutomationTracer extends LitElement {
|
||||
className: isError ? "error" : undefined,
|
||||
};
|
||||
}
|
||||
// null means it was stopped by a condition
|
||||
if (entry) {
|
||||
entries.push(html`
|
||||
<ha-timeline
|
||||
lastItem
|
||||
.icon=${entry.icon}
|
||||
class=${ifDefined(entry.className)}
|
||||
>
|
||||
${entry.description}
|
||||
</ha-timeline>
|
||||
`);
|
||||
}
|
||||
|
||||
entries.push(html`
|
||||
<ha-timeline
|
||||
lastItem
|
||||
.icon=${entry.icon}
|
||||
class=${ifDefined(entry.className)}
|
||||
>
|
||||
${entry.description}
|
||||
</ha-timeline>
|
||||
`);
|
||||
|
||||
return html`${entries}`;
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ export class QuickBar extends LitElement {
|
||||
: this._entityItems;
|
||||
|
||||
if (items && this._filter && this._filter !== " ") {
|
||||
items = this._filterItems(items || [], this._filter);
|
||||
items = this._filterItems(items, this._filter);
|
||||
}
|
||||
|
||||
return html`
|
||||
|
@ -99,16 +99,12 @@ export class CloudRemotePref extends LitElement {
|
||||
)}</mwc-button
|
||||
>
|
||||
</a>
|
||||
${remote_certificate
|
||||
? html`
|
||||
<div class="spacer"></div>
|
||||
<mwc-button @click=${this._openCertInfo}>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.cloud.account.remote.certificate_info"
|
||||
)}
|
||||
</mwc-button>
|
||||
`
|
||||
: ""}
|
||||
<div class="spacer"></div>
|
||||
<mwc-button @click=${this._openCertInfo}>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.cloud.account.remote.certificate_info"
|
||||
)}
|
||||
</mwc-button>
|
||||
</div>
|
||||
</ha-card>
|
||||
`;
|
||||
|
@ -36,7 +36,7 @@ export class DialogEnergyBatterySettings
|
||||
this._params = params;
|
||||
this._source = params.source
|
||||
? { ...params.source }
|
||||
: (this._source = emptyBatteryEnergyPreference());
|
||||
: emptyBatteryEnergyPreference();
|
||||
}
|
||||
|
||||
public closeDialog(): void {
|
||||
|
@ -42,7 +42,7 @@ export class DialogEnergyGasSettings
|
||||
this._params = params;
|
||||
this._source = params.source
|
||||
? { ...params.source }
|
||||
: (this._source = emptyGasEnergyPreference());
|
||||
: emptyGasEnergyPreference();
|
||||
this._costs = this._source.entity_energy_price
|
||||
? "entity"
|
||||
: this._source.number_energy_price
|
||||
|
@ -46,10 +46,9 @@ export class DialogEnergyGridFlowSettings
|
||||
this._params = params;
|
||||
this._source = params.source
|
||||
? { ...params.source }
|
||||
: (this._source =
|
||||
params.direction === "from"
|
||||
? emptyFlowFromGridSourceEnergyPreference()
|
||||
: emptyFlowToGridSourceEnergyPreference());
|
||||
: params.direction === "from"
|
||||
? emptyFlowFromGridSourceEnergyPreference()
|
||||
: emptyFlowToGridSourceEnergyPreference();
|
||||
this._costs = this._source.entity_energy_price
|
||||
? "entity"
|
||||
: this._source.number_energy_price
|
||||
|
@ -49,7 +49,7 @@ export class DialogEnergySolarSettings
|
||||
this._fetchSolarForecastConfigEntries();
|
||||
this._source = params.source
|
||||
? { ...params.source }
|
||||
: (this._source = emptySolarEnergyPreference());
|
||||
: emptySolarEnergyPreference();
|
||||
this._forecast = this._source.config_entry_solar_forecast !== null;
|
||||
}
|
||||
|
||||
|
@ -493,7 +493,9 @@ class HaConfigZwave extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
||||
}
|
||||
|
||||
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 hass = this.hass;
|
||||
return Object.keys(this.hass.states)
|
||||
@ -512,7 +514,9 @@ class HaConfigZwave extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
||||
}
|
||||
|
||||
selectedNodeChanged(selectedNode) {
|
||||
if (selectedNode === -1) return;
|
||||
if (selectedNode === -1) {
|
||||
return;
|
||||
}
|
||||
this.selectedEntity = -1;
|
||||
|
||||
this.hass
|
||||
@ -573,7 +577,9 @@ class HaConfigZwave extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
||||
}
|
||||
|
||||
selectedEntityChanged(selectedEntity) {
|
||||
if (selectedEntity === -1) return;
|
||||
if (selectedEntity === -1) {
|
||||
return;
|
||||
}
|
||||
this.hass
|
||||
.callApi(
|
||||
"GET",
|
||||
@ -640,12 +646,16 @@ class HaConfigZwave extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
||||
}
|
||||
|
||||
computeRefreshEntityServiceData(selectedEntity) {
|
||||
if (selectedEntity === -1) return -1;
|
||||
if (selectedEntity === -1) {
|
||||
return -1;
|
||||
}
|
||||
return { entity_id: this.entities[selectedEntity].entity_id };
|
||||
}
|
||||
|
||||
computePollIntensityServiceData(entityPollingIntensity) {
|
||||
if (!this.selectedNode === -1 || this.selectedEntity === -1) return -1;
|
||||
if (this.selectedNode === -1 || this.selectedEntity === -1) {
|
||||
return -1;
|
||||
}
|
||||
return {
|
||||
node_id: this.nodes[this.selectedNode].attributes.node_id,
|
||||
value_id: this.entities[this.selectedEntity].attributes.value_id,
|
||||
|
@ -300,12 +300,13 @@ class ZwaveGroups extends LocalizeMixin(PolymerElement) {
|
||||
|
||||
_computeAssocServiceData(selectedGroup, type) {
|
||||
if (
|
||||
!this.groups === -1 ||
|
||||
!this.groups ||
|
||||
selectedGroup === -1 ||
|
||||
this.selectedNode === -1 ||
|
||||
this._selectedTargetNode === -1
|
||||
)
|
||||
) {
|
||||
return -1;
|
||||
}
|
||||
return {
|
||||
node_id: this.nodes[this.selectedNode].attributes.node_id,
|
||||
association: type,
|
||||
|
@ -65,7 +65,7 @@ class DialogSystemLogDetail extends LitElement {
|
||||
this._manifest &&
|
||||
(this._manifest.is_built_in ||
|
||||
// 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`
|
||||
<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 borderColor: string[] = [];
|
||||
const backgroundColor: string[] = [];
|
||||
|
@ -220,21 +220,7 @@ export class HuiEnergyGasGraphCard
|
||||
|
||||
this._unit = getEnergyGasUnit(this.hass, energyData.prefs) || "m³";
|
||||
|
||||
const statisticsData = Object.values(energyData.stats);
|
||||
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 gasColor = computedStyles
|
||||
|
@ -226,21 +226,7 @@ export class HuiEnergySolarGraphCard
|
||||
}
|
||||
}
|
||||
|
||||
const statisticsData = Object.values(energyData.stats);
|
||||
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 solarColor = computedStyles
|
||||
|
@ -88,7 +88,7 @@ export class HuiEnergyUsageGraphCard
|
||||
)}
|
||||
chart-type="bar"
|
||||
></ha-chart-base>
|
||||
${!this._chartData.datasets.length
|
||||
${!this._chartData.datasets.some((dataset) => dataset.data.length)
|
||||
? html`<div class="no-data">
|
||||
${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."
|
||||
@ -228,6 +228,8 @@ export class HuiEnergyUsageGraphCard
|
||||
);
|
||||
|
||||
private async _getStatistics(energyData: EnergyData): Promise<void> {
|
||||
const datasets: ChartDataset<"bar">[] = [];
|
||||
|
||||
const statistics: {
|
||||
to_grid?: string[];
|
||||
from_grid?: string[];
|
||||
@ -283,33 +285,9 @@ export class HuiEnergyUsageGraphCard
|
||||
energyData.start
|
||||
);
|
||||
|
||||
const statisticsData = Object.values(energyData.stats);
|
||||
|
||||
const datasets: ChartDataset<"bar">[] = [];
|
||||
let endTime: Date;
|
||||
|
||||
this._start = energyData.start;
|
||||
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: {
|
||||
to_grid?: { [statId: string]: { [start: string]: number } };
|
||||
to_battery?: { [statId: string]: { [start: string]: number } };
|
||||
|
@ -104,12 +104,7 @@ class HuiTimestampDisplay extends LitElement {
|
||||
this._relative =
|
||||
this._format === "relative"
|
||||
? relativeTime(this.ts, this.hass!.locale)
|
||||
: (this._relative = relativeTime(
|
||||
new Date(),
|
||||
this.hass!.locale,
|
||||
this.ts,
|
||||
false
|
||||
));
|
||||
: relativeTime(new Date(), this.hass!.locale, this.ts, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ class HaPanelMy extends LitElement {
|
||||
|
||||
protected render() {
|
||||
if (this._error) {
|
||||
let error = "Unknown error";
|
||||
let error: string;
|
||||
switch (this._error) {
|
||||
case "not_supported":
|
||||
error =
|
||||
|
Loading…
x
Reference in New Issue
Block a user