Skip to content

Instantly share code, notes, and snippets.

@alanef
Created December 18, 2020 17:41
Show Gist options
  • Select an option

  • Save alanef/ab9a9480bde7809d8466f584938368a2 to your computer and use it in GitHub Desktop.

Select an option

Save alanef/ab9a9480bde7809d8466f584938368a2 to your computer and use it in GitHub Desktop.
const find = require('local-devices');
const fetch = require('node-fetch');
let heatpumpIPs = [];
const getHeatpumps = () => find().then( async devices => {
for ( let i = 0; i < devices.length; i++) {
try {
let response = await fetch('http://' + devices[i].ip + '/common/basic_info')
let isHeatpump = await response.ok
if( ! isHeatpump ) {
throw new Error(devices[i].ip + ': Not a Heat Pump')
}
heatpumpIPs.push(devices[i].ip)
} catch (e) {
//
console.log(e.message);
}
}
return devices
})
async function go() {
devices = await getHeatpumps()
console.log(heatpumpIPs)
}
go();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment