Skip to content

Added method updateDisplayName() #3764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

justjam2013
Copy link
Contributor

@justjam2013 justjam2013 commented Jan 5, 2025

♻️ Current situation

When a cached plugin is deserialized, the cached values are loaded into the "private" property _associatedHAPAccessory. Even if displayName is changed, the properties of _associatedHAPAccessory are never modified. When the plugin is serialized back to cache, it reads the properties of _associatedHAPAccessory.

See Accessory name cannot be updated

💡 Proposed solution

Add a method to update displayName in _associatedHAPAccessory without accessing the private variable.

However a user may modify `displayName` directly, so defensively sync `_associatedHAPAccessory.displayName` with `displayName` at the moment of serialization.

⚙️ Release Notes

➕ Additional Information

Note: As _associatedHAPAccessory.displayName is sync'd with displayName at the moment of serialization, the method updateDisplayName() is not strictly needed. A better approach would be to remove the displayName property and replace it with getter and setter methods:

  public getDisplayName(): string {
    return  this._associatedHAPAccessory.displayName;
  }

  public setDisplayName(name: string): void {
    this._associatedHAPAccessory.displayName = name;
  }

Ideally setDisplayName() would have a check to make sure that name is not null, undefined, or "" and/or return an error. However this will likely break Homebridge UI and a whole lot of plugins.

Testing

Added test method to verify that a call to updateDisplayName() updates both displayName and _associatedHAPAccessory.displayName.

Reviewer Nudging

@github-actions github-actions bot added the latest label Jan 5, 2025
@donavanbecker donavanbecker changed the base branch from latest to beta-1.9.0 January 18, 2025 15:01
@donavanbecker donavanbecker enabled auto-merge (squash) January 18, 2025 15:02
@donavanbecker donavanbecker merged commit ab58890 into homebridge:beta-1.9.0 Jan 18, 2025
9 checks passed
donavanbecker pushed a commit that referenced this pull request Jan 19, 2025
* Added method updateDisplayName()

* Sync _associatedHAPAccessory.displayName and displayName at serialization
donavanbecker pushed a commit that referenced this pull request Jan 19, 2025
* Added method updateDisplayName()

* Sync _associatedHAPAccessory.displayName and displayName at serialization
donavanbecker pushed a commit that referenced this pull request Jan 19, 2025
* Added method updateDisplayName()

* Sync _associatedHAPAccessory.displayName and displayName at serialization
donavanbecker pushed a commit that referenced this pull request Jan 19, 2025
* Added method updateDisplayName()

* Sync _associatedHAPAccessory.displayName and displayName at serialization
donavanbecker pushed a commit that referenced this pull request Feb 11, 2025
- Added method updateDisplayName() (#3764) (@justjam2013)
- Fixed method handleUpdatePlatformAccessories() (#3765) (@justjam2013)
- Make it possible to set Characteristic.SerialNumber via config.json (#3761) (@Vvorcun)
- minor dependency updates
- fix: check for valid array in `handleUpdatePlatformAccessories`
- minor dependency updates

- `hap-nodejs` @ `v0.12.3`
bwp91 pushed a commit that referenced this pull request Feb 11, 2025
* Added method updateDisplayName()

* Sync _associatedHAPAccessory.displayName and displayName at serialization
bwp91 added a commit that referenced this pull request Feb 11, 2025
- Added method updateDisplayName() (#3764) (@justjam2013)
- Fixed method handleUpdatePlatformAccessories() (#3765) (@justjam2013)
- Make it possible to set Characteristic.SerialNumber via config.json (#3761) (@Vvorcun)
- minor dependency updates
- fix: check for valid array in `handleUpdatePlatformAccessories`
- minor dependency updates

- `hap-nodejs` @ `v0.12.3`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants