peter-murray / node-hue-api

Node.js Library for interacting with the Philips Hue Bridge and Lights
Apache License 2.0
1.18k stars 145 forks source link

Error: Unknown type 'geofence' to create Bridge Model Object from. #182

Closed vincentEuloge closed 4 years ago

vincentEuloge commented 4 years ago

When I call 'api.sensors.getAll()' I get the error: "Error: Unknown type 'geofence' to create Bridge Model Object from."

In the source code: 'https://github.com/peter-murray/node-hue-api/blob/master/lib/model/index.js'. there's no such thing as the geofence type.

After some research, it seems that 'geofence' is linked to my smartphone, here is the object which corresponds to it

{
  config:{on: true, reachable: true}
  manufacturername:'XXXXXXXX'
  modelid:'HA_GEOFENCE'
  name:'Samsung SM-G920F'
  recycle:false
  state:{presence: false, lastupdated: '2019-04-10T05:41:00'}
  swversion:'A_1'
  type:'Geofence'
  uniqueid:'YYYYYYY'
}

I found a quick workaround by modifying the 'buildAllSensorsResult' function.

function buildAllSensorsResult(data) {
  const result = [];

  if (data) {
    Object.keys(data).forEach(id => {
      try{
        const sensorData = data[id]
        , type = sensorData.type.toLowerCase()
        , sensor = model.createFromBridge(type, id, sensorData)
        ;
        result.push(sensor);
      }catch(err){
        console.log(err.toString());
      }

    });
  }

  return result;
}

the 'try catch' avoids receiving zero results when a type is unknown

peter-murray commented 4 years ago

Thanks for the information, I will get on to that later today and get a fix out.

There is no mention of geofence in the supported sensor types from Signify developer documentation, but I will use the information you have provided to cater for a new sensor type for now.

peter-murray commented 4 years ago

I have released a 4.0.9-rc1 to npm regsitry that contains a fix for you, can you please verify this works and if so I can release it as 4.0.9.

vincentEuloge commented 4 years ago

I just tested it, it works. Thanks

peter-murray commented 4 years ago

4.0.9 has been released to the npm registry with the fix applied.

Thanks for the feedback.