Skip to content
Merged
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
10 changes: 5 additions & 5 deletions gallery/src/data/traces/basic_trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions gallery/src/data/traces/motion-light-trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
47 changes: 15 additions & 32 deletions src/data/logbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,7 +46,6 @@ export const getLogbookDataForContext = async (
startDate,
undefined,
undefined,
undefined,
contextId
)
);
Expand All @@ -56,20 +55,13 @@ export const getLogbookData = async (
hass: HomeAssistant,
startDate: string,
endDate: string,
entityId?: string,
entity_matches_only?: boolean
entityId?: string
): Promise<LogbookEntry[]> => {
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)
);
};

Expand Down Expand Up @@ -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 = "*";

Expand All @@ -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);
}
if (entitymatchesOnly) {
params.append("entity_matches_only", "");
}
if (contextId) {
params.append("context_id", contextId);
params = { ...params, entity_ids: entityId.split(",") };
} else if (contextId) {
params = { ...params, context_id: contextId };
}

return hass.callApi<LogbookEntry[]>(
"GET",
`logbook/${startDate}?${params.toString()}`
);
return hass.callWS<LogbookEntry[]>(params);
};

export const clearLogbookCache = (startDate: string, endDate: string) => {
Expand Down
3 changes: 1 addition & 2 deletions src/dialogs/more-info/ha-more-info-logbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/panels/logbook/ha-logbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
<h4 class="date">
${formatDate(new Date(item.when), this.hass.locale)}
${formatDate(new Date(item.when * 1000), this.hass.locale)}
</h4>
`
: html``}
Expand Down Expand Up @@ -207,14 +207,14 @@ class HaLogbook extends LitElement {
<div class="secondary">
<span
>${formatTimeWithSeconds(
new Date(item.when),
new Date(item.when * 1000),
this.hass.locale
)}</span
>
-
<ha-relative-time
.hass=${this.hass}
.datetime=${item.when}
.datetime=${item.when * 1000}
capitalize
></ha-relative-time>
${["script", "automation"].includes(item.domain!) &&
Expand Down
5 changes: 2 additions & 3 deletions src/panels/lovelace/cards/hui-logbook-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
Expand All @@ -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;
Expand Down