Skip to content

Commit

Permalink
Merge branch 'home-assistant:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
paolapersico1 authored May 8, 2024
2 parents 70af495 + 9c57c9f commit 9fb5756
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"hls.js": "patch:hls.js@npm%3A1.5.7#~/.yarn/patches/hls.js-npm-1.5.7-f5bbd3d060.patch",
"home-assistant-js-websocket": "9.3.0",
"idb-keyval": "6.2.1",
"intl-messageformat": "10.5.11",
"intl-messageformat": "10.5.12",
"js-yaml": "4.1.0",
"leaflet": "1.9.4",
"leaflet-draw": "1.0.4",
Expand Down
10 changes: 9 additions & 1 deletion src/common/entity/get_states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ export const FIXED_DOMAIN_STATES = {
input_button: [],
lawn_mower: ["error", "paused", "mowing", "docked"],
light: ["on", "off"],
lock: ["jammed", "locked", "locking", "unlocked", "unlocking"],
lock: [
"jammed",
"locked",
"locking",
"unlocked",
"unlocking",
"opening",
"open",
],
media_player: [
"off",
"on",
Expand Down
4 changes: 4 additions & 0 deletions src/data/logbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ export const localizeStateMessage = (
return localize(`${LOGBOOK_LOCALIZE_PATH}.is_locking`);
case "unlocking":
return localize(`${LOGBOOK_LOCALIZE_PATH}.is_unlocking`);
case "opening":
return localize(`${LOGBOOK_LOCALIZE_PATH}.is_opening`);
case "open":
return localize(`${LOGBOOK_LOCALIZE_PATH}.is_opened`);
case "locked":
return localize(`${LOGBOOK_LOCALIZE_PATH}.was_locked`);
case "jammed":
Expand Down
25 changes: 16 additions & 9 deletions src/data/script_i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,19 @@ const tryDescribeAction = <T extends ActionType>(
const config = action as ActionTypes["service"];

const targets: string[] = [];
if (config.target) {
const targetOrData = config.target || config.data;
if (targetOrData) {
for (const [key, name] of Object.entries({
area_id: "areas",
device_id: "devices",
entity_id: "entities",
floor_id: "floors",
label_id: "labels",
})) {
if (!(key in config.target)) {
if (!(key in targetOrData)) {
continue;
}
const keyConf: string[] = Array.isArray(config.target[key])
? config.target[key]
: [config.target[key]];
const keyConf: string[] = ensureArray(targetOrData[key]) || [];

for (const targetThing of keyConf) {
if (isTemplate(targetThing)) {
Expand Down Expand Up @@ -195,8 +194,12 @@ const tryDescribeAction = <T extends ActionType>(
(config.service && isTemplate(config.service))
) {
return hass.localize(
`${actionTranslationBaseKey}.service.description.service_based_on_template`,
{ targets: formatListWithAnds(hass.locale, targets) }
targets.length
? `${actionTranslationBaseKey}.service.description.service_based_on_template`
: `${actionTranslationBaseKey}.service.description.service_based_on_template_no_targets`,
{
targets: formatListWithAnds(hass.locale, targets),
}
);
}

Expand All @@ -208,7 +211,9 @@ const tryDescribeAction = <T extends ActionType>(

if (config.metadata) {
return hass.localize(
`${actionTranslationBaseKey}.service.description.service_name`,
targets.length
? `${actionTranslationBaseKey}.service.description.service_name`
: `${actionTranslationBaseKey}.service.description.service_name_no_targets`,
{
domain: domainToName(hass.localize, domain),
name: service || config.service,
Expand All @@ -218,7 +223,9 @@ const tryDescribeAction = <T extends ActionType>(
}

return hass.localize(
`${actionTranslationBaseKey}.service.description.service_based_on_name`,
targets.length
? `${actionTranslationBaseKey}.service.description.service_based_on_name`
: `${actionTranslationBaseKey}.service.description.service_based_on_name_no_targets`,
{
name: service
? `${domainToName(hass.localize, domain)}: ${service}`
Expand Down
2 changes: 2 additions & 0 deletions src/fake_data/entity_component_icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ export const ENTITY_COMPONENT_ICONS: Record<string, ComponentIcons> = {
locking: "mdi:lock-clock",
unlocked: "mdi:lock-open",
unlocking: "mdi:lock-clock",
opening: "mdi:lock-clock",
open: "mdi:lock-open-variant",
},
},
},
Expand Down
81 changes: 73 additions & 8 deletions src/panels/history/ha-panel-history.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { mdiDownload, mdiFilterRemove } from "@mdi/js";
import {
mdiDotsVertical,
mdiDownload,
mdiFilterRemove,
mdiImagePlus,
} from "@mdi/js";
import { ActionDetail } from "@material/mwc-list";
import { differenceInHours } from "date-fns";
import {
HassServiceTarget,
Expand All @@ -23,6 +29,8 @@ import type { StateHistoryCharts } from "../../components/chart/state-history-ch
import "../../components/ha-circular-progress";
import "../../components/ha-date-range-picker";
import "../../components/ha-icon-button";
import "../../components/ha-button-menu";
import "../../components/ha-list-item";
import "../../components/ha-icon-button-arrow-prev";
import "../../components/ha-menu-button";
import "../../components/ha-target-picker";
Expand All @@ -49,6 +57,7 @@ import { showAlertDialog } from "../../dialogs/generic/show-dialog-box";
import { haStyle } from "../../resources/styles";
import { HomeAssistant } from "../../types";
import { fileDownload } from "../../util/file_download";
import { addEntitiesToLovelaceView } from "../lovelace/editor/add-entities-to-view";

class HaPanelHistory extends LitElement {
@property({ attribute: false }) hass!: HomeAssistant;
Expand Down Expand Up @@ -144,13 +153,23 @@ class HaPanelHistory extends LitElement {
></ha-icon-button>
`
: ""}
<ha-icon-button
slot="actionItems"
@click=${this._downloadHistory}
.disabled=${this._isLoading}
.path=${mdiDownload}
.label=${this.hass.localize("ui.panel.history.download_data")}
></ha-icon-button>
<ha-button-menu slot="actionItems" @action=${this._handleMenuAction}>
<ha-icon-button
slot="trigger"
.label=${this.hass.localize("ui.common.menu")}
.path=${mdiDotsVertical}
></ha-icon-button>
<ha-list-item graphic="icon" .disabled=${this._isLoading}>
${this.hass.localize("ui.panel.history.download_data")}
<ha-svg-icon slot="graphic" .path=${mdiDownload}></ha-svg-icon>
</ha-list-item>
<ha-list-item graphic="icon" .disabled=${this._isLoading}>
${this.hass.localize("ui.panel.history.add_card")}
<ha-svg-icon slot="graphic" .path=${mdiImagePlus}></ha-svg-icon>
</ha-list-item>
</ha-button-menu>
<div class="flex content">
<div class="filters">
Expand Down Expand Up @@ -633,6 +652,17 @@ class HaPanelHistory extends LitElement {
navigate(`/history?${createSearchParam(params)}`, { replace: true });
}

private async _handleMenuAction(ev: CustomEvent<ActionDetail>) {
switch (ev.detail.index) {
case 0:
this._downloadHistory();
break;
case 1:
this._suggestCard();
break;
}
}

private _downloadHistory() {
// Make a copy because getEntityIDs is memoized and sort works in-place
const entities = [...this._getEntityIds()].sort();
Expand Down Expand Up @@ -726,6 +756,41 @@ class HaPanelHistory extends LitElement {
fileDownload(url, "history.csv");
}

private _suggestCard() {
const entities = this._getEntityIds();
if (entities.length === 0 || !this._mungedStateHistory) {
showAlertDialog(this, {
title: this.hass.localize("ui.panel.history.add_card_error"),
text: this.hass.localize("ui.panel.history.error_no_data"),
warning: true,
});
return;
}

// If you pick things like "This week", the end date can be in the future
const endDateTime = Math.min(this._endDate.getTime(), Date.now());
const cards = [
{
title: this.hass.localize("panel.history"),
type: "history-graph",
hours_to_show: Math.round(
(endDateTime - this._startDate.getTime()) / 1000 / 60 / 60
),
entities,
},
];
addEntitiesToLovelaceView(
this,
this.hass,
cards,
{
title: this.hass.localize("panel.history"),
cards,
},
entities
);
}

static get styles() {
return [
haStyle,
Expand Down
6 changes: 6 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@
"was_opened": "was opened",
"was_closed": "was closed",
"is_opening": "is opening",
"is_opened": "is opened",
"is_closing": "is closing",
"was_unlocked": "was unlocked",
"was_locked": "was locked",
Expand Down Expand Up @@ -3251,6 +3252,9 @@
"service_based_on_template": "Call a service based on a template on {targets}",
"service_based_on_name": "Call a service ''{name}'' on {targets}",
"service_name": "{domain} ''{name}'' on {targets}",
"service_based_on_template_no_targets": "Call a service based on a template",
"service_based_on_name_no_targets": "Call a service ''{name}''",
"service_name_no_targets": "{domain} ''{name}''",
"service": "Call a service",
"target_template": "templated {name}",
"target_unknown_entity": "unknown entity",
Expand Down Expand Up @@ -6949,6 +6953,8 @@
"remove_all": "Remove all selections",
"download_data": "Download data",
"download_data_error": "Unable to download data",
"add_card": "Add current view as card",
"add_card_error": "Unable to add card",
"error_no_data": "You need to select data first."
}
},
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9065,7 +9065,7 @@ __metadata:
husky: "npm:9.0.11"
idb-keyval: "npm:6.2.1"
instant-mocha: "npm:1.5.2"
intl-messageformat: "npm:10.5.11"
intl-messageformat: "npm:10.5.12"
js-yaml: "npm:4.1.0"
jszip: "npm:3.10.1"
leaflet: "npm:1.9.4"
Expand Down Expand Up @@ -9523,15 +9523,15 @@ __metadata:
languageName: node
linkType: hard

"intl-messageformat@npm:10.5.11":
version: 10.5.11
resolution: "intl-messageformat@npm:10.5.11"
"intl-messageformat@npm:10.5.12":
version: 10.5.12
resolution: "intl-messageformat@npm:10.5.12"
dependencies:
"@formatjs/ecma402-abstract": "npm:1.18.2"
"@formatjs/fast-memoize": "npm:2.2.0"
"@formatjs/icu-messageformat-parser": "npm:2.7.6"
tslib: "npm:^2.4.0"
checksum: 10/2146f4d3e2c4bcf2c4fa343e4ee070fe1124d3821caa2fa0e7112a68fdefbedbbda6a3778f3ba04e38bbce3db33511ca9eecbb0a7e06013e6699255c153813ce
checksum: 10/d12e17bf7c4ce477df4ffe991268f2fbd37fd59ae103def2b8886f65691ff37d22eff559dcd063f8fe6d370fa2748a4b2064285c15f5c1b1ba6383049eecb111
languageName: node
linkType: hard

Expand Down

0 comments on commit 9fb5756

Please sign in to comment.