Images

Images are used in various places throughout Homey, such as album art for speakers and in Flows.

When an Image is registered, it needs a way of providing Homey with it's data. This can be either:

  • an URL, available from anywhere on the internet
  • a getBuffer method that returns a Buffer containing the binary data

Creating an image

Using an URL

URLs should be used when the image is available from anywhere on the internet. It's faster than using a Buffer.

const myImage = new Homey.Image('png');
myImage.setUrl('https://www.example.com/image.png'); // the URL must start with https://
myImage.register().catch(console.error);

Using a Buffer

Buffers should be used when downloading an image that cannot be access anywhere in the world.

const fetch = require('node-fetch');

const myImage = new Homey.Image('png');
myImage.setBuffer(async () => {
  const res = await fetch('http://192.168.1.100/image.png');
  if(!res.ok)
    throw new Error('Invalid Response');

  return res.buffer();
});
myImage.register().catch(console.error);

Using a Path

Paths should be used when the image is locally available.

const myImage = new Homey.Image('png');
myImage.setPath('/userdata/image.png'); // the URL must start with https://
myImage.register().catch(console.error);

Updating the image

Call Image.update() when the image has been updated, and the front-end will download the image again.

When your image uses a Buffer, the method provided in setBuffer will be called again.

At any time, you can switch between delivery type by calling Image#setPath, Image#setBuffer or Image#setURL.