Skip to content

Commit

Permalink
Merge branch 'dev' into fix_badges_editor
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored Mar 4, 2024
2 parents 35ada40 + 8ccc38e commit 3404a36
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ export class HuiEnergyDevicesDetailGraphCard
}

protected willUpdate(changedProps: PropertyValues) {
if (changedProps.has("_hiddenStats") && this._data) {
if (
(changedProps.has("_hiddenStats") || changedProps.has("_config")) &&
this._data
) {
this._processStatistics();
}
}
Expand Down Expand Up @@ -217,17 +220,17 @@ export class HuiEnergyDevicesDetailGraphCard
const datasets: ChartDataset<"bar", ScatterDataPoint[]>[] = [];
const datasetExtras: ChartDatasetExtra[] = [];

datasets.push(
...this._processDataSet(
const { data: processedData, dataExtras: processedDataExtras } =
this._processDataSet(
data,
energyData.statsMetadata,
energyData.prefs.device_consumption,
sorted_devices
)
);
);

datasets.push(...processedData);

const items = datasets.length;
datasetExtras.push(...Array<ChartDatasetExtra>(items).fill({}));
datasetExtras.push(...processedDataExtras);

if (compareData) {
// Add empty dataset to align the bars
Expand All @@ -247,18 +250,19 @@ export class HuiEnergyDevicesDetailGraphCard
show_legend: false,
});

datasets.push(
...this._processDataSet(
compareData,
energyData.statsMetadata,
energyData.prefs.device_consumption,
sorted_devices,
true
)
);
datasetExtras.push(
...Array<ChartDatasetExtra>(items).fill({ show_legend: false })
const {
data: processedCompareData,
dataExtras: processedCompareDataExtras,
} = this._processDataSet(
compareData,
energyData.statsMetadata,
energyData.prefs.device_consumption,
sorted_devices,
true
);

datasets.push(...processedCompareData);
datasetExtras.push(...processedCompareDataExtras);
}

this._start = energyData.start;
Expand All @@ -281,6 +285,7 @@ export class HuiEnergyDevicesDetailGraphCard
compare = false
) {
const data: ChartDataset<"bar", ScatterDataPoint[]>[] = [];
const dataExtras: ChartDatasetExtra[] = [];

devices.forEach((source, idx) => {
const color = getColorByIndex(idx);
Expand Down Expand Up @@ -317,23 +322,30 @@ export class HuiEnergyDevicesDetailGraphCard
}
}

const order = sorted_devices.indexOf(source.stat_consumption);
const itemExceedsMax = !!(
this._config?.max_devices && order >= this._config.max_devices
);

data.push({
label: getStatisticLabel(
this.hass,
source.stat_consumption,
statisticsMetaData[source.stat_consumption]
),
hidden: this._hiddenStats.has(source.stat_consumption),
hidden:
this._hiddenStats.has(source.stat_consumption) || itemExceedsMax,
borderColor: compare ? color + "7F" : color,
backgroundColor: compare ? color + "32" : color + "7F",
data: consumptionData,
order: 1 + sorted_devices.indexOf(source.stat_consumption),
order: 1 + order,
stack: "devices",
pointStyle: compare ? false : "circle",
xAxisID: compare ? "xAxisCompare" : undefined,
});
dataExtras.push({ show_legend: !compare && !itemExceedsMax });
});
return data;
return { data, dataExtras };
}

static get styles(): CSSResultGroup {
Expand Down
44 changes: 19 additions & 25 deletions src/panels/lovelace/editor/view-editor/hui-dialog-edit-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ import { EditViewDialogParams } from "./show-edit-view-dialog";
export class HuiDialogEditView extends LitElement {
@property({ attribute: false }) public hass?: HomeAssistant;

@state() private _currentType?: string;

@state() private _params?: EditViewDialogParams;

@state() private _config?: LovelaceViewConfig;
Expand Down Expand Up @@ -107,7 +105,6 @@ export class HuiDialogEditView extends LitElement {
this._config = viewConfig;
return;
}
this._currentType = view.type;
this._config = view;
}

Expand Down Expand Up @@ -205,14 +202,12 @@ export class HuiDialogEditView extends LitElement {
}
}

const isEmpty =
!this._config?.cards?.length && !this._config?.sections?.length;

const isCompatibleViewType =
isEmpty ||
(this._currentType === SECTION_VIEW_LAYOUT
? this._config?.type === SECTION_VIEW_LAYOUT
: this._config?.type !== SECTION_VIEW_LAYOUT);
this._config?.type === SECTION_VIEW_LAYOUT
? this._config?.type === SECTION_VIEW_LAYOUT &&
!this._config?.cards?.length
: this._config?.type !== SECTION_VIEW_LAYOUT &&
!this._config?.sections?.length;

return html`
<ha-dialog
Expand Down Expand Up @@ -272,6 +267,19 @@ export class HuiDialogEditView extends LitElement {
: ``}
</mwc-list-item>
</ha-button-menu>
${!isCompatibleViewType
? html`
<ha-alert class="incompatible" alert-type="warning">
${this._config?.type === SECTION_VIEW_LAYOUT
? this.hass!.localize(
"ui.panel.lovelace.editor.edit_view.type_warning_sections"
)
: this.hass!.localize(
"ui.panel.lovelace.editor.edit_view.type_warning_others"
)}
</ha-alert>
`
: nothing}
${!this._yamlMode
? html`<paper-tabs
scrollable
Expand Down Expand Up @@ -311,19 +319,6 @@ export class HuiDialogEditView extends LitElement {
</mwc-button>
`
: nothing}
${!isCompatibleViewType
? html`
<ha-alert class="incompatible" alert-type="warning">
${this._config?.type === SECTION_VIEW_LAYOUT
? this.hass!.localize(
"ui.panel.lovelace.editor.edit_view.type_warning_sections"
)
: this.hass!.localize(
"ui.panel.lovelace.editor.edit_view.type_warning_others"
)}
</ha-alert>
`
: nothing}
<mwc-button
slot="primaryAction"
?disabled=${!this._config ||
Expand Down Expand Up @@ -422,7 +417,7 @@ export class HuiDialogEditView extends LitElement {
};

if (viewConf.type === SECTION_VIEW_LAYOUT && !viewConf.sections?.length) {
viewConf.sections = [{ cards: [] }];
viewConf.sections = [{ type: "grid", cards: [] }];
} else if (!viewConf.cards?.length) {
viewConf.cards = [];
}
Expand Down Expand Up @@ -576,7 +571,6 @@ export class HuiDialogEditView extends LitElement {
}
.incompatible {
display: block;
margin-top: 16px;
}
@media all and (min-width: 600px) {
Expand Down
6 changes: 6 additions & 0 deletions src/panels/lovelace/views/hui-masonry-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ export class MasonryView extends LitElement implements LovelaceViewElement {
padding-top: 4px;
}
.badges {
margin: 8px 16px;
font-size: 85%;
text-align: center;
}
#columns {
display: flex;
flex-direction: row;
Expand Down

0 comments on commit 3404a36

Please sign in to comment.