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 #211 from ilcato/fix-warning-and-slowdown
Browse files Browse the repository at this point in the history
Fix api syntax
  • Loading branch information
ilcato authored Feb 27, 2021
2 parents 706d6a7 + 415e6d5 commit afa42d1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
9 changes: 6 additions & 3 deletions src/getFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export class GetFunctions {

if (service.floatServiceId) {
this.platform.fibaroClient.getDeviceProperties(service.floatServiceId)
.then((properties) => {
.then((res) => {
const properties = res.body;
r = parseFloat(properties.value);
this.returnValue(r, callback, characteristic);
})
Expand Down Expand Up @@ -186,7 +187,8 @@ export class GetFunctions {
getCurrentHeatingCoolingState(callback, characteristic, service, IDs, properties) {
if (service.operatingModeId) { // Operating mode is availble on Home Center
this.platform.fibaroClient.getDeviceProperties(service.operatingModeId)
.then((properties) => {
.then((res) => {
const properties = res.body;
switch (properties.mode) {
case "0": // OFF
this.returnValue(this.hapCharacteristic.CurrentHeatingCoolingState.OFF, callback, characteristic);
Expand Down Expand Up @@ -220,7 +222,8 @@ export class GetFunctions {
getTargetHeatingCoolingState(callback, characteristic, service, IDs, properties) {
if (service.operatingModeId) { // Operating mode is availble on Home Center
this.platform.fibaroClient.getDeviceProperties(service.operatingModeId)
.then((properties) => {
.then((res) => {
const properties = res.body;
switch (properties.mode) {
case "0": // OFF
this.returnValue(this.hapCharacteristic.TargetHeatingCoolingState.OFF, callback, characteristic);
Expand Down
15 changes: 10 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,14 @@ class FibaroHC2 {
if (!this.fibaroClient)
return;
this.fibaroClient.getScenes()
.then((scenes) => {
.then((res) => {
const scenes = res.body;
this.mapSceneIDs(scenes);
this.setFunctions = new SetFunctions(Characteristic, this); // There's a dependency in setFunction to Scene Mapping
return this.fibaroClient ? this.fibaroClient.getDevices() : {};
})
.then((devices) => {
.then((res) => {
const devices = res.body;
this.LoadAccessories(devices);
})
.catch((err) => {
Expand Down Expand Up @@ -342,7 +344,8 @@ class FibaroHC2 {
if (service.isSecuritySystem) {
if (!this.fibaroClient) return;
this.fibaroClient.getGlobalVariable("SecuritySystem")
.then((securitySystemStatus) => {
.then((res) => {
const securitySystemStatus = res.body;
if (this.getFunctions)
this.getFunctions.getSecuritySystemState(callback, characteristic, service, IDs, securitySystemStatus); })
.catch((err) => {
Expand All @@ -355,7 +358,8 @@ class FibaroHC2 {
if (service.isGlobalVariableSwitch) {
if (!this.fibaroClient) return;
this.fibaroClient.getGlobalVariable(IDs[1])
.then((switchStatus) => {
.then((res) => {
const switchStatus = res.body;
if (this.getFunctions)
this.getFunctions.getBool(callback, characteristic, service, IDs, switchStatus);
})
Expand All @@ -375,7 +379,8 @@ class FibaroHC2 {
setTimeout(() => {
if (!this.fibaroClient) return;
this.fibaroClient.getDeviceProperties(IDs[0])
.then((properties: any) => {
.then((res) => {
const properties = res.body;
if (getFunction.function) {
if (this.config.FibaroTemperatureUnit == "F") {
if (characteristic.displayName == 'Current Temperature') {
Expand Down
9 changes: 6 additions & 3 deletions src/pollerupdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export class Poller {
this.pollingUpdateRunning = true;

this.platform.fibaroClient.refreshStates(this.lastPoll)
.then((updates) => {
.then((res) => {
const updates = res.body;
if (updates.last != undefined)
this.lastPoll = updates.last;
if (updates.changes != undefined) {
Expand All @@ -68,7 +69,8 @@ export class Poller {
// Manage Security System state
if (this.platform.config.securitysystem == "enabled") {
this.platform.fibaroClient.getGlobalVariable("SecuritySystem")
.then((securitySystemStatus) => {
.then((res) => {
const securitySystemStatus = res.body;
if (this.platform.securitySystemService == undefined)
return;
let statec = this.platform.getFunctions.getCurrentSecuritySystemStateMapping.get(securitySystemStatus.value);
Expand All @@ -85,7 +87,8 @@ export class Poller {
let globalVariables = this.platform.config.switchglobalvariables.split(',');
for(let i = 0; i < globalVariables.length; i++) {
this.platform.fibaroClient.getGlobalVariable(globalVariables[i])
.then((switchStatus) => {
.then((res) => {
const switchStatus = res.body;
this.platform.getFunctions.getBool(null, this.searchCharacteristic(globalVariables[i]), null, null, switchStatus);
})
.catch((err) =>{
Expand Down
6 changes: 4 additions & 2 deletions src/setFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ export class SetFunctions {
if (service.operatingModeId) { // Operating mode is availble on Home Center
// need to force the operating mode to the current one because of a Fibaro API bug (setting temperature through the API change the mode to HEAT)
this.platform.fibaroClient.getDeviceProperties(IDs[0])
.then((properties) => {
.then((res) => {
const properties = res.body;
currentOpMode = properties.mode;
this.command("setThermostatSetpoint", [currentOpMode, value], service, IDs);
})
Expand Down Expand Up @@ -307,7 +308,8 @@ export class SetFunctions {
}
checkLockCurrentState(IDs, value) {
this.platform.fibaroClient.getDeviceProperties(IDs[0])
.then((properties) => {
.then((res) => {
const properties = res.body;
var currentValue = (properties.value == "true") ? this.hapCharacteristic.LockCurrentState.SECURED : this.hapCharacteristic.LockCurrentState.UNSECURED;
if (currentValue != value) {
this.platform.log("There was a problem setting value to Lock: ", `${IDs[0]}`);
Expand Down

0 comments on commit afa42d1

Please sign in to comment.