homebridge-saphi-tv
Version:
This plugin allows you to control your SaphiOS PhilipsTV with support for Apps, Sources and Channels as well as Ambilight, Ambilight+Hue and a CC Remote.
71 lines • 2.65 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Utilities = void 0;
const wake_on_lan_1 = __importDefault(require("wake_on_lan"));
const fetch_timeout_1 = __importDefault(require("fetch-timeout"));
class Utilities {
constructor(config, platform) {
this.config = config;
this.platform = platform;
}
async GET(url) {
return await (0, fetch_timeout_1.default)(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
}, this.config.timeout, 'Timeout Error')
.catch(err => {
this.platform.log.debug('Error', err);
});
}
async POST(url, body) {
return await (0, fetch_timeout_1.default)(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
}, this.config.timeout, 'Timeout Error').catch(err => {
this.platform.log.debug('Error', err);
});
}
waitFor(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
wolRequest(url) {
return new Promise(() => {
this.platform.log.debug('calling WOL with URL %s', url);
if (!url) {
this.platform.log.warn('WOL-Error: ', 'No WOL-Address given.');
return;
}
if (url.substring(0, 3).toUpperCase() === 'WOL') {
//Wake on lan request
const macAddress = url.replace(/^WOL[:]?[/]?[/]?/gi, '');
this.platform.log.debug('Executing WakeOnLan request to ' + macAddress);
wake_on_lan_1.default.wake(macAddress, { num_packets: 20 }, (error) => {
if (error) {
this.platform.log.warn('WOL-Error: ', error);
}
else {
this.platform.log.info('WOL-OK!');
}
});
}
else {
if (url.length > 3) {
this.platform.log.warn('WOL-Error: ', 'The given WOL-Address does not have the correct format. Please double check your configuration');
}
else {
this.platform.log.warn('WOL-Error: ', 'No WOL-Address given.');
}
}
});
}
}
exports.Utilities = Utilities;
//# sourceMappingURL=utilities.js.map