Skip to content

Commit

Permalink
Add link from energy dashboard to energy settings
Browse files Browse the repository at this point in the history
  • Loading branch information
karwosts committed Nov 10, 2023
1 parent 3a926c6 commit aba83cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/panels/energy/ha-panel-energy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class PanelEnergy extends LitElement {
<hui-energy-period-selector
.hass=${this.hass}
showConfig
collectionKey="energy_dashboard"
></hui-energy-period-selector>
</div>
Expand Down
21 changes: 20 additions & 1 deletion src/panels/lovelace/components/hui-energy-period-selector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "@material/mwc-button/mwc-button";
import type { RequestSelectedDetail } from "@material/mwc-list/mwc-list-item";
import { mdiDotsVertical } from "@mdi/js";
import { mdiDotsVertical, mdiPencil } from "@mdi/js";
import {
addDays,
addMonths,
Expand Down Expand Up @@ -42,6 +42,7 @@ import {
formatDateYear,
} from "../../../common/datetime/format_date";
import { debounce } from "../../../common/util/debounce";
import { navigate } from "../../../common/navigate";
import "../../../components/ha-button-menu";
import "../../../components/ha-check-list-item";
import "../../../components/ha-date-range-picker";
Expand All @@ -61,6 +62,8 @@ export class HuiEnergyPeriodSelector extends SubscribeMixin(LitElement) {

@property({ type: Boolean, reflect: true }) public narrow?;

@property({ type: Boolean }) public showConfig = false;

@state() _startDate?: Date;

@state() _endDate?: Date;
Expand Down Expand Up @@ -278,11 +281,27 @@ export class HuiEnergyPeriodSelector extends SubscribeMixin(LitElement) {
"ui.panel.lovelace.components.energy_period_selector.compare"
)}
</ha-check-list-item>
${this.showConfig && this.hass.user?.is_admin
? html`
<mwc-list-item
graphic="icon"
@request-selected=${this._navigateConfig}
>
<ha-svg-icon slot="graphic" .path=${mdiPencil}> </ha-svg-icon>
${this.hass!.localize("ui.panel.lovelace.menu.configure_ui")}
</mwc-list-item>
`
: nothing}
</ha-button-menu>
</div>
`;
}

private _navigateConfig(ev) {
ev.stopPropagation();
navigate("/config/energy?historyBack=1");
}

private _simpleRange = memoizeOne(
(startDate, endDate, locale, config): string => {
if (differenceInDays(endDate!, startDate!) === 0) {
Expand Down

0 comments on commit aba83cf

Please sign in to comment.