Skip to content

Commit

Permalink
Updates to address ETIMEDOUT error
Browse files Browse the repository at this point in the history
Reference CHANGELOG.md for summary of changes.
  • Loading branch information
DMBlakeley committed Oct 2, 2023
1 parent 7678f5f commit faee85b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/).

## v3.0.3
* Updates to `tempestApi.ts` to minimize `ETIMEDOUT` error:
* Revert `axios.get` calls to include `headers:` declaration.
* Add `import https from 'https';`
* Add `axios.defaults.httpsAgent = new https.Agent({ keepAlive: true });`
* Add `axios.defaults.timeout = 10000;` and remove timeout from `axios.get` calls.

## v3.0.2
* Update node-version: [16.x, 18.x, 20.x], remove 14.x which is no longer supported by homebridge.
* Update `devDependencies` and `dependencies` to latest versions. Update/lock `axios` to version `1.5.0`.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": false,
"displayName": "Homebridge WeatherFlow Tempest",
"name": "homebridge-weatherflow-tempest",
"version": "3.0.2",
"version": "3.0.3",
"description": "Exposes WeatherFlow Tempest Station data as Temperature Sensors, Light Sensors, Humidity Sensors and Fan Sensors (for Wind Speed).",
"license": "Apache-2.0",
"repository": {
Expand Down
22 changes: 16 additions & 6 deletions src/tempestApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Logger } from 'homebridge';
import axios, { AxiosResponse } from 'axios';
import https from 'https';

axios.defaults.timeout = 10000; // same as default interval
axios.defaults.httpsAgent = new https.Agent({ keepAlive: true });

export interface Observation {
// temperature sensors
Expand Down Expand Up @@ -52,9 +56,11 @@ export class TempestApi {
private async getStationObservation(): Promise<AxiosResponse | undefined> {

try {
const url = `https://swd.weatherflow.com/swd/rest/observations/station/${this.station_id}?token=${this.token}`;
const url = `https://swd.weatherflow.com/swd/rest/observations/station/${this.station_id}`;
const options = {
timeout: 1000,
headers: {
'Authorization': `Bearer ${this.token}`,
},
validateStatus: (status: number) => status >= 200 && status < 300, // Default
};
const observation = await axios.get(url, options);
Expand Down Expand Up @@ -108,9 +114,11 @@ export class TempestApi {

public async getTempestBatteryLevel(device_id): Promise<number> {

const url = `https://swd.weatherflow.com/swd/rest/observations/device/${device_id}?token=${this.token}`;
const url = `https://swd.weatherflow.com/swd/rest/observations/device/${device_id}`;
const options = {
timeout: 1000,
headers: {
'Authorization': `Bearer ${this.token}`,
},
validateStatus: (status: number) => status >= 200 && status < 300, // Default
};

Expand All @@ -130,9 +138,11 @@ export class TempestApi {

public async getTempestDeviceId(): Promise<number> {

const url = `https://swd.weatherflow.com/swd/rest/stations/${this.station_id}?token=${this.token}`;
const url = `https://swd.weatherflow.com/swd/rest/stations/${this.station_id}`;
const options = {
timeout: 1000,
headers: {
'Authorization': `Bearer ${this.token}`,
},
validateStatus: (status: number) => status >= 200 && status < 300, // Default
};

Expand Down

0 comments on commit faee85b

Please sign in to comment.