Skip to content

Commit

Permalink
Switch to db-vendo-client for DB
Browse files Browse the repository at this point in the history
  • Loading branch information
gaudes committed Jan 27, 2025
1 parent b42ee57 commit e3ba7d3
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 9 deletions.
2 changes: 2 additions & 0 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export default class fHelpers {
constructor(Fahrplan) {
this.Fahrplan = Fahrplan;
this.hClient = null;
this.hClientNav = null;
this.hProfile = null;
this.hProfileNav = null;
this.isUnloaded = false;
// Init Sentry
if (this.Fahrplan.supportsFeature && this.Fahrplan.supportsFeature("PLUGINS")) {
Expand Down
4 changes: 2 additions & 2 deletions lib/station.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ export default class fStation {
async verifyStation(eBhf) {
let aResult = null;
try {
aResult = await this.helper.hClient.stop(eBhf);
aResult = await this.helper.hClient.locations(eBhf);
this.json = JSON.stringify(aResult);
if (aResult.id === eBhf) {
if (aResult[0].id === eBhf) {
return true;
}
return false;
Expand Down
15 changes: 11 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import url from "node:url";

//#region Global Variables
import { createClient as hCreateClient } from "hafas-client";
// import hCreateClient from "hafas-client";
import { profile as hDBprofile } from "hafas-client/p/db/index.js";
//import { profile as hDBprofile } from "hafas-client/p/db/index.js";
//import hDBprofile from "hafas-client/p/db";
import { profile as hOEBBprofile } from "hafas-client/p/oebb/index.js";
//import hOEBBprofile from "hafas-client/p/oebb";
// const adapter = new utils.Adapter('fahrplan');
import { createClient as vCreateClient } from "db-vendo-client";
import { withThrottling } from "db-vendo-client/throttle.js";
import { profile as hDBprofile } from "db-vendo-client/p/db/index.js";
import { profile as hDBprofileNav } from "db-vendo-client/p/dbnav/index.js";

let iUpdateInterval = 5;
let tUpdateTimeout = null;
let iCounterRoutes = 0;
Expand Down Expand Up @@ -62,11 +65,15 @@ class Fahrplan extends utils.Adapter {
this.SysLang = SysConf.common.language;
}
if (this.config.Provider === "DB" && this.helper !== undefined) {
this.helper.hClient = hCreateClient(hDBprofile, "ioBroker.Fahrplan");
this.helper.hClient = vCreateClient(withThrottling(hDBprofile), "ioBroker.Fahrplan");
this.helper.hClientNav = vCreateClient(withThrottling(hDBprofileNav), "ioBroker.Fahrplan");
this.helper.hProfile = hDBprofile;
this.helper.hProfileNav = hDBprofileNav;
} else if (this.config.Provider === "OEBB" && this.helper !== undefined) {
this.helper.hClient = hCreateClient(hOEBBprofile, "ioBroker.Fahrplan");
this.helper.hClientNav = hCreateClient(hOEBBprofile, "ioBroker.Fahrplan");
this.helper.hProfile = hOEBBprofile;
this.helper.hProfileNav = hOEBBprofile;
} else {
this.log.error("Unknown provider configured");
this.terminate("Unknown provider configured");
Expand Down
200 changes: 197 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"dependencies": {
"@iobroker/adapter-core": "^3.2.3",
"db-vendo-client": "^6.3.4",
"hafas-client": "^6.3.3"
},
"devDependencies": {
Expand Down

0 comments on commit e3ba7d3

Please sign in to comment.