Skip to content

Commit

Permalink
ioBroker Check and Service Bot fix errors and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Sickbart committed Aug 10, 2024
1 parent b65bc32 commit 69dc60d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 51 deletions.
15 changes: 1 addition & 14 deletions io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,6 @@
"uk": "новий конфігурований хост API",
"zh-cn": "新的可配置 API 主机"
},
"1.2.2": {
"en": "more features",
"de": "weitere Funktionen",
"ru": "Слава Украины",
"pt": "mais funcionalidades",
"nl": "meer functies",
"fr": "plus de fonctionnalités",
"it": "altre caratteristiche",
"es": "más funciones",
"pl": "Dziękuję, drodzy sąsiedzi",
"uk": "більше можливостей",
"zh-cn": "更多功能"
},
"1.2.1": {
"en": "adjustments for Surepet API changes",
"de": "Anpassungen für Surepet API Änderungen",
Expand Down Expand Up @@ -282,7 +269,7 @@
},
"dependencies": [
{
"js-controller": ">=3.0.0"
"js-controller": ">=5.0.19"
}
],
"globalDependencies": [
Expand Down
91 changes: 54 additions & 37 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,21 @@ class Sureflap extends utils.Adapter {
startLoadingData() {
this.log.debug(`starting SureFlap Adapter v` + ADAPTER_VERSION);
clearTimeout(this.timerId);
this.doAuthenticate().then(() => this.startUpdateLoop()).catch(error => {
if (error.message === this.lastLoginError) {
this.log.debug(error);
} else {
this.log.error(error);
this.lastLoginError = error.message;
}
this.log.info(`disconnected`);
if (!this.adapterUnloaded) {
// @ts-ignore
this.timerId = setTimeout(this.startLoadingData.bind(this), RETRY_FREQUENCY_LOGIN * 1000);
}
});
this.doAuthenticate()
.then(() => this.startUpdateLoop())
.catch(error => {
if (error.message === this.lastLoginError) {
this.log.debug(error);
} else {
this.log.error(error);
this.lastLoginError = error.message;
}
this.log.info(`disconnected`);
if (!this.adapterUnloaded) {
// @ts-ignore
this.timerId = setTimeout(this.startLoadingData.bind(this), RETRY_FREQUENCY_LOGIN * 1000);
}
});
}

/**
Expand Down Expand Up @@ -327,22 +329,31 @@ class Sureflap extends utils.Adapter {
*/
updateLoop() {
clearTimeout(this.timerId);
this.getDataFromApi().then(() => this.getAdditionalDataFromApi()).then(() => this.createAdapterObjectHierarchy()).then(() => this.getDeviceStatusFromData()).then(() => this.getPetStatusFromData()).then(() => this.getEventHistoryFromData()).then(() => this.updateAdapterVersion()).then(() => this.setUpdateTimer()).catch(error => {
if (error.message === this.lastError) {
this.log.debug(error);
} else {
this.log.error(error);
this.lastError = error.message;
}
this.log.info(`update loop stopped`);
this.log.info(`disconnected`);
if (!this.adapterUnloaded) {
// @ts-ignore
this.timerId = setTimeout(this.startLoadingData.bind(this), RETRY_FREQUENCY_LOGIN * 1000);
}
}).finally(() => {
this.firstLoop = false;
});
this.getDataFromApi()
.then(() => this.getAdditionalDataFromApi())
.then(() => this.createAdapterObjectHierarchy())
.then(() => this.getDeviceStatusFromData())
.then(() => this.getPetStatusFromData())
.then(() => this.getEventHistoryFromData())
.then(() => this.updateAdapterVersion())
.then(() => this.setUpdateTimer())
.catch(error => {
if (error.message === this.lastError) {
this.log.debug(error);
} else {
this.log.error(error);
this.lastError = error.message;
}
this.log.info(`update loop stopped`);
this.log.info(`disconnected`);
if (!this.adapterUnloaded) {
// @ts-ignore
this.timerId = setTimeout(this.startLoadingData.bind(this), RETRY_FREQUENCY_LOGIN * 1000);
}
})
.finally(() => {
this.firstLoop = false;
});
}

/**
Expand Down Expand Up @@ -2372,13 +2383,19 @@ class Sureflap extends utils.Adapter {
return /** @type {Promise<void>} */(new Promise((resolve, reject) => {
if (this.firstLoop === true) {
this.log.debug(`creating device hierarchy...`);
this.removeDeprecatedDataFromAdapter().then(() => this.removeDeletedAndRenamedPetsFromAdapter()).then(() => this.createHouseholdsAndHubsToAdapter()).then(() => this.createDevicesToAdapter()).then(() => this.createPetsToAdapter()).then(() => {
this.log.debug(`device hierarchy created.`);
return resolve();
}).catch(() => {
this.log.error(`creating device hierarchy failed.`);
return reject();
});
this.removeDeprecatedDataFromAdapter()
.then(() => this.removeDeletedAndRenamedPetsFromAdapter())
.then(() => this.createHouseholdsAndHubsToAdapter())
.then(() => this.createDevicesToAdapter())
.then(() => this.createPetsToAdapter())
.then(() => {
this.log.debug(`device hierarchy created.`);
return resolve();
})
.catch(() => {
this.log.error(`creating device hierarchy failed.`);
return reject();
});
} else {
return resolve();
}
Expand Down Expand Up @@ -3895,7 +3912,7 @@ class Sureflap extends utils.Adapter {
*/
httpRequest(tag, options, postData) {
return new Promise((resolve, reject) => {
this.log.silly(`doing http request with tag ${tag}`);
this.log.silly(`doing http request '${tag}'`);
const req = https.request(options, (res) => {
if (res.statusCode && (res.statusCode < 200 || res.statusCode >= 300)) {
this.log.debug(`Request (${tag}) returned status code ${res.statusCode}.`);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"homepage": "https://github.com/Sickboy78/ioBroker.sureflap",
"license": "MIT",
"keywords": [
"ioBroker",
"sureflap",
"surepetcare",
"petcare",
Expand Down

0 comments on commit 69dc60d

Please sign in to comment.