@@ -50,12 +50,9 @@ export class HatchBabyApi {
50
50
} )
51
51
}
52
52
53
- async getIotDevices ( memberProducts : string [ ] ) {
53
+ async getIotDevices ( ... products : Product [ ] ) {
54
54
// Combine the user's products with the known products to ensure we get all devices
55
- const allProducts = Array . from (
56
- new Set ( [ ...memberProducts , ...knownProducts ] ) ,
57
- ) ,
58
- productFetchQueryString = allProducts
55
+ const productFetchQueryString = products
59
56
. map ( ( product ) => 'iotProducts=' + product )
60
57
. join ( '&' ) ,
61
58
devices =
@@ -157,12 +154,9 @@ export class HatchBabyApi {
157
154
}
158
155
159
156
async getDevices ( ) {
160
- const member = await this . getMember ( ) ,
161
- memberProducts = member . products . filter (
162
- ( product : Product ) => ! ignoredProducts . includes ( product ) ,
163
- ) ,
164
- [ devices , onIotClient ] = await Promise . all ( [
165
- this . getIotDevices ( memberProducts ) ,
157
+ const [ devices , member , onIotClient ] = await Promise . all ( [
158
+ this . getIotDevices ( ...knownProducts ) ,
159
+ this . getMember ( ) ,
166
160
this . getOnIotClient ( ) ,
167
161
] ) ,
168
162
createDevices = < T extends IotDevice < any > > (
@@ -189,33 +183,44 @@ export class HatchBabyApi {
189
183
logInfo ( 'Unsupported Product Found: ' + product + debugMessage )
190
184
191
185
if ( this . config . debug ) {
192
- const debugDevices = createDevices ( product , IotDevice )
193
- for ( const device of debugDevices ) {
194
- try {
195
- logInfo ( `Debug info for ${ product } ${ device . info . name } :` )
196
- logInfo (
197
- JSON . stringify (
198
- {
199
- ...device . info ,
200
- id : '***' ,
201
- macAddress : '***' ,
202
- thingName : '***' ,
203
- memberId : '***' ,
204
- email : '***' ,
205
- } ,
206
- null ,
207
- 2 ,
208
- ) ,
186
+ this . getIotDevices ( product )
187
+ . then ( async ( unknownDevices ) => {
188
+ const debugDevices = unknownDevices . map (
189
+ ( device ) => new IotDevice ( device , onIotClient ) ,
209
190
)
210
- logInfo ( `State for ${ product } ${ device . info . name } :` )
211
- logInfo ( JSON . stringify ( await device . getCurrentState ( ) , null , 2 ) )
212
- } catch ( e ) {
213
- logError (
214
- `Failed to get debug info for ${ product } ${ device . info . name } ` ,
215
- )
216
- logError ( e )
217
- }
218
- }
191
+ for ( const device of debugDevices ) {
192
+ try {
193
+ logInfo ( `Debug info for ${ product } ${ device . info . name } :` )
194
+ logInfo (
195
+ JSON . stringify (
196
+ {
197
+ ...device . info ,
198
+ id : '***' ,
199
+ macAddress : '***' ,
200
+ thingName : '***' ,
201
+ memberId : '***' ,
202
+ email : '***' ,
203
+ } ,
204
+ null ,
205
+ 2 ,
206
+ ) ,
207
+ )
208
+ logInfo ( `State for ${ product } ${ device . info . name } :` )
209
+ logInfo (
210
+ JSON . stringify ( await device . getCurrentState ( ) , null , 2 ) ,
211
+ )
212
+ } catch ( e ) {
213
+ logError (
214
+ `Failed to get debug info for ${ product } ${ device . info . name } ` ,
215
+ )
216
+ logError ( e )
217
+ }
218
+ }
219
+ } )
220
+ . catch ( ( error ) => {
221
+ logError ( 'Failed to get debug info for ' + product )
222
+ logError ( error )
223
+ } )
219
224
}
220
225
}
221
226
}
0 commit comments