Skip to content

Commit

Permalink
fix(INotify): LightDetail unregister
Browse files Browse the repository at this point in the history
  • Loading branch information
Gh61 committed Jan 21, 2024
1 parent 541e9b7 commit bdcea91
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/controls/light-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,26 @@ export class HueLightDetail extends IdLitElement {
}
}

private registerLightContainerPropertyChanged(lightContainer: LightController) {
lightContainer.registerOnPropertyChanged(this._elementId, () => {
this.onLightContainerState();
this.requestUpdate();
}, /* includeHass: */ true);
}

private unregisterLightContainerPropertyChanged(lightContainer: LightController) {
lightContainer.unregisterOnPropertyChanged(this._elementId);
}

protected override updated(changedProps: PropertyValues<HueLightDetail>): void {
// register for changes on light
if (changedProps.has('lightContainer')) {
const oldValue = changedProps.get('lightContainer') as LightController | null;
if (oldValue) {
oldValue.unregisterOnPropertyChanged(this._elementId);
this.unregisterLightContainerPropertyChanged(oldValue);
}
if (this.lightContainer) {
this.lightContainer.registerOnPropertyChanged(this._elementId, () => {
this.onLightContainerState();
this.requestUpdate();
}, /* includeHass: */ true);
this.registerLightContainerPropertyChanged(this.lightContainer);
this.onLightContainerChanged();
}
}
Expand Down Expand Up @@ -320,6 +328,10 @@ export class HueLightDetail extends IdLitElement {
public override connectedCallback(): void {
super.connectedCallback();

if (this.lightContainer) {
this.registerLightContainerPropertyChanged(this.lightContainer);
}

this.updateComplete.then(() => {
if (!this._colorPicker) {
this._colorPicker = <HueColorTempPicker>this.renderRoot.querySelector('.color-picker');
Expand All @@ -338,6 +350,14 @@ export class HueLightDetail extends IdLitElement {
});
}

public override disconnectedCallback(): void {
super.disconnectedCallback();

if (this.lightContainer) {
this.unregisterLightContainerPropertyChanged(this.lightContainer);
}
}

private updateColorPickerSize(): void {
const colorPicker = <HueColorTempPicker>this.renderRoot.querySelector('.color-picker');
if (!colorPicker)
Expand Down

0 comments on commit bdcea91

Please sign in to comment.