Skip to content

Commit

Permalink
v4.4.13 release (#612)
Browse files Browse the repository at this point in the history
* Serialize the simultaneous commands.
---------

Co-authored-by: Cameron <32912464+kiwi-cam@users.noreply.github.com>
Co-authored-by: banboobee <98196664+banboobee@users.noreply.github.com>

* Fix log error (#606)

* chore: Fix linting errors

---------

Co-authored-by: Cameron <32912464+kiwi-cam@users.noreply.github.com>
Co-authored-by: banboobee <98196664+banboobee@users.noreply.github.com>

* Added default battery level for file and w1

To prevent false low battery warnings

---------

Co-authored-by: banboobee <qzh00033@nifty.ne.jp>
Co-authored-by: Dave Nicolson <david.nicolson@gmail.com>
Co-authored-by: banboobee <98196664+banboobee@users.noreply.github.com>
Co-authored-by: Martin Reinhardt <martin@m13t.de>
  • Loading branch information
5 people committed Jun 18, 2023
1 parent 9b26402 commit f7a1298
Show file tree
Hide file tree
Showing 64 changed files with 24,728 additions and 12,007 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Expand Up @@ -45,7 +45,7 @@
"no-autofix/prefer-const": "warn",

"indent": ["error", 2, { "SwitchCase": 1 }],
"linebreak-style": ["error", "unix"],
"linebreak-style": ["error", "windows"],
"curly": 1
}
}
13 changes: 12 additions & 1 deletion CHANGELOG.md
Expand Up @@ -4,7 +4,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.4.12] - 2023-05-24
## [Unreleased]
### Added
- w1 and file temperatures will return a battery level of 100 if none found
### Fixed
- Fixes log error (Thanks @hypery2k) #606
- Fan speed fixes (Thanks @dnicolson) #592 and #593
- Resolve the workaround of #440. (Thanks @banboobee) #519
### Changed
- Serializes the simultaneous IR/RF commands. (Thanks @banboobee) #520
- Updated dependancies to resolve known vulnerabilities

## [4.4.12] - 2022-06-08
### Added
- Added tempStepSize to configuration (defaulting to 1) to allow AC units with 0.5 steps (Thanks @nasudon) #570
- Added support for fahrenheit temperature sources #495 - set tempSourceUnits to 'F'
Expand Down
252 changes: 126 additions & 126 deletions accessories/accessory.js
@@ -1,126 +1,126 @@
const uuid = require('uuid');

const { HomebridgeAccessory } = require('../base');

const sendData = require('../helpers/sendData');
const delayForDuration = require('../helpers/delayForDuration');
const catchDelayCancelError = require('../helpers/catchDelayCancelError');

class BroadlinkRMAccessory extends HomebridgeAccessory {

constructor (log, config = {}, serviceManagerType) {
if (!config.name) {config.name = "Unknown Accessory"}

config.resendDataAfterReload = config.resendHexAfterReload;
if (config.host) {
//Clean up MAC address formatting
config.host = config.host.toLowerCase();
if (!config.host.includes(".") && !config.host.includes(":") && config.host.length === 12){
config.host = config.host.match(/[\s\S]{1,2}/g).join(':');
}
}

super(log, config, serviceManagerType);
if (config.debug) {this.debug = true}

this.manufacturer = 'Broadlink';
this.model = 'RM Mini or Pro';
this.serialNumber = uuid.v4();

//Set LogLevel
switch(this.config.logLevel){
case 'none':
this.logLevel = 6;
break;
case 'critical':
this.logLevel = 5;
break;
case 'error':
this.logLevel = 4;
break;
case 'warning':
this.logLevel = 3;
break;
case 'info':
this.logLevel = 2;
break;
case 'debug':
this.logLevel = 1;
break;
case 'trace':
this.logLevel = 0;
break;
default:
//default to 'info':
if(this.config.logLevel !== undefined) {log(`\x1b[31m[CONFIG ERROR] \x1b[33mlogLevel\x1b[0m should be one of: trace, debug, info, warning, error, critical, or none.`);}
this.logLevel = 2;
break;
}
if(this.config.debug) {this.logLevel = Math.min(1, this.logLevel);}
if(this.config.disableLogs) {this.logLevel = 6;}
}

performSetValueAction ({ host, data, log, name, logLevel }) {
sendData({ host, hexData: data, log, name, logLevel });
}

reset () {
// Clear Multi-hex timeouts
if (this.intervalTimeoutPromise) {
this.intervalTimeoutPromise.cancel();
this.intervalTimeoutPromise = null;
}

if (this.pauseTimeoutPromise) {
this.pauseTimeoutPromise.cancel();
this.pauseTimeoutPromise = null;
}
}

async performSend (data, actionCallback) {
const { logLevel, config, host, log, name } = this;

//Error catch
if(data === undefined){return}

if (typeof data === 'string') {
sendData({ host, hexData: data, log, name, logLevel });

return;
}

await catchDelayCancelError(async () => {
// Itterate through each hex config in the array
for (let index = 0; index < data.length; index++) {
const { pause } = data[index];

await this.performRepeatSend(data[index], actionCallback);

if (pause) {
this.pauseTimeoutPromise = delayForDuration(pause);
await this.pauseTimeoutPromise;
}
}
});
}

async performRepeatSend (parentData, actionCallback) {
const { host, log, name, logLevel } = this;
let { data, interval, sendCount } = parentData;

sendCount = sendCount || 1
if (sendCount > 1) {interval = interval || 0.1;}

// Itterate through each hex config in the array
for (let index = 0; index < sendCount; index++) {
sendData({ host, hexData: data, log, name, logLevel });

if (interval && index < sendCount - 1) {
this.intervalTimeoutPromise = delayForDuration(interval);
await this.intervalTimeoutPromise;
}
}
}
}

module.exports = BroadlinkRMAccessory;
const uuid = require('uuid');

const { HomebridgeAccessory } = require('../base');

const sendData = require('../helpers/sendData');
const delayForDuration = require('../helpers/delayForDuration');
const catchDelayCancelError = require('../helpers/catchDelayCancelError');

class BroadlinkRMAccessory extends HomebridgeAccessory {

constructor (log, config = {}, serviceManagerType) {
if (!config.name) {config.name = "Unknown Accessory"}

config.resendDataAfterReload = config.resendHexAfterReload;
if (config.host) {
//Clean up MAC address formatting
config.host = config.host.toLowerCase();
if (!config.host.includes(".") && !config.host.includes(":") && config.host.length === 12){
config.host = config.host.match(/[\s\S]{1,2}/g).join(':');
}
}

super(log, config, serviceManagerType);
if (config.debug) {this.debug = true}

this.manufacturer = 'Broadlink';
this.model = 'RM Mini or Pro';
this.serialNumber = uuid.v4();

//Set LogLevel
switch(this.config.logLevel){
case 'none':
this.logLevel = 6;
break;
case 'critical':
this.logLevel = 5;
break;
case 'error':
this.logLevel = 4;
break;
case 'warning':
this.logLevel = 3;
break;
case 'info':
this.logLevel = 2;
break;
case 'debug':
this.logLevel = 1;
break;
case 'trace':
this.logLevel = 0;
break;
default:
//default to 'info':
if(this.config.logLevel !== undefined) {log(`\x1b[31m[CONFIG ERROR] \x1b[33mlogLevel\x1b[0m should be one of: trace, debug, info, warning, error, critical, or none.`);}
this.logLevel = 2;
break;
}
if(this.config.debug) {this.logLevel = Math.min(1, this.logLevel);}
if(this.config.disableLogs) {this.logLevel = 6;}
}

performSetValueAction ({ host, data, log, name, logLevel }) {
sendData({ host, hexData: data, log, name, logLevel });
}

reset () {
// Clear Multi-hex timeouts
if (this.intervalTimeoutPromise) {
this.intervalTimeoutPromise.cancel();
this.intervalTimeoutPromise = null;
}

if (this.pauseTimeoutPromise) {
this.pauseTimeoutPromise.cancel();
this.pauseTimeoutPromise = null;
}
}

async performSend (data, actionCallback) {
const { logLevel, config, host, log, name } = this;

//Error catch
if(data === undefined){return}

if (typeof data === 'string') {
sendData({ host, hexData: data, log, name, logLevel });

return;
}

await catchDelayCancelError(async () => {
// Itterate through each hex config in the array
for (let index = 0; index < data.length; index++) {
const { pause } = data[index];

await this.performRepeatSend(data[index], actionCallback);

if (pause) {
this.pauseTimeoutPromise = delayForDuration(pause);
await this.pauseTimeoutPromise;
}
}
});
}

async performRepeatSend (parentData, actionCallback) {
const { host, log, name, logLevel } = this;
let { data, interval, sendCount } = parentData;

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 16 and ubuntu-latest

'data' is never reassigned. Use 'const' instead

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 20 and ubuntu-latest

'data' is never reassigned. Use 'const' instead

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 18 and ubuntu-latest

'data' is never reassigned. Use 'const' instead

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 18 and windows-latest

'data' is never reassigned. Use 'const' instead

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 20 and windows-latest

'data' is never reassigned. Use 'const' instead

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 18 and macOS-latest

'data' is never reassigned. Use 'const' instead

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 16 and macOS-latest

'data' is never reassigned. Use 'const' instead

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 20 and macOS-latest

'data' is never reassigned. Use 'const' instead

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 16 and windows-latest

'data' is never reassigned. Use 'const' instead

sendCount = sendCount || 1
if (sendCount > 1) {interval = interval || 0.1;}

// Itterate through each hex config in the array
for (let index = 0; data && index < sendCount; index++) {
sendData({ host, hexData: data, log, name, logLevel });

if (interval && index < sendCount - 1) {
this.intervalTimeoutPromise = delayForDuration(interval);
await this.intervalTimeoutPromise;
}
}
}
}

module.exports = BroadlinkRMAccessory;

0 comments on commit f7a1298

Please sign in to comment.