Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nk-rm into beta
  • Loading branch information
kiwi-cam committed Jun 17, 2023
2 parents 9b26402 + 35855e9 commit 931f941
Show file tree
Hide file tree
Showing 9 changed files with 13,084 additions and 100 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,17 @@ 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
### Added
- w1 and file temperatures will return a battery level of 100 if none found
- Serializes the simultaneous IR/RF commands. (Thanks @banboobee) #520
- +/- controls for light accessory. (Thanks @banboobee) #530
- Sync channel selection when tv is powered on. (Thanks @banboobee) #529
### Fixed
- Fixes log error (Thanks @hypery2k) #606
- Fan speed fixes (Thanks @dnicolson) #592 and #593
- Resolve the workaround of #440. (Thanks @banboobee) #519

## [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
46 changes: 29 additions & 17 deletions accessories/accessory.js
Expand Up @@ -5,6 +5,7 @@ const { HomebridgeAccessory } = require('../base');
const sendData = require('../helpers/sendData');
const delayForDuration = require('../helpers/delayForDuration');
const catchDelayCancelError = require('../helpers/catchDelayCancelError');
const { getDevice } = require('../helpers/getDevice');

class BroadlinkRMAccessory extends HomebridgeAccessory {

Expand Down Expand Up @@ -66,15 +67,15 @@ class BroadlinkRMAccessory extends HomebridgeAccessory {

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

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

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

async performSend (data, actionCallback) {
Expand All @@ -83,22 +84,32 @@ class BroadlinkRMAccessory extends HomebridgeAccessory {
//Error catch
if(data === undefined){return}

if (typeof data === 'string') {
// Get the Broadlink device
const device = getDevice({ host, log });

if (!host || !device) { // Error reporting
sendData({ host, hexData: data, log, name, logLevel });

return;
}

await catchDelayCancelError(async () => {
await device.mutex.use(async () => { // Queue command sequence
if (typeof data === 'string') {
await sendData({ host, hexData: data, log, name, logLevel });

Check failure on line 98 in accessories/accessory.js

View workflow job for this annotation

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

Expected indentation of 8 spaces but found 1 tab

Check failure on line 98 in accessories/accessory.js

View workflow job for this annotation

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

Expected indentation of 8 spaces but found 1 tab

Check failure on line 98 in accessories/accessory.js

View workflow job for this annotation

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

Expected indentation of 8 spaces but found 1 tab

return;

Check failure on line 100 in accessories/accessory.js

View workflow job for this annotation

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

Expected indentation of 8 spaces but found 1 tab

Check failure on line 100 in accessories/accessory.js

View workflow job for this annotation

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

Expected indentation of 8 spaces but found 1 tab

Check failure on line 100 in accessories/accessory.js

View workflow job for this annotation

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

Expected indentation of 8 spaces but found 1 tab
}

// 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;
// this.pauseTimeoutPromise = delayForDuration(pause);
// await this.pauseTimeoutPromise;
await new Promise(resolve => setTimeout(resolve, pause * 1000));
}
}
});
Expand All @@ -112,12 +123,13 @@ class BroadlinkRMAccessory extends HomebridgeAccessory {
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 });
for (let index = 0; data && index < sendCount; index++) {
await sendData({ host, hexData: data, log, name, logLevel });

if (interval && index < sendCount - 1) {
this.intervalTimeoutPromise = delayForDuration(interval);
await this.intervalTimeoutPromise;
// this.intervalTimeoutPromise = delayForDuration(interval);
// await this.intervalTimeoutPromise;
await new Promise(resolve => setTimeout(resolve, interval * 1000));
}
}
}
Expand Down
26 changes: 18 additions & 8 deletions accessories/aircon.js
Expand Up @@ -293,15 +293,15 @@ class AirConAccessory extends BroadlinkRMAccessory {
}
if (enableAutoOff && parseInt(onDuration) > 0) {
log(`${name} setTargetHeatingCoolingState: (automatically turn off in ${onDuration} seconds)`);
if (this.autoOffTimeoutPromise) {
if (this.autoOffTimeoutPromise) {
this.autoOffTimeoutPromise.cancel();
this.autoOffTimeoutPromise = null;
}
this.autoOffTimeoutPromise = delayForDuration(onDuration);
await this.autoOffTimeoutPromise;
await this.performSend(data.off);
this.updateServiceTargetHeatingCoolingState(this.HeatingCoolingStates.off);
this.updateServiceCurrentHeatingCoolingState(this.HeatingCoolingStates.off);
}
this.autoOffTimeoutPromise = delayForDuration(onDuration);
await this.autoOffTimeoutPromise;
await this.performSend(data.off);
this.updateServiceTargetHeatingCoolingState(this.HeatingCoolingStates.off);
this.updateServiceCurrentHeatingCoolingState(this.HeatingCoolingStates.off);
}
});
}
Expand Down Expand Up @@ -522,6 +522,7 @@ class AirConAccessory extends BroadlinkRMAccessory {
const { temperatureFilePath, noHumidity, batteryAlerts } = config;
let humidity = null;
let temperature = null;
let battery = null;

if (logLevel <=1) {log(`\x1b[34m[DEBUG]\x1b[0m ${name} updateTemperatureFromFile reading file: ${temperatureFilePath}`);}

Expand All @@ -545,11 +546,18 @@ class AirConAccessory extends BroadlinkRMAccessory {
let value = line.split(':');

Check warning on line 546 in accessories/aircon.js

View workflow job for this annotation

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

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

Check warning on line 546 in accessories/aircon.js

View workflow job for this annotation

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

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

Check warning on line 546 in accessories/aircon.js

View workflow job for this annotation

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

'value' is never reassigned. Use 'const' instead
if(value[0] == 'temperature') {temperature = parseFloat(value[1]);}
if(value[0] == 'humidity' && !noHumidity) {humidity = parseFloat(value[1]);}
if(value[0] == 'battery' && batteryAlerts) {state.batteryLevel = parseFloat(value[1]);}
if(value[0] == 'battery' && batteryAlerts) {battery = parseFloat(value[1]);}
}
});
}

//Default battery level if none returned
if (battery) {
state.batteryLevel = battery;
}else{
state.batteryLevel = 100;
}

if (logLevel <=1) {log(`\x1b[34m[DEBUG]\x1b[0m ${name} updateTemperatureFromFile (parsed temperature: ${temperature} humidity: ${humidity})`);}

this.onTemperature(temperature, humidity);
Expand Down Expand Up @@ -578,6 +586,8 @@ class AirConAccessory extends BroadlinkRMAccessory {
if (logLevel <=3) {log(`\x1b[33m[WARNING]\x1b[0m ${name} updateTemperatureFromW1 error reading file: ${fName}, using previous Temperature`);}
temperature = (state.currentTemperature || 0);
}
//Default battery level
state.batteryLevel = 100;

if (logLevel <=1) {log(`\x1b[34m[DEBUG]\x1b[0m ${name} updateTemperatureFromW1 (parsed temperature: ${temperature})`);}
this.onTemperature(temperature);
Expand Down
21 changes: 9 additions & 12 deletions accessories/fan.js
Expand Up @@ -92,7 +92,7 @@ class FanAccessory extends SwitchAccessory {

async setSwitchState(hexData, previousValue) {
const { config, state, serviceManager } = this;
if (!this.state.switchState) {
if (!state.switchState) {
this.lastFanSpeed = undefined;
}

Expand All @@ -101,7 +101,7 @@ class FanAccessory extends SwitchAccessory {
}

// Reset the fan speed back to the default speed when turned off
if (this.state.switchState === false && config.alwaysResetToDefaults) {
if (!state.switchState && config.alwaysResetToDefaults) {
this.setDefaults();
serviceManager.setCharacteristic(Characteristic.RotationSpeed, state.fanSpeed);
}
Expand All @@ -115,16 +115,13 @@ class FanAccessory extends SwitchAccessory {
this.reset();

// Create an array of speeds specified in the data config
const foundSpeeds = [];
const allHexKeys = Object.keys(data || {});

allHexKeys.forEach((key) => {
const parts = key.split('fanSpeed');

if (parts.length !== 2) {return;}

foundSpeeds.push(parts[1])
})
const foundSpeeds = Object.keys(data || {}).reduce((accu, key) => {
const match = key.match(/fanSpeed(\d+)/);
if (match && match[1]) {
accu.push(match[1]);

Check failure on line 121 in accessories/fan.js

View workflow job for this annotation

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

Expected indentation of 8 spaces but found 10

Check failure on line 121 in accessories/fan.js

View workflow job for this annotation

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

Expected indentation of 8 spaces but found 10

Check failure on line 121 in accessories/fan.js

View workflow job for this annotation

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

Expected indentation of 8 spaces but found 10
}
return accu;
}, []);

if (config.speedCycle && config.speedSteps) {
for (let i = 1; i <= config.speedSteps; i++) {
Expand Down

0 comments on commit 931f941

Please sign in to comment.