mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-25 13:57:21 +00:00
Update zwave_js log subscription to handle core changes (#9262)
This commit is contained in:
parent
9fbd594f37
commit
ce3c8f264d
@ -193,6 +193,18 @@ export const getIdentifiersFromDevice = (
|
||||
};
|
||||
};
|
||||
|
||||
export type ZWaveJSLogUpdate = ZWaveJSLogMessageUpdate | ZWaveJSLogConfigUpdate;
|
||||
|
||||
interface ZWaveJSLogMessageUpdate {
|
||||
type: "log_message";
|
||||
log_message: ZWaveJSLogMessage;
|
||||
}
|
||||
|
||||
interface ZWaveJSLogConfigUpdate {
|
||||
type: "log_config";
|
||||
log_config: ZWaveJSLogConfig;
|
||||
}
|
||||
|
||||
export interface ZWaveJSLogMessage {
|
||||
timestamp: string;
|
||||
level: string;
|
||||
@ -203,10 +215,10 @@ export interface ZWaveJSLogMessage {
|
||||
export const subscribeZWaveJSLogs = (
|
||||
hass: HomeAssistant,
|
||||
entry_id: string,
|
||||
callback: (message: ZWaveJSLogMessage) => void
|
||||
callback: (update: ZWaveJSLogUpdate) => void
|
||||
) =>
|
||||
hass.connection.subscribeMessage<ZWaveJSLogMessage>(callback, {
|
||||
type: "zwave_js/subscribe_logs",
|
||||
hass.connection.subscribeMessage<ZWaveJSLogUpdate>(callback, {
|
||||
type: "zwave_js/subscribe_log_updates",
|
||||
entry_id,
|
||||
});
|
||||
|
||||
|
@ -33,16 +33,20 @@ class ZWaveJSLogs extends SubscribeMixin(LitElement) {
|
||||
|
||||
public hassSubscribe(): Array<UnsubscribeFunc | Promise<UnsubscribeFunc>> {
|
||||
return [
|
||||
subscribeZWaveJSLogs(this.hass, this.configEntryId, (log) => {
|
||||
subscribeZWaveJSLogs(this.hass, this.configEntryId, (update) => {
|
||||
if (!this.hasUpdated) {
|
||||
return;
|
||||
}
|
||||
if (Array.isArray(log.message)) {
|
||||
for (const line of log.message) {
|
||||
this._textarea!.value += `${line}\n`;
|
||||
if (update.type === "log_message") {
|
||||
if (Array.isArray(update.log_message.message)) {
|
||||
for (const line of update.log_message.message) {
|
||||
this._textarea!.value += `${line}\n`;
|
||||
}
|
||||
} else {
|
||||
this._textarea!.value += `${update.log_message.message}\n`;
|
||||
}
|
||||
} else {
|
||||
this._textarea!.value += `${log.message}\n`;
|
||||
this._logConfig = update.log_config;
|
||||
}
|
||||
}).then((unsub) => {
|
||||
this._textarea!.value += `${this.hass.localize(
|
||||
@ -141,7 +145,6 @@ class ZWaveJSLogs extends SubscribeMixin(LitElement) {
|
||||
return;
|
||||
}
|
||||
setZWaveJSLogLevel(this.hass!, this.configEntryId, selected);
|
||||
this._logConfig.level = selected;
|
||||
this._textarea!.value += `${this.hass.localize(
|
||||
"ui.panel.config.zwave_js.logs.log_level_changed",
|
||||
{ level: selected.charAt(0).toUpperCase() + selected.slice(1) }
|
||||
|
Loading…
x
Reference in New Issue
Block a user