athombv / homey-web-api-issues

This issue tracker is for Homey Developers using the Web API.
4 stars 1 forks source link

homey.insights.on() is broken and never fires #49

Closed hive closed 2 months ago

hive commented 9 months ago

The insights event listeners never fire meaning its not possible to be aware of insight changes.

try {
      this.api = await HomeyAPI.createAppAPI({
            homey: this.homey,
      });

      // POC for zones - works
      console.log('--- Zones ---')                // works
      await api.zones.connect()                   // works
      let zones = await api.zones.getZones()      // works
      console.log(zones)                          // works
      api.zones.on('zone.update', (data: any) => console.log(data))  // works

      // POC for insights - never fires
      console.log('--- Insights ---')                // works
      await api.insights.connect()                   // works
      let insights = await api.insights.getLogs()    // works
      console.log(insights)                          // works
      api.insights.on('log.update', (data: any) => console.log(data))  // never fires

      for (let x in values) {
            insights[x].on('update', async (data: any) => {
                  console.log(data) // never fires
            });
      }

    } catch (e) {
      this.error(e); 
    }
jeroenwienk commented 9 months ago

The insights event listeners never fire meaning its not possible to be aware of insight changes.

try {
      this.api = await HomeyAPI.createAppAPI({
            homey: this.homey,
      });

      // POC for zones - works
      console.log('--- Zones ---')                // works
      await api.zones.connect()                   // works
      let zones = await api.zones.getZones()      // works
      console.log(zones)                          // works
      api.zones.on('zone.update', (data: any) => console.log(data))  // works

      // POC for insights - never fires
      console.log('--- Insights ---')                // works
      await api.insights.connect()                   // works
      let insights = await api.insights.getLogs()    // works
      console.log(insights)                          // works
      api.insights.on('log.update', (data: any) => console.log(data))  // never fires

      for (let x in values) {
            insights[x].on('update', async (data: any) => {
                  console.log(data) // never fires
            });
      }

    } catch (e) {
      this.error(e); 
    }

When do you expect it to fire?

hive commented 9 months ago

I would assume that when an insight is updated or created that it would fire along with information about the insights information which has updated, perhaps when a log entry is created in the log?

Note that there is also no way to listen to the logEntries in order to provide information about any insights - the only approach is to poll constantly.

WeeJeWel commented 2 months ago

It's correct that there is no event when a log entry is created. Polling is the way forward, that's why there's a property that tells you when the next value is expected.

log.update does fire when the Insight's title, units etc. changes, which is of course almost never.