Created
December 18, 2020 17:41
-
-
Save alanef/ab9a9480bde7809d8466f584938368a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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