Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/devices/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,10 @@ export abstract class SwitchBotDevice extends EventEmitter {
try {
return await tryBLE()
} catch (err) {
this.logger?.warn?.('BLE getStatus failed', err)
if (this.enableFallback && this.hasAPI()) {
this.logger?.warn?.('Falling back to API getStatus', err)
this.logger?.debug?.('BLE getStatus failed, falling back to API', err)
} else {
this.logger?.warn?.('BLE getStatus failed', err)
}
}
if (this.enableFallback && this.hasAPI()) {
Expand All @@ -360,9 +361,10 @@ export abstract class SwitchBotDevice extends EventEmitter {
try {
return await tryAPI()
} catch (err) {
this.logger?.warn?.('API getStatus failed', err)
if (this.enableFallback && this.hasBLE()) {
this.logger?.warn?.('Falling back to BLE getStatus', err)
this.logger?.debug?.('API getStatus failed, falling back to BLE', err)
} else {
this.logger?.warn?.('API getStatus failed', err)
}
}
if (this.enableFallback && this.hasBLE()) {
Expand Down Expand Up @@ -486,7 +488,7 @@ export abstract class SwitchBotDevice extends EventEmitter {
this.circuitBreakerBLE.recordFailure()
}

this.logger.error('BLE command failed', error)
this.logger.debug('BLE command failed', error)
this.emitError({ type: 'ble', error })

return {
Expand Down Expand Up @@ -565,7 +567,7 @@ export abstract class SwitchBotDevice extends EventEmitter {
this.circuitBreakerAPI.recordFailure()
}

this.logger.error('API command failed', error)
this.logger.debug('API command failed', error)
this.emitError({ type: 'api', error })

return {
Expand Down Expand Up @@ -728,7 +730,7 @@ export abstract class SwitchBotDevice extends EventEmitter {
this.circuitBreakerBLE.recordFailure()
}

this.logger.error('Failed to read BLE status', error)
this.logger.debug('Failed to read BLE status', error)
throw error
}
}
Expand Down Expand Up @@ -797,7 +799,7 @@ export abstract class SwitchBotDevice extends EventEmitter {
this.circuitBreakerAPI.recordFailure()
}

this.logger.error('Failed to read API status', error)
this.logger.debug('Failed to read API status', error)
throw error
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ export class RetryExecutor {
if (attemptNumber < this.config.maxAttempts && (isDBusError || isBleakRetry || attemptNumber < this.config.maxAttempts)) {
// DBus error: always backoff 0.25s (250ms) before normal backoff
if (isDBusError) {
this.logger.warn(
this.logger.debug(
`${description} DBus error detected on attempt ${attemptNumber}, applying 250ms backoff`,
{ error: errorMsg },
)
await new Promise(resolve => setTimeout(resolve, 250))
}
const delayMs = this.calculateDelay(attemptNumber)
this.logger.warn(
this.logger.debug(
`${description} failed on attempt ${attemptNumber}/${this.config.maxAttempts}, retrying in ${delayMs}ms`,
{
error: errorMsg,
Expand All @@ -156,7 +156,7 @@ export class RetryExecutor {
)
await new Promise(resolve => setTimeout(resolve, delayMs))
} else {
this.logger.error(
this.logger.debug(
`${description} failed after ${attemptNumber} attempts`,
{
error: errorMsg,
Expand Down
Loading