Skip to content

Commit

Permalink
Reload knx object when project data is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
farmio committed Sep 3, 2024
1 parent 6f0c5a2 commit 88029d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ import "./knx-router";
import { KNX } from "./types/knx";
import { LocationChangedEvent } from "./types/navigation";

declare global {
// for fire event
interface HASSDomEvents {
"knx-reload": undefined;
}
}

@customElement("knx-frontend")
class KnxFrontend extends knxElement {
@property({ attribute: false }) public hass!: HomeAssistant;
Expand All @@ -38,6 +45,11 @@ class KnxFrontend extends knxElement {
}
this.addEventListener("knx-location-changed", (e) => this._setRoute(e as LocationChangedEvent));

this.addEventListener("knx-reload", (_) => {
this.knx.log.debug("Reloading KNX object");
this._initKnx();
});

computeDirectionStyles(computeRTL(this.hass), this.parentElement as LitElement);

document.body.addEventListener("keydown", (ev: KeyboardEvent) => {
Expand Down
3 changes: 3 additions & 0 deletions src/views/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mdiFileUpload } from "@mdi/js";
import { css, nothing, html, LitElement, TemplateResult, CSSResultGroup } from "lit";
import { customElement, property, state } from "lit/decorators";

import { fireEvent } from "@ha/common/dom/fire_event";
import { navigate } from "@ha/common/navigate";
import "@ha/components/ha-card";
import "@ha/layouts/hass-tabs-subpage";
Expand Down Expand Up @@ -250,6 +251,7 @@ export class KNXInfo extends LitElement {
this._projectPassword = undefined;
}
this._uploading = false;
fireEvent(this, "knx-reload");
this.loadKnxInfo();
}
}
Expand All @@ -271,6 +273,7 @@ export class KNXInfo extends LitElement {
text: extractApiErrorMessage(err),
});
} finally {
fireEvent(this, "knx-reload");
this.loadKnxInfo();
}
}
Expand Down

0 comments on commit 88029d9

Please sign in to comment.