diff --git a/gallery/src/data/traces/basic_trace.ts b/gallery/src/data/traces/basic_trace.ts index 1df0446a1e..6345b4f845 100644 --- a/gallery/src/data/traces/basic_trace.ts +++ b/gallery/src/data/traces/basic_trace.ts @@ -298,11 +298,11 @@ export const basicTrace: DemoTrace = { source: "state of input_boolean.toggle_1", entity_id: "automation.toggle_toggles", context_id: "6cfcae368e7b3686fad6c59e83ae76c9", - when: "2021-03-25T04:36:51.240832+00:00", + when: 1616647011.240832, domain: "automation", }, { - when: "2021-03-25T04:36:51.249828+00:00", + when: 1616647011.249828, name: "Toggle 4", state: "on", entity_id: "input_boolean.toggle_4", @@ -313,7 +313,7 @@ export const basicTrace: DemoTrace = { context_name: "Ensure Party mode", }, { - when: "2021-03-25T04:36:51.258947+00:00", + when: 1616647011.258947, name: "Toggle 2", state: "on", entity_id: "input_boolean.toggle_2", @@ -324,7 +324,7 @@ export const basicTrace: DemoTrace = { context_name: "Ensure Party mode", }, { - when: "2021-03-25T04:36:51.261806+00:00", + when: 1616647011.261806, name: "Toggle 3", state: "off", entity_id: "input_boolean.toggle_3", @@ -335,7 +335,7 @@ export const basicTrace: DemoTrace = { context_name: "Ensure Party mode", }, { - when: "2021-03-25T04:36:51.265246+00:00", + when: 1616647011.265246, name: "Toggle 4", state: "off", entity_id: "input_boolean.toggle_4", diff --git a/gallery/src/data/traces/motion-light-trace.ts b/gallery/src/data/traces/motion-light-trace.ts index b735e28b03..fa566e5556 100644 --- a/gallery/src/data/traces/motion-light-trace.ts +++ b/gallery/src/data/traces/motion-light-trace.ts @@ -185,11 +185,11 @@ export const motionLightTrace: DemoTrace = { "has been triggered by state of binary_sensor.pauluss_macbook_pro_camera_in_use", source: "state of binary_sensor.pauluss_macbook_pro_camera_in_use", entity_id: "automation.auto_elgato", - when: "2021-03-14T06:07:01.768492+00:00", + when: 1615702021.768492, domain: "automation", }, { - when: "2021-03-14T06:07:01.872187+00:00", + when: 1615702021.872187, name: "Elgato Key Light Air", state: "on", entity_id: "light.elgato_key_light_air", @@ -200,7 +200,7 @@ export const motionLightTrace: DemoTrace = { context_name: "Auto Elgato", }, { - when: "2021-03-14T06:07:53.284505+00:00", + when: 1615702073.284505, name: "Elgato Key Light Air", state: "off", entity_id: "light.elgato_key_light_air", diff --git a/src/data/logbook.ts b/src/data/logbook.ts index 0ce969c3f4..6e7a289b90 100644 --- a/src/data/logbook.ts +++ b/src/data/logbook.ts @@ -10,7 +10,7 @@ const LOGBOOK_LOCALIZE_PATH = "ui.components.logbook.messages"; export const CONTINUOUS_DOMAINS = ["proximity", "sensor"]; export interface LogbookEntry { - when: string; + when: number; name: string; message?: string; entity_id?: string; @@ -46,7 +46,6 @@ export const getLogbookDataForContext = async ( startDate, undefined, undefined, - undefined, contextId ) ); @@ -56,20 +55,13 @@ export const getLogbookData = async ( hass: HomeAssistant, startDate: string, endDate: string, - entityId?: string, - entity_matches_only?: boolean + entityId?: string ): Promise => { const localize = await hass.loadBackendTranslation("device_class"); return addLogbookMessage( hass, localize, - await getLogbookDataCache( - hass, - startDate, - endDate, - entityId, - entity_matches_only - ) + await getLogbookDataCache(hass, startDate, endDate, entityId) ); }; @@ -97,8 +89,7 @@ export const getLogbookDataCache = async ( hass: HomeAssistant, startDate: string, endDate: string, - entityId?: string, - entity_matches_only?: boolean + entityId?: string ) => { const ALL_ENTITIES = "*"; @@ -125,39 +116,31 @@ export const getLogbookDataCache = async ( hass, startDate, endDate, - entityId !== ALL_ENTITIES ? entityId : undefined, - entity_matches_only + entityId !== ALL_ENTITIES ? entityId : undefined ).then((entries) => entries.reverse()); return DATA_CACHE[cacheKey][entityId]; }; -const getLogbookDataFromServer = async ( +export const getLogbookDataFromServer = ( hass: HomeAssistant, startDate: string, endDate?: string, entityId?: string, - entitymatchesOnly?: boolean, contextId?: string ) => { - const params = new URLSearchParams(); - + let params: any = { + type: "logbook/get_events", + start_time: startDate, + }; if (endDate) { - params.append("end_time", endDate); + params = { ...params, end_time: endDate }; } if (entityId) { - params.append("entity", entityId); + params = { ...params, entity_ids: entityId.split(",") }; + } else if (contextId) { + params = { ...params, context_id: contextId }; } - if (entitymatchesOnly) { - params.append("entity_matches_only", ""); - } - if (contextId) { - params.append("context_id", contextId); - } - - return hass.callApi( - "GET", - `logbook/${startDate}?${params.toString()}` - ); + return hass.callWS(params); }; export const clearLogbookCache = (startDate: string, endDate: string) => { diff --git a/src/dialogs/more-info/ha-more-info-logbook.ts b/src/dialogs/more-info/ha-more-info-logbook.ts index 05bc1bfe0f..e577ff7cb6 100644 --- a/src/dialogs/more-info/ha-more-info-logbook.ts +++ b/src/dialogs/more-info/ha-more-info-logbook.ts @@ -147,8 +147,7 @@ export class MoreInfoLogbook extends LitElement { this.hass, lastDate.toISOString(), now.toISOString(), - this.entityId, - true + this.entityId ), this.hass.user?.is_admin ? loadTraceContexts(this.hass) : {}, this._fetchUserPromise, diff --git a/src/panels/logbook/ha-logbook.ts b/src/panels/logbook/ha-logbook.ts index 0e42b26240..adb946efa8 100644 --- a/src/panels/logbook/ha-logbook.ts +++ b/src/panels/logbook/ha-logbook.ts @@ -135,11 +135,11 @@ class HaLogbook extends LitElement { ${index === 0 || (item?.when && previous?.when && - new Date(item.when).toDateString() !== - new Date(previous.when).toDateString()) + new Date(item.when * 1000).toDateString() !== + new Date(previous.when * 1000).toDateString()) ? html`

- ${formatDate(new Date(item.when), this.hass.locale)} + ${formatDate(new Date(item.when * 1000), this.hass.locale)}

` : html``} @@ -207,14 +207,14 @@ class HaLogbook extends LitElement {
${formatTimeWithSeconds( - new Date(item.when), + new Date(item.when * 1000), this.hass.locale )} - ${["script", "automation"].includes(item.domain!) && diff --git a/src/panels/lovelace/cards/hui-logbook-card.ts b/src/panels/lovelace/cards/hui-logbook-card.ts index ae459a11d3..3adf6f40e8 100644 --- a/src/panels/lovelace/cards/hui-logbook-card.ts +++ b/src/panels/lovelace/cards/hui-logbook-card.ts @@ -249,8 +249,7 @@ export class HuiLogbookCard extends LitElement implements LovelaceCard { this.hass, lastDate.toISOString(), now.toISOString(), - this._configEntities!.map((entity) => entity.entity).toString(), - true + this._configEntities!.map((entity) => entity.entity).toString() ), this._fetchUserPromise, ]); @@ -264,7 +263,7 @@ export class HuiLogbookCard extends LitElement implements LovelaceCard { : newEntries; this._logbookEntries = logbookEntries.filter( - (logEntry) => new Date(logEntry.when) > hoursToShowDate + (logEntry) => new Date(logEntry.when * 1000) > hoursToShowDate ); this._lastLogbookDate = now;