Skip to content

Commit

Permalink
next
Browse files Browse the repository at this point in the history
  • Loading branch information
donavanbecker committed Sep 23, 2024
1 parent aad9567 commit 2f52e6d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,22 @@
"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"
]
}
]
},
"apiKey": {
"title": "Air Now API Key",
"title": "API Key",
"type": "string",
"required": true,
"x-schema-form": {
Expand Down
2 changes: 1 addition & 1 deletion src/devices/airqualitysensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
6 changes: 3 additions & 3 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 2f52e6d

Please sign in to comment.