cocoro-sdk
Advanced tools
Comparing version 0.2.1 to 0.3.0
{ | ||
"name": "cocoro-sdk", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "", | ||
@@ -13,3 +13,3 @@ "main": "dist/index.js", | ||
"author": "David Mohl", | ||
"license": "MIT", | ||
"license": "AGPL", | ||
"devDependencies": { | ||
@@ -16,0 +16,0 @@ "@babel/core": "^7.14.8", |
@@ -55,1 +55,5 @@ # Cocoro Air SDK | ||
All property updates are getting batched and sent at once to the server to update the device state | ||
## License | ||
AGPL |
@@ -28,4 +28,2 @@ import { default as fetchCookie } from 'fetch-cookie'; | ||
private async sendGETRequest(path) { | ||
console.debug('sending get request: ', path); | ||
return fetch(`${this.apiBase}${path}`, { | ||
@@ -42,4 +40,2 @@ method: 'get', | ||
private async sendPOSTRequest(path: string, body: Record<string, any>) { | ||
console.debug('sending post request: ', path, JSON.stringify(body)); | ||
return fetch(`${this.apiBase}${path}`, { | ||
@@ -173,4 +169,34 @@ method: 'post', | ||
// update existing device propertstatus to the new values | ||
for (const [k, v] of Object.entries(updateMap)) { | ||
for (let i = 0; i <= device.status.length; i++) { | ||
if (device.status[i].statusCode === k) { | ||
device.status[i] = v; | ||
} | ||
} | ||
} | ||
// reset property updates so they don't fire again | ||
device.propertyUpdates = []; | ||
return res.json(); | ||
} | ||
/** | ||
* Fetches a specific device | ||
* Good for reloading the latest data | ||
* | ||
* @param {Device} device The device | ||
* @return {Promise<Device>} The device. | ||
*/ | ||
async fetchDevice(device: Device): Promise<Device> { | ||
const devices = await this.queryDevices(); | ||
for (const d of devices) { | ||
if (d.deviceId === device.deviceId) { | ||
return d; | ||
} | ||
} | ||
throw new Error('device does not exist'); | ||
} | ||
} |
@@ -93,3 +93,3 @@ import { default as fetchCookie } from 'fetch-cookie'; | ||
*/ | ||
queuePropertyUpdate(propertyStatus: PropertyStatus): void { | ||
queuePropertyStatusUpdate(propertyStatus: PropertyStatus): void { | ||
for (const property of this.properties) { | ||
@@ -183,2 +183,29 @@ if (property.statusCode !== propertyStatus.statusCode) { | ||
/** | ||
* Gets the room temperature. | ||
* | ||
* @return {number} The temperature. | ||
*/ | ||
getRoomTemperature(): number { | ||
return parseInt( | ||
( | ||
this.getPropertyStatus( | ||
StatusCode.ROOM_TEMPERATURE, | ||
) as RangePropertyStatus | ||
).valueRange.code, | ||
); | ||
} | ||
/** | ||
* Gets the windspeed. | ||
* | ||
* @return {ValueSingle} The windspeed. | ||
*/ | ||
getWindspeed() { | ||
const ws = this.getPropertyStatus( | ||
StatusCode.WINDSPEED, | ||
) as SinglePropertyStatus; | ||
return ws.valueSingle.code; | ||
} | ||
/** | ||
* Queues a temperature update | ||
@@ -192,3 +219,3 @@ * | ||
this.queuePropertyUpdate({ | ||
this.queuePropertyStatusUpdate({ | ||
valueBinary: { | ||
@@ -206,3 +233,3 @@ code: s8.state, | ||
queuePowerOn(): void { | ||
this.queuePropertyUpdate({ | ||
this.queuePropertyStatusUpdate({ | ||
valueSingle: { | ||
@@ -220,3 +247,3 @@ code: ValueSingle.POWER_ON, | ||
queuePowerOff(): void { | ||
this.queuePropertyUpdate({ | ||
this.queuePropertyStatusUpdate({ | ||
valueSingle: { | ||
@@ -242,3 +269,3 @@ code: ValueSingle.POWER_OFF, | ||
) { | ||
this.queuePropertyUpdate({ | ||
this.queuePropertyStatusUpdate({ | ||
valueSingle: { | ||
@@ -251,2 +278,26 @@ code: mode, | ||
} | ||
/** | ||
* Queues windspeed update | ||
*/ | ||
queueWindspeedUpdate( | ||
mode: | ||
| ValueSingle.WINDSPEED_LEVEL_1 | ||
| ValueSingle.WINDSPEED_LEVEL_2 | ||
| ValueSingle.WINDSPEED_LEVEL_3 | ||
| ValueSingle.WINDSPEED_LEVEL_4 | ||
| ValueSingle.WINDSPEED_LEVEL_5 | ||
| ValueSingle.WINDSPEED_LEVEL_6 | ||
| ValueSingle.WINDSPEED_LEVEL_7 | ||
| ValueSingle.WINDSPEED_LEVEL_8 | ||
| ValueSingle.WINDSPEED_LEVEL_AUTO, | ||
) { | ||
this.queuePropertyStatusUpdate({ | ||
valueSingle: { | ||
code: mode, | ||
}, | ||
statusCode: StatusCode.WINDSPEED, | ||
valueType: ValueType.SINGLE, | ||
}); | ||
} | ||
} |
@@ -8,2 +8,3 @@ export enum StatusCode { | ||
HEAT_TEMPERATURE = 'B3', | ||
ROOM_TEMPERATURE = 'BB', | ||
} | ||
@@ -10,0 +11,0 @@ |
Copyleft License
License(Experimental) Copyleft license information was found
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
69538
2902
59
2