Skip to content
This repository has been archived by the owner on Apr 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #164 from 0ff/feature/show-correct-temperature
Browse files Browse the repository at this point in the history
Show the temperature of an associated temp sensor if available
  • Loading branch information
ilcato authored Feb 15, 2020
2 parents cfa926a + 081a8ce commit 5c7c3f1
Showing 3 changed files with 25 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/getFunctions.ts
Original file line number Diff line number Diff line change
@@ -100,7 +100,20 @@ export class GetFunctions {
// Float getter
getFloat(callback, characteristic, service, IDs, properties) {
let r = parseFloat(properties.value);
this.returnValue(r, callback, characteristic);

if(service.floatServiceId) {
this.platform.fibaroClient.getDeviceProperties(service.floatServiceId)
.then((properties) => {
r = parseFloat(properties.value);
this.returnValue(r, callback, characteristic);
})
.catch((err) => {
console.log("There was a problem getting value from: ", `${service.floatServiceId} - Err: ${err}` );
callback(err, null);
});
} else {
this.returnValue(r, callback, characteristic);
}
}
getBrightness(callback, characteristic, service, IDs, properties) {
let r;
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -172,7 +172,7 @@ class FibaroHC2 {
for (let s = 0; s < accessory.services.length; s++) {
let service = accessory.services[s];
if (service.subtype != undefined) {
let subtypeParams = service.subtype.split("-"); // DEVICE_ID-VIRTUAL_BUTTON_ID-RGB_MARKER-OPERATING_MODE_ID
let subtypeParams = service.subtype.split("-"); // DEVICE_ID-VIRTUAL_BUTTON_ID-RGB_MARKER-OPERATING_MODE_ID-FLOAT_SVC_ID
if (subtypeParams.length >= 3 && subtypeParams[2] == "RGB") {
// For RGB devices add specific attributes for managing it
service.HSBValue = {hue: 0, saturation: 0, brightness: 0};
@@ -183,6 +183,9 @@ class FibaroHC2 {
if (subtypeParams.length >= 4) {
service.operatingModeId = subtypeParams[3];
}
if (subtypeParams.length >= 5) {
service.floatServiceId = subtypeParams[4];
}
}
for (let i = 0; i < service.characteristics.length; i++) {
let characteristic = service.characteristics[i];
8 changes: 7 additions & 1 deletion src/shadows.ts
Original file line number Diff line number Diff line change
@@ -237,7 +237,13 @@ export class ShadowAccessory {
let m = siblings.get("com.fibaro.operatingMode");
if (m) {
controlService.operatingModeId = m.id;
controlService.subtype = device.id + "---" + m.id;
controlService.subtype = device.id + "---" + m.id;
}
// Check if there's a temperature Sensor and use it instead of the provided float value
let t = siblings.get("com.fibaro.temperatureSensor");
if(t) {
controlService.floatServiceId = t.id;
controlService.subtype = (controlService.subtype || device.id + "----") + t.id;
}
ss = [new ShadowService(controlService, controlCharacteristics)];
break;

0 comments on commit 5c7c3f1

Please sign in to comment.