NEEO Does Not Update Switch State Correctly

I have defined the callback function to get the state of the switch, but while call back function seems to return the correct state, the UI does not seem to show the correct state. Is there a problem with my code or with the UI?

.addSwitch({ name: 'wemoSwitch', label: 'Power' },
{ setter: controller.switchSet, getter: controller.switchGet } )

function switchGet(deviceid) {
  let client = wemoClients[deviceid];
  if (client) {
      client.getBinaryState(function(err, value) {
      console.log('switchGet ', value);
      return value === '1' ? true : false;
    });
  } else {
    wemo.discover(foundWeMoDevice);
  }
},

I also noticed that the POWER ON and POWER OFF buttons do not update the switch status. Any Ideas?

Both the switch and power on/off buttons are operating the device correctly.

Reply
2replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Your code is not correct, your function does not returns anything.

    You need to return a Promise in the swtichGet function, like below. 

    function switchGet(deviceid) {
    return new Promise( (resolve, reject) => {
      let client = wemoClients[deviceid];
      client.getBinaryState(function(err, value) {
          console.log('switchGet ', value);
          resolve( value === '1' ? true : false );
      });
    });
    }
    Like
    • Thanks Cédric Legendre 

      What do I return if the client is not set? Just not call resolve? Call reject?

      Like
Like Follow