Skip to content

Commit

Permalink
maybe?
Browse files Browse the repository at this point in the history
  • Loading branch information
donavanbecker committed Oct 24, 2024
1 parent eec6627 commit d385bb0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import type { API, DynamicPlatformPlugin, HAP, Logging, PlatformAccessory, Unkno
import type {
accessoryAttribute,
devicesConfig,
HttpMethod,
location,
locations,
resideoDevice,
ResideoPlatformConfig,
sensorAccessory,

T9groups,
} from './settings.js'

Expand Down Expand Up @@ -209,16 +211,28 @@ export class ResideoPlatform implements DynamicPlatformPlugin {
}
}

public async discoverlocations(): Promise<location[]> {
async discoverlocations(): Promise<location[]> {
this.debugLog(`accessToken: ${this.config.credentials?.accessToken}, consumerKey: ${this.config.credentials?.consumerKey}`)
const { body, statusCode } = await request(LocationURL, {

const options: {
method: HttpMethod
headers: {
'Authorization': string
'Content-Type': string
'apikey': string | undefined
}
} = {
method: 'GET',
headers: {
'Authorization': `Bearer ${this.config.credentials?.accessToken}`,
'Content-Type': 'application/json',
'apikey': this.config.credentials?.consumerKey,
},
})
}

this.debugLog(`Request options: ${JSON.stringify(options)}`)

const { body, statusCode } = await request(`${LocationURL}?apikey=${this.config.credentials?.consumerKey}`, options)

this.debugLog(`Response status code: ${statusCode}`)

Expand All @@ -228,7 +242,7 @@ export class ResideoPlatform implements DynamicPlatformPlugin {

const locations = await body.json() as location[]
this.debugLog(`(discoverlocations) Location: ${JSON.stringify(locations)}`)
return locations // Ensure this returns an array
return locations
}

public async getCurrentSensorData(location: location, device: resideoDevice & devicesConfig, group: T9groups) {
Expand Down
2 changes: 2 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const LocationURL = 'https://api.honeywell.com/v2/locations'
*/
export const DeviceURL = 'https://api.honeywell.com/v2/devices'

export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD'

// Config
export interface ResideoPlatformConfig extends PlatformConfig {
credentials?: credentials
Expand Down

0 comments on commit d385bb0

Please sign in to comment.