You are currently viewing the Homey Apps SDK v2 documentation. New apps should use Homey Apps SDK v3 ››

Images

A Device can have one or more references to a registered Image.

Album Art

A device can have one album art image attached. Register the images once, and then keep updating it.

/drivers/<driver_id>/device.js

class MyDevice extends Homey.Device {

  onInit() {
    this.image = new Homey.Image();
    this.image.setUrl(null);
    this.image.register()
    	.then(() => {
    		return this.setAlbumArtImage( this.image );
    	})
    	.catch(this.error);

    this.myDeviceApi.on('track', track => {
      const albumArtUrl = track.albumArtUrl; // e.g. https://www.example.com/track/abcd/image.png
      this.image.setUrl(albumArtUrl);
      this.image.update();
    });
  }

Camera

A device can have one or more camera images.

class MyCameraDevice extends Homey.Device {

  onInit() {
    this.image = new Homey.Image();
    this.image.setStream(async (stream) => {
      const res = await fetch(this.myDeviceApi.localImageUrl);
      if(!res.ok) throw new Error(res.statusText);
      res.body.pipe(stream);
    });
    this.image.register()
    	.then(() => {
    		return this.setCameraImage('front',  Homey.__("camera.front.title"), this.image );
    	})
    	.catch(this.error);

    this.myDeviceApi.on('motion', track => {
      this.image.update()
        .catch(this.error);
    });
  }