Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timespans to logbook, energy and history #23362

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 20 additions & 27 deletions src/components/ha-date-range-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import type { ActionDetail } from "@material/mwc-list/mwc-list-foundation";
import "@material/mwc-list/mwc-list-item";
import { mdiCalendar } from "@mdi/js";
import {
addDays,
subHours,
endOfDay,
endOfMonth,
endOfWeek,
endOfYear,
subDays,
startOfDay,
startOfMonth,
startOfWeek,
Expand Down Expand Up @@ -112,28 +113,8 @@ export class HaDateRangePicker extends LitElement {
weekStartsOn,
}),
],
[this.hass.localize(
"ui.components.date-range-picker.ranges.yesterday"
)]: [
calcDate(
addDays(today, -1),
startOfDay,
this.hass.locale,
this.hass.config,
{
weekStartsOn,
}
),
calcDate(
addDays(today, -1),
endOfDay,
this.hass.locale,
this.hass.config,
{
weekStartsOn,
}
),
],
[this.hass.localize("ui.components.date-range-picker.ranges.now-24h")]:
[subHours(today, 24), today],
[this.hass.localize(
"ui.components.date-range-picker.ranges.this_week"
)]: [weekStart, weekEnd],
Expand Down Expand Up @@ -161,6 +142,9 @@ export class HaDateRangePicker extends LitElement {
}
),
],
[this.hass.localize(
"ui.components.date-range-picker.ranges.now-30d"
)]: [subHours(today, 24 * 30), today],
[this.hass.localize(
"ui.components.date-range-picker.ranges.this_year"
)]: [
Expand All @@ -177,6 +161,9 @@ export class HaDateRangePicker extends LitElement {
weekStartsOn,
}),
],
[this.hass.localize(
"ui.components.date-range-picker.ranges.now-365d"
)]: [subDays(today, 365), today],
}
: {}),
};
Expand Down Expand Up @@ -362,7 +349,6 @@ export class HaDateRangePicker extends LitElement {

static get styles(): CSSResultGroup {
return css`

ha-icon-button {
direction: var(--direction);
}
Expand All @@ -389,16 +375,23 @@ export class HaDateRangePicker extends LitElement {
width: 340px;
}
@media only screen and (max-width: 460px) {
ha-textarea {
width: 100%
ha-textarea {
width: 100%;
}
}

@media only screen and (max-width: 800px) {
.date-range-ranges {
border-right: none;
border-bottom: 1px solid var(--divider-color);
}
}

@media only screen and (max-height: 920px) and (max-width: 800px) {
.date-range-ranges {
overflow: scroll;
max-height: calc(70vh - 350px);
}
}
`;
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/panels/lovelace/components/hui-energy-period-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
startOfWeek,
startOfYear,
subDays,
subHours,
} from "date-fns";
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
import type { CSSResultGroup, PropertyValues } from "lit";
Expand Down Expand Up @@ -129,6 +130,8 @@ export class HuiEnergyPeriodSelector extends SubscribeMixin(LitElement) {
weekStartsOn,
}),
],
[this.hass.localize("ui.components.date-range-picker.ranges.now-24h")]:
[subHours(today, 24), today],
[this.hass.localize(
"ui.components.date-range-picker.ranges.yesterday"
)]: [
Expand Down Expand Up @@ -173,12 +176,16 @@ export class HuiEnergyPeriodSelector extends SubscribeMixin(LitElement) {
calcDate(today, startOfQuarter, this.hass.locale, this.hass.config),
calcDate(today, endOfQuarter, this.hass.locale, this.hass.config),
],
[this.hass.localize("ui.components.date-range-picker.ranges.now-30d")]:
[subHours(today, 24 * 30), today],
[this.hass.localize(
"ui.components.date-range-picker.ranges.this_year"
)]: [
calcDate(today, startOfYear, this.hass.locale, this.hass.config),
calcDate(today, endOfYear, this.hass.locale, this.hass.config),
],
[this.hass.localize("ui.components.date-range-picker.ranges.now-365d")]:
[subDays(today, 365), today],
};
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,13 @@
"ranges": {
"today": "Today",
"yesterday": "Yesterday",
"now-24h": "Last 24 hours",
"this_week": "This week",
"this_quarter": "This quarter",
"this_month": "This month",
"this_year": "This year"
"now-30d": "Last 30 days",
"this_year": "This year",
"now-365d": "Last 365 days"
}
},
"grid-size-picker": {
Expand Down
Loading