mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-09 10:26:35 +00:00
Switch logbook calls to use the new websocket (#12665)
This commit is contained in:
parent
c9c3be71cc
commit
4c982b3323
@ -298,11 +298,11 @@ export const basicTrace: DemoTrace = {
|
|||||||
source: "state of input_boolean.toggle_1",
|
source: "state of input_boolean.toggle_1",
|
||||||
entity_id: "automation.toggle_toggles",
|
entity_id: "automation.toggle_toggles",
|
||||||
context_id: "6cfcae368e7b3686fad6c59e83ae76c9",
|
context_id: "6cfcae368e7b3686fad6c59e83ae76c9",
|
||||||
when: "2021-03-25T04:36:51.240832+00:00",
|
when: 1616647011.240832,
|
||||||
domain: "automation",
|
domain: "automation",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
when: "2021-03-25T04:36:51.249828+00:00",
|
when: 1616647011.249828,
|
||||||
name: "Toggle 4",
|
name: "Toggle 4",
|
||||||
state: "on",
|
state: "on",
|
||||||
entity_id: "input_boolean.toggle_4",
|
entity_id: "input_boolean.toggle_4",
|
||||||
@ -313,7 +313,7 @@ export const basicTrace: DemoTrace = {
|
|||||||
context_name: "Ensure Party mode",
|
context_name: "Ensure Party mode",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
when: "2021-03-25T04:36:51.258947+00:00",
|
when: 1616647011.258947,
|
||||||
name: "Toggle 2",
|
name: "Toggle 2",
|
||||||
state: "on",
|
state: "on",
|
||||||
entity_id: "input_boolean.toggle_2",
|
entity_id: "input_boolean.toggle_2",
|
||||||
@ -324,7 +324,7 @@ export const basicTrace: DemoTrace = {
|
|||||||
context_name: "Ensure Party mode",
|
context_name: "Ensure Party mode",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
when: "2021-03-25T04:36:51.261806+00:00",
|
when: 1616647011.261806,
|
||||||
name: "Toggle 3",
|
name: "Toggle 3",
|
||||||
state: "off",
|
state: "off",
|
||||||
entity_id: "input_boolean.toggle_3",
|
entity_id: "input_boolean.toggle_3",
|
||||||
@ -335,7 +335,7 @@ export const basicTrace: DemoTrace = {
|
|||||||
context_name: "Ensure Party mode",
|
context_name: "Ensure Party mode",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
when: "2021-03-25T04:36:51.265246+00:00",
|
when: 1616647011.265246,
|
||||||
name: "Toggle 4",
|
name: "Toggle 4",
|
||||||
state: "off",
|
state: "off",
|
||||||
entity_id: "input_boolean.toggle_4",
|
entity_id: "input_boolean.toggle_4",
|
||||||
|
@ -185,11 +185,11 @@ export const motionLightTrace: DemoTrace = {
|
|||||||
"has been triggered by state of binary_sensor.pauluss_macbook_pro_camera_in_use",
|
"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",
|
source: "state of binary_sensor.pauluss_macbook_pro_camera_in_use",
|
||||||
entity_id: "automation.auto_elgato",
|
entity_id: "automation.auto_elgato",
|
||||||
when: "2021-03-14T06:07:01.768492+00:00",
|
when: 1615702021.768492,
|
||||||
domain: "automation",
|
domain: "automation",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
when: "2021-03-14T06:07:01.872187+00:00",
|
when: 1615702021.872187,
|
||||||
name: "Elgato Key Light Air",
|
name: "Elgato Key Light Air",
|
||||||
state: "on",
|
state: "on",
|
||||||
entity_id: "light.elgato_key_light_air",
|
entity_id: "light.elgato_key_light_air",
|
||||||
@ -200,7 +200,7 @@ export const motionLightTrace: DemoTrace = {
|
|||||||
context_name: "Auto Elgato",
|
context_name: "Auto Elgato",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
when: "2021-03-14T06:07:53.284505+00:00",
|
when: 1615702073.284505,
|
||||||
name: "Elgato Key Light Air",
|
name: "Elgato Key Light Air",
|
||||||
state: "off",
|
state: "off",
|
||||||
entity_id: "light.elgato_key_light_air",
|
entity_id: "light.elgato_key_light_air",
|
||||||
|
@ -10,7 +10,7 @@ const LOGBOOK_LOCALIZE_PATH = "ui.components.logbook.messages";
|
|||||||
export const CONTINUOUS_DOMAINS = ["proximity", "sensor"];
|
export const CONTINUOUS_DOMAINS = ["proximity", "sensor"];
|
||||||
|
|
||||||
export interface LogbookEntry {
|
export interface LogbookEntry {
|
||||||
when: string;
|
when: number;
|
||||||
name: string;
|
name: string;
|
||||||
message?: string;
|
message?: string;
|
||||||
entity_id?: string;
|
entity_id?: string;
|
||||||
@ -46,7 +46,6 @@ export const getLogbookDataForContext = async (
|
|||||||
startDate,
|
startDate,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
|
||||||
contextId
|
contextId
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -56,20 +55,13 @@ export const getLogbookData = async (
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
startDate: string,
|
startDate: string,
|
||||||
endDate: string,
|
endDate: string,
|
||||||
entityId?: string,
|
entityId?: string
|
||||||
entity_matches_only?: boolean
|
|
||||||
): Promise<LogbookEntry[]> => {
|
): Promise<LogbookEntry[]> => {
|
||||||
const localize = await hass.loadBackendTranslation("device_class");
|
const localize = await hass.loadBackendTranslation("device_class");
|
||||||
return addLogbookMessage(
|
return addLogbookMessage(
|
||||||
hass,
|
hass,
|
||||||
localize,
|
localize,
|
||||||
await getLogbookDataCache(
|
await getLogbookDataCache(hass, startDate, endDate, entityId)
|
||||||
hass,
|
|
||||||
startDate,
|
|
||||||
endDate,
|
|
||||||
entityId,
|
|
||||||
entity_matches_only
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -97,8 +89,7 @@ export const getLogbookDataCache = async (
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
startDate: string,
|
startDate: string,
|
||||||
endDate: string,
|
endDate: string,
|
||||||
entityId?: string,
|
entityId?: string
|
||||||
entity_matches_only?: boolean
|
|
||||||
) => {
|
) => {
|
||||||
const ALL_ENTITIES = "*";
|
const ALL_ENTITIES = "*";
|
||||||
|
|
||||||
@ -125,39 +116,31 @@ export const getLogbookDataCache = async (
|
|||||||
hass,
|
hass,
|
||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate,
|
||||||
entityId !== ALL_ENTITIES ? entityId : undefined,
|
entityId !== ALL_ENTITIES ? entityId : undefined
|
||||||
entity_matches_only
|
|
||||||
).then((entries) => entries.reverse());
|
).then((entries) => entries.reverse());
|
||||||
return DATA_CACHE[cacheKey][entityId];
|
return DATA_CACHE[cacheKey][entityId];
|
||||||
};
|
};
|
||||||
|
|
||||||
const getLogbookDataFromServer = async (
|
export const getLogbookDataFromServer = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
startDate: string,
|
startDate: string,
|
||||||
endDate?: string,
|
endDate?: string,
|
||||||
entityId?: string,
|
entityId?: string,
|
||||||
entitymatchesOnly?: boolean,
|
|
||||||
contextId?: string
|
contextId?: string
|
||||||
) => {
|
) => {
|
||||||
const params = new URLSearchParams();
|
let params: any = {
|
||||||
|
type: "logbook/get_events",
|
||||||
|
start_time: startDate,
|
||||||
|
};
|
||||||
if (endDate) {
|
if (endDate) {
|
||||||
params.append("end_time", endDate);
|
params = { ...params, end_time: endDate };
|
||||||
}
|
}
|
||||||
if (entityId) {
|
if (entityId) {
|
||||||
params.append("entity", entityId);
|
params = { ...params, entity_ids: entityId.split(",") };
|
||||||
|
} else if (contextId) {
|
||||||
|
params = { ...params, context_id: contextId };
|
||||||
}
|
}
|
||||||
if (entitymatchesOnly) {
|
return hass.callWS<LogbookEntry[]>(params);
|
||||||
params.append("entity_matches_only", "");
|
|
||||||
}
|
|
||||||
if (contextId) {
|
|
||||||
params.append("context_id", contextId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return hass.callApi<LogbookEntry[]>(
|
|
||||||
"GET",
|
|
||||||
`logbook/${startDate}?${params.toString()}`
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const clearLogbookCache = (startDate: string, endDate: string) => {
|
export const clearLogbookCache = (startDate: string, endDate: string) => {
|
||||||
|
@ -147,8 +147,7 @@ export class MoreInfoLogbook extends LitElement {
|
|||||||
this.hass,
|
this.hass,
|
||||||
lastDate.toISOString(),
|
lastDate.toISOString(),
|
||||||
now.toISOString(),
|
now.toISOString(),
|
||||||
this.entityId,
|
this.entityId
|
||||||
true
|
|
||||||
),
|
),
|
||||||
this.hass.user?.is_admin ? loadTraceContexts(this.hass) : {},
|
this.hass.user?.is_admin ? loadTraceContexts(this.hass) : {},
|
||||||
this._fetchUserPromise,
|
this._fetchUserPromise,
|
||||||
|
@ -135,11 +135,11 @@ class HaLogbook extends LitElement {
|
|||||||
${index === 0 ||
|
${index === 0 ||
|
||||||
(item?.when &&
|
(item?.when &&
|
||||||
previous?.when &&
|
previous?.when &&
|
||||||
new Date(item.when).toDateString() !==
|
new Date(item.when * 1000).toDateString() !==
|
||||||
new Date(previous.when).toDateString())
|
new Date(previous.when * 1000).toDateString())
|
||||||
? html`
|
? html`
|
||||||
<h4 class="date">
|
<h4 class="date">
|
||||||
${formatDate(new Date(item.when), this.hass.locale)}
|
${formatDate(new Date(item.when * 1000), this.hass.locale)}
|
||||||
</h4>
|
</h4>
|
||||||
`
|
`
|
||||||
: html``}
|
: html``}
|
||||||
@ -207,14 +207,14 @@ class HaLogbook extends LitElement {
|
|||||||
<div class="secondary">
|
<div class="secondary">
|
||||||
<span
|
<span
|
||||||
>${formatTimeWithSeconds(
|
>${formatTimeWithSeconds(
|
||||||
new Date(item.when),
|
new Date(item.when * 1000),
|
||||||
this.hass.locale
|
this.hass.locale
|
||||||
)}</span
|
)}</span
|
||||||
>
|
>
|
||||||
-
|
-
|
||||||
<ha-relative-time
|
<ha-relative-time
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.datetime=${item.when}
|
.datetime=${item.when * 1000}
|
||||||
capitalize
|
capitalize
|
||||||
></ha-relative-time>
|
></ha-relative-time>
|
||||||
${["script", "automation"].includes(item.domain!) &&
|
${["script", "automation"].includes(item.domain!) &&
|
||||||
|
@ -249,8 +249,7 @@ export class HuiLogbookCard extends LitElement implements LovelaceCard {
|
|||||||
this.hass,
|
this.hass,
|
||||||
lastDate.toISOString(),
|
lastDate.toISOString(),
|
||||||
now.toISOString(),
|
now.toISOString(),
|
||||||
this._configEntities!.map((entity) => entity.entity).toString(),
|
this._configEntities!.map((entity) => entity.entity).toString()
|
||||||
true
|
|
||||||
),
|
),
|
||||||
this._fetchUserPromise,
|
this._fetchUserPromise,
|
||||||
]);
|
]);
|
||||||
@ -264,7 +263,7 @@ export class HuiLogbookCard extends LitElement implements LovelaceCard {
|
|||||||
: newEntries;
|
: newEntries;
|
||||||
|
|
||||||
this._logbookEntries = logbookEntries.filter(
|
this._logbookEntries = logbookEntries.filter(
|
||||||
(logEntry) => new Date(logEntry.when) > hoursToShowDate
|
(logEntry) => new Date(logEntry.when * 1000) > hoursToShowDate
|
||||||
);
|
);
|
||||||
|
|
||||||
this._lastLogbookDate = now;
|
this._lastLogbookDate = now;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user