Hi, I’m using the ManagerImages but clearly the wrong way.
My apps constantly create new images with ManagerImages.createImage() but the images live forever in Homey. Is there a best practice to do this? Is there also a way to delete old images?
See this issue of one of my apps here:
They will disappear when app got restarted.
Hope restarting the app after every game will not be the solution
I have done it this way and only have one image (album art) per device which is changed again and again.
Chris
this.registerCapabilityListener('volume_set', this.onCapabilityVolumeSet.bind(this));
this.registerCapabilityListener('volume_mute', this.onCapabilityVolumeMute.bind(this));
this.registerCapabilityListener('button.off', this.onCapabilityPlayerOff.bind(this));
this.registerCapabilityListener('button.preset1', this.onCapabilityPreset.bind(this, '1'));
this.registerCapabilityListener('button.preset2', this.onCapabilityPreset.bind(this, '2'));
this.registerCapabilityListener('button.preset3', this.onCapabilityPreset.bind(this, '3'));
this.registerCapabilityListener('button.preset4', this.onCapabilityPreset.bind(this, '4'));
this.registerDeviceListener('GetInfoEx', this.onDeviceGetInfoEx.bind(this));
this.#albumArtImage = await this.homey.images.createImage();
this.#albumArtImage.setUrl(null)
this.setAlbumArtImage(this.#albumArtImage)
.catch((err) => this.logError(`onInit() > AlbumArtImage > ${err.message}`));
this.#upnpClient = new UPnP.UpnpDeviceClient(`http://${this.getStoreValue('address')}:49152/description.xml`);
// FIXME: Workaround until "subscribe > renew" is fixed
// this.#upnpClient.subscribe('AVTransport', (event) => {
// this.logDebug(`onInit() > subscribe > AVTransport`)
// this.getDeviceValues()
// })
const album = data.TrackMetaData['dc:subtitle'] ? data.TrackMetaData['dc:title'] : data.TrackMetaData['upnp:album']
this.setCapabilityValue('speaker_album', String(album))
const track = data.TrackMetaData['dc:subtitle'] ? data.TrackMetaData['dc:subtitle'] : data.TrackMetaData['dc:title']
this.setCapabilityValue('speaker_track', String(track))
if (this.#currentAlbumURI !== data.TrackMetaData['upnp:albumArtURI']) {
this.#currentAlbumURI = data.TrackMetaData['upnp:albumArtURI']
this.logDebug(`onDeviceGetInfoEx() > AlbumArtImage > ${this.#currentAlbumURI}`)
this.#albumArtImage.setStream((stream) => {
const func = this.#currentAlbumURI.startsWith('https://') ? https.get : http.get
func(this.#currentAlbumURI, (res) => { res.pipe(stream) })
.on('error', (err) => { throw err });
})
this.#albumArtImage.update()
.catch((err) => this.logError(`onDeviceGetInfoEx() > AlbumArtImage > ${err.message}`));
}
} else {
this.logDebug(`onDeviceGetInfoEx() > TrackMetaData doesn't exist`)
2 Likes