UNPKG

homebridge-eightsleepthermostat

Version:

Homebridge thermostat accessory for the Eight Sleep Pod smart bed.

62 lines 2.05 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.get = exports.put = exports.updateState = exports.currentState = exports.clientAPI = void 0; const axios_1 = __importDefault(require("axios")); const agentkeepalive_1 = __importDefault(require("agentkeepalive")); axios_1.default.defaults.headers.common = { 'Content-Type': 'application/json', 'Accept-Encoding': 'gzip, deflate, br', 'Accept': 'application/json', 'Accept-Language': 'en-US,en;q=0.9', 'User-Agent': 'Eight%20Sleep/15296 CFNetwork/1331.0.7 Darwin/21.4.0', }; exports.clientAPI = axios_1.default.create({ baseURL: 'https://client-api.8slp.net/v1', httpsAgent: new agentkeepalive_1.default.HttpsAgent({ keepAlive: true }), }); const currentState = (endpoint) => { return generateRequest(endpoint); }; exports.currentState = currentState; const updateState = (endpoint, key, newValue) => { const body = makeReqBody(key, newValue); return generateRequest(endpoint, body); }; exports.updateState = updateState; const makeReqBody = (key, data) => { const body = {}; body[key] = data; return body; }; const generateRequest = (endpoint, data) => { return { endpoint: endpoint, body: data, }; }; const put = async (req, log) => { try { const res = await exports.clientAPI.put(req.endpoint, req.body); return res.data; } catch (error) { log === null || log === void 0 ? void 0 : log.debug('PUT request failed:', error); return null; } }; exports.put = put; const get = async (req, log) => { try { const res = await exports.clientAPI.get(req.endpoint); return res.data; } catch (error) { log === null || log === void 0 ? void 0 : log.debug('GET request failed:', error); return null; } }; exports.get = get; //# sourceMappingURL=clientRequest.js.map