homebridge-air
Advanced tools
Comparing version 1.0.0-beta.8 to 1.0.0-beta.9
import { interval } from 'rxjs'; | ||
import { skipWhile } from 'rxjs/operators'; | ||
import striptags from 'striptags'; | ||
import { request } from 'undici'; | ||
// import { request } from 'undici' | ||
import { AirNowUrl, AqicnUrl, HomeKitAQI } from '../settings.js'; | ||
@@ -117,8 +117,9 @@ import { deviceBase } from './device.js'; | ||
try { | ||
const { body, statusCode } = await request(url); | ||
let response; | ||
const response = await fetch(url); | ||
const statusCode = response.status; | ||
let responseBody; | ||
let rawBody = ''; | ||
try { | ||
rawBody = await body.text(); // Read the raw response body as text | ||
response = JSON.parse(rawBody); // Parse the raw response body as JSON | ||
rawBody = await response.text(); // Read the raw response body as text | ||
responseBody = JSON.parse(rawBody); // Parse the raw response body as JSON | ||
} | ||
@@ -131,11 +132,11 @@ catch (jsonError) { | ||
await this.debugWarnLog(`statusCode: ${JSON.stringify(statusCode)}`); | ||
await this.debugLog(`response: ${JSON.stringify(response)}`); | ||
await this.debugLog(`response: ${JSON.stringify(responseBody)}`); | ||
if (statusCode !== 200) { | ||
this.errorLog(`${this.device.provider === 'airnow' ? 'AirNow' : 'World Air Quality Index'} air quality Network or Unknown Error from %s.`, this.device.provider); | ||
this.AirQualitySensor.StatusFault = this.hap.Characteristic.StatusFault.GENERAL_FAULT; | ||
await this.debugLog(`Error: ${JSON.stringify(response)}`); | ||
await this.apiError(response); | ||
await this.debugLog(`Error: ${JSON.stringify(responseBody)}`); | ||
await this.apiError(responseBody); | ||
} | ||
else { | ||
this.deviceStatus = this.device.provider === 'aqicn' ? response.data : response; | ||
this.deviceStatus = this.device.provider === 'aqicn' ? responseBody.data : responseBody; | ||
await this.parseStatus(); | ||
@@ -142,0 +143,0 @@ } |
@@ -98,5 +98,14 @@ import { readFileSync } from 'node:fs'; | ||
} | ||
if (!deviceConfig.zipCode) { | ||
await this.errorLog('Missing your Zip Code'); | ||
if (deviceConfig.zipCode || deviceConfig.city) { | ||
if (!deviceConfig.zipCode || !deviceConfig.city) { | ||
const missing = !deviceConfig.zipCode ? 'Zip Code' : 'City'; | ||
await this.errorLog(`Missing your ${missing}`); | ||
} | ||
} | ||
if (deviceConfig.latitude || deviceConfig.longitude) { | ||
if (!deviceConfig.latitude || !deviceConfig.longitude) { | ||
const missing = !deviceConfig.latitude ? 'Latitude' : 'Longitude'; | ||
await this.errorLog(`Missing your ${missing}`); | ||
} | ||
} | ||
} | ||
@@ -114,6 +123,10 @@ } | ||
try { | ||
for (const device of this.config.devices) { | ||
device.city = device.city ?? 'Unknown'; | ||
device.zipCode = device.zipCode ?? '00000' ?? await this.infoLog(`Discovered ${device.city}`); | ||
this.createAirQualitySensor(device); | ||
if (this.config.devices) { | ||
for (const device of this.config.devices) { | ||
device.city = device.city ?? 'Unknown'; | ||
device.zipCode = device.zipCode ?? '00000'; | ||
device.provider = device.provider ?? 'Unknown'; | ||
await this.infoLog(`Discovered ${device.city}`); | ||
this.createAirQualitySensor(device); | ||
} | ||
} | ||
@@ -127,3 +140,3 @@ } | ||
// generate a unique id for the accessory | ||
const uuidString = (device.latitude && device.longitude) ? (device.latitude + device.longitude + device.apiKey) : (device.zipCode + device.apiKey); | ||
const uuidString = (device.latitude && device.longitude) ? (device.latitude + device.longitude) : (device.zipCode + device.city); | ||
const uuid = this.api.hap.uuid.generate(uuidString); | ||
@@ -154,3 +167,3 @@ // see if an accessory with the same uuid has already been registered and restored from | ||
} | ||
else if (!device.delete) { | ||
else if (!device.delete && !existingAccessory) { | ||
// create a new accessory | ||
@@ -157,0 +170,0 @@ const accessory = new this.api.platformAccessory(device.city, uuid); |
@@ -5,3 +5,3 @@ { | ||
"type": "module", | ||
"version": "1.0.0-beta.8", | ||
"version": "1.0.0-beta.9", | ||
"description": "The AirNow plugin allows you to monitor the current AirQuality for your Zip Code from HomeKit and Siri.", | ||
@@ -25,3 +25,3 @@ "author": { | ||
"type": "git", | ||
"url": "https://github.com/donavanbecker/homebridge-air.git" | ||
"url": "git+https://github.com/donavanbecker/homebridge-air.git" | ||
}, | ||
@@ -62,3 +62,2 @@ "bugs": { | ||
"dependencies": { | ||
"@apiverve/zipcodes": "^1.1.4", | ||
"@homebridge/plugin-ui-utils": "^1.0.3", | ||
@@ -70,3 +69,3 @@ "rxjs": "^7.8.1", | ||
"devDependencies": { | ||
"@antfu/eslint-config": "^3.6.2", | ||
"@antfu/eslint-config": "^3.7.1", | ||
"@types/aes-js": "^3.1.4", | ||
@@ -81,3 +80,3 @@ "@types/debug": "^4.1.12", | ||
"@vitest/coverage-v8": "^2.1.1", | ||
"eslint": "^9.10.0", | ||
"eslint": "^9.11.0", | ||
"eslint-plugin-format": "^0.1.2", | ||
@@ -87,4 +86,4 @@ "homebridge": "^1.8.4", | ||
"jest": "^29.7.0", | ||
"nodemon": "^3.1.4", | ||
"npm-check-updates": "^17.1.1", | ||
"nodemon": "^3.1.7", | ||
"npm-check-updates": "^17.1.3", | ||
"shx": "^0.3.4", | ||
@@ -91,0 +90,0 @@ "ts-node": "^10.9.2", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
333577
4
3034
4
- Removed@apiverve/zipcodes@^1.1.4
- Removed@apiverve/zipcodes@1.1.5(transitive)
- Removedasap@2.0.6(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaxios@1.7.7(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removeddata-uri-to-buffer@4.0.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedfetch-blob@3.2.0(transitive)
- Removedfollow-redirects@1.15.9(transitive)
- Removedform-data@4.0.1(transitive)
- Removedformdata-polyfill@4.0.10(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removednode-domexception@1.0.0(transitive)
- Removednode-fetch@3.3.2(transitive)
- Removedpromise@8.3.0(transitive)
- Removedproxy-from-env@1.1.0(transitive)
- Removedweb-streams-polyfill@3.3.3(transitive)