diff --git a/config.schema.json b/config.schema.json index 713aee7..d921b62 100644 --- a/config.schema.json +++ b/config.schema.json @@ -29,12 +29,14 @@ "oneOf": [ { "title": "Air Now", + "description": "AirNow is a U.S. government agency that provides air quality data for the United States.", "enum": [ "airnow" ] }, { "title": "Aqicn", + "description": "Aqicn is a global air quality data provider.", "enum": [ "aqicn" ] @@ -42,7 +44,7 @@ ] }, "apiKey": { - "title": "Air Now API Key", + "title": "API Key", "type": "string", "required": true, "x-schema-form": { diff --git a/src/devices/airqualitysensor.ts b/src/devices/airqualitysensor.ts index d04ade6..8125d58 100644 --- a/src/devices/airqualitysensor.ts +++ b/src/devices/airqualitysensor.ts @@ -96,7 +96,7 @@ export class AirQualitySensor extends deviceBase { } else if (provider === 'airnow' || provider === 'aqicn') { const pollutants = provider === 'airnow' ? ['O3', 'PM2.5', 'PM10'] : ['o3', 'no2', 'so2', 'pm25', 'pm10', 'co'] pollutants.forEach((pollutant) => { - const param = provider === 'airnow' ? this.deviceStatus.find(p => p.ParameterName === pollutant) : this.deviceStatus.iaqi[pollutant]?.v + const param = provider === 'airnow' ? this.deviceStatus.find((p: { ParameterName: string }) => p.ParameterName === pollutant) : this.deviceStatus.iaqi[pollutant]?.v const aqi = provider === 'airnow' ? Number.parseFloat(param.AQI.toString()) : Number.parseFloat(param) if (aqi !== undefined) { switch (pollutant.toLowerCase()) { diff --git a/src/platform.ts b/src/platform.ts index c692b3a..84351c2 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -135,8 +135,7 @@ export class AirPlatform implements DynamicPlatformPlugin { try { for (const device of this.config.devices!) { device.city = device.city ?? 'Unknown' - device.zipCode = device.zipCode ?? '00000' - ?? await this.infoLog(`Discovered ${device.city}`) + device.zipCode = device.zipCode ?? '00000' ?? await this.infoLog(`Discovered ${device.city}`) this.createAirQualitySensor(device) } } catch { @@ -145,7 +144,8 @@ export class AirPlatform implements DynamicPlatformPlugin { } private async createAirQualitySensor(device: any) { - const uuid = this.api.hap.uuid.generate(device.city + device.apiKey + device.zipCode) + // generate a unique id for the accessory + const uuid = this.api.hap.uuid.generate(device.latitude && device.longitude ? device.latitude + device.longitude + device.apiKey : device.city + device.zipCode + device.apiKey) // see if an accessory with the same uuid has already been registered and restored from // the cached devices we stored in the `configureAccessory` method above