-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Don't crash on startup when external converters fails to load #2…
- Loading branch information
Showing
3 changed files
with
40 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,32 @@ | ||
import * as zhc from 'zigbee-herdsman-converters'; | ||
import * as settings from '../util/settings'; | ||
import utils from '../util/utils'; | ||
import {loadExternalConverter} from '../util/utils'; | ||
import Extension from './extension'; | ||
import logger from '../util/logger'; | ||
|
||
export default class ExternalConverters extends Extension { | ||
constructor(zigbee: Zigbee, mqtt: MQTT, state: State, publishEntityState: PublishEntityState, | ||
eventBus: EventBus, enableDisableExtension: (enable: boolean, name: string) => Promise<void>, | ||
restartCallback: () => void, addExtension: (extension: Extension) => Promise<void>) { | ||
super(zigbee, mqtt, state, publishEntityState, eventBus, enableDisableExtension, restartCallback, addExtension); | ||
|
||
for (const definition of utils.getExternalConvertersDefinitions(settings.get())) { | ||
const toAdd = {...definition}; | ||
delete toAdd['homeassistant']; | ||
zhc.addDefinition(toAdd); | ||
for (const file of settings.get().external_converters) { | ||
try { | ||
for (const definition of loadExternalConverter(file)) { | ||
const toAdd = {...definition}; | ||
delete toAdd['homeassistant']; | ||
zhc.addDefinition(toAdd); | ||
} | ||
} catch (error) { | ||
logger.error(`Failed to load external converter file '${file}' (${error.message})`); | ||
logger.error( | ||
`Probably there is a syntax error in the file or the external converter is not ` + | ||
`compatible with the current Zigbee2MQTT version`); | ||
logger.error( | ||
`Note that external converters are not meant for long term usage, it's meant for local ` + | ||
`testing after which a pull request should be created to add out-of-the-box support for the device`, | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters