Fix BLE data parsing and move from toString-based Buffer parsing to int-based

- parsing only 1 byte for command (hex "98" vs earlier "0098")
This commit is contained in:
Victor Hagelbäck 2021-02-02 19:23:19 +01:00
parent 8719cda8a3
commit 5b3efb4b79
2 changed files with 47 additions and 25 deletions

View file

@ -25,20 +25,35 @@ const logFormat = printf((info) => {
/** Winston-based logger */
class Logger {
static shouldLogLookup = {};
constructor() {
throw new Error('Please call createLogger instead');
}
static getLogLevel() {
const config = Configuration.getConfiguration();
// eslint-disable-next-line max-len
const level = (config.logLevel && LEVELS.find((l) => l.startsWith(config.logLevel[0].toLowerCase())))
|| 'info';
return level;
}
static shouldLog(logLevel) {
if (!Logger.shouldLogLookup[logLevel]) {
// eslint-disable-next-line max-len
Logger.shouldLogLookup[logLevel] = Logger.logLevels().levels[logLevel] <= Logger.logLevels().levels[Logger.getLogLevel()];
}
return Logger.shouldLogLookup[logLevel];
}
/** Created logger will follow Winston createLogger, but
* - add module name to logger
* - swap debug/verbose levels and omit http to mimic HA standard
* Levels (in order): error, warn, info, debug, verbose, silly
* */
static getLogger(moduleName) {
const config = Configuration.getConfiguration();
// eslint-disable-next-line max-len
const level = (config.logLevel && LEVELS.find((l) => l.startsWith(config.logLevel[0].toLowerCase())))
|| 'info';
const level = Logger.getLogLevel();
const logger = winston.createLogger({
format: combine(