Skip to content

Commit

Permalink
Improved terminal text coloring to support dark terminal windows
Browse files Browse the repository at this point in the history
  • Loading branch information
lprhodes committed Mar 17, 2018
1 parent ac43c77 commit af6a9b8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
24 changes: 12 additions & 12 deletions accessories/aircon.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ class AirConAccessory extends BroadlinkRMAccessory {

// Check required properties
if (config.pseudoDeviceTemperature) {
assert.isBelow(config.pseudoDeviceTemperature, config.maxTemperature + 1, `\x1b[31m[CONFIG ERROR] \x1b[33mpseudoDeviceTemperature\x1b[30m (${config.pseudoDeviceTemperature}) must be less than the maxTemperature (${config.maxTemperature})`)
assert.isAbove(config.pseudoDeviceTemperature, config.minTemperature - 1, `\x1b[31m[CONFIG ERROR] \x1b[33mpseudoDeviceTemperature\x1b[30m (${config.pseudoDeviceTemperature}) must be more than the minTemperature (${config.minTemperature})`)
assert.isBelow(config.pseudoDeviceTemperature, config.maxTemperature + 1, `\x1b[31m[CONFIG ERROR] \x1b[33mpseudoDeviceTemperature\x1b[0m (${config.pseudoDeviceTemperature}) must be less than the maxTemperature (${config.maxTemperature})`)
assert.isAbove(config.pseudoDeviceTemperature, config.minTemperature - 1, `\x1b[31m[CONFIG ERROR] \x1b[33mpseudoDeviceTemperature\x1b[0m (${config.pseudoDeviceTemperature}) must be more than the minTemperature (${config.minTemperature})`)
}

// minTemperature can't be more than 10 or HomeKit throws a fit
assert.isBelow(config.minTemperature, 11, `\x1b[31m[CONFIG ERROR] \x1b[33mminTemperature\x1b[30m (${config.minTemperature}) must be <= 10`)
assert.isBelow(config.minTemperature, 11, `\x1b[31m[CONFIG ERROR] \x1b[33mminTemperature\x1b[0m (${config.minTemperature}) must be <= 10`)

// maxTemperature > minTemperature
assert.isBelow(config.minTemperature, config.maxTemperature, `\x1b[31m[CONFIG ERROR] \x1b[33mmaxTemperature\x1b[30m (${config.minTemperature}) must be more than minTemperature (${config.minTemperature})`)
assert.isBelow(config.minTemperature, config.maxTemperature, `\x1b[31m[CONFIG ERROR] \x1b[33mmaxTemperature\x1b[0m (${config.minTemperature}) must be more than minTemperature (${config.minTemperature})`)
}

reset () {
Expand Down Expand Up @@ -260,7 +260,7 @@ class AirConAccessory extends BroadlinkRMAccessory {

let mode = hexData['pseudo-mode'];

if (mode) assert.oneOf(mode, [ 'heat', 'cool', 'auto' ], '\x1b[31m[CONFIG ERROR] \x1b[33mpseudo-mode\x1b[30m should be one of "heat", "cool" or "auto"');
if (mode) assert.oneOf(mode, [ 'heat', 'cool', 'auto' ], '\x1b[31m[CONFIG ERROR] \x1b[33mpseudo-mode\x1b[0m should be one of "heat", "cool" or "auto"');

if (!mode) {
if (state.targetTemperature < state.currentTemperature) {
Expand Down Expand Up @@ -292,10 +292,10 @@ class AirConAccessory extends BroadlinkRMAccessory {
const defaultTemperature = (temperature >= heatTemperature) ? defaultHeatTemperature : defaultCoolTemperature;
hexData = data[`temperature${defaultTemperature}`];

assert(hexData, `\x1b[31m[CONFIG ERROR] \x1b[30m You need to provide a hex code for the following temperature:
\x1b[33m{ "temperature${temperature}": { "data": "HEXCODE", "pseudo-mode" : "heat/cool" } }\x1b[30m
assert(hexData, `\x1b[31m[CONFIG ERROR] \x1b[0m You need to provide a hex code for the following temperature:
\x1b[33m{ "temperature${temperature}": { "data": "HEXCODE", "pseudo-mode" : "heat/cool" } }\x1b[0m
or provide the default temperature:
\x1b[33m { "temperature${defaultTemperature}": { "data": "HEXCODE", "pseudo-mode" : "heat/cool" } }\x1b[30m`);
\x1b[33m { "temperature${defaultTemperature}": { "data": "HEXCODE", "pseudo-mode" : "heat/cool" } }\x1b[0m`);


this.log(`${name} Update to default temperature (${defaultTemperature})`);
Expand Down Expand Up @@ -363,8 +363,8 @@ class AirConAccessory extends BroadlinkRMAccessory {

log(`${name} onTemperature (${temperature})`);

assert.isBelow(temperature, config.maxTemperature + 1, `\x1b[31m[CONFIG ERROR] \x1b[33mmaxTemperature\x1b[30m (${config.maxTemperature}) must be more than the reported temperature (${temperature})`)
assert.isAbove(temperature, config.minTemperature - 1, `\x1b[31m[CONFIG ERROR] \x1b[33mminTemperature\x1b[30m (${config.maxTemperature}) must be less than the reported temperature (${temperature})`)
assert.isBelow(temperature, config.maxTemperature + 1, `\x1b[31m[CONFIG ERROR] \x1b[33mmaxTemperature\x1b[0m (${config.maxTemperature}) must be more than the reported temperature (${temperature})`)
assert.isAbove(temperature, config.minTemperature - 1, `\x1b[31m[CONFIG ERROR] \x1b[33mminTemperature\x1b[0m (${config.maxTemperature}) must be less than the reported temperature (${temperature})`)

this.processQueuedTemperatureCallbacks(temperature);
}
Expand Down Expand Up @@ -417,13 +417,13 @@ class AirConAccessory extends BroadlinkRMAccessory {
fs.readFile(temperatureFilePath, 'utf8', (err, temperature) => {

if (err) {
log(`\x1b[31m[ERROR] \x1b[30m${name} updateTemperatureFromFile\n\n${err.message}`);
log(`\x1b[31m[ERROR] \x1b[0m${name} updateTemperatureFromFile\n\n${err.message}`);

return;
}

if (!temperature || temperature.trim().length === 0) {
log(`\x1b[31m[ERROR] \x1b[30m${name} updateTemperatureFromFile (no temperature found)`);
log(`\x1b[31m[ERROR] \x1b[0m${name} updateTemperatureFromFile (no temperature found)`);

return;
}
Expand Down
2 changes: 1 addition & 1 deletion accessories/switchMulti.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SwitchMultiAccessory extends SwitchAccessory {
const { data, log, name, config, serviceManagerType } = this;

setTimeout(() => {
log(`\x1b[33m[Warning] \x1b[30m${name}: The "switch-multi" accessory is now deprecated and shall be removed in the future. Check out the updated "switch" documentation at http://github.com/lprhodes/homebridge-broadlink-rm`);
log(`\x1b[33m[Warning] \x1b[0m${name}: The "switch-multi" accessory is now deprecated and shall be removed in the future. Check out the updated "switch" documentation at http://github.com/lprhodes/homebridge-broadlink-rm`);
}, 1600)

this.serviceManager = new ServiceManagerTypes[serviceManagerType](name, Service.Switch, this.log);
Expand Down
2 changes: 1 addition & 1 deletion accessories/switchMultiRepeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class SwitchMultiAccessory extends SwitchAccessory {
const { data, log, name, config, serviceManagerType } = this;

setTimeout(() => {
log(`\x1b[33m[Warning] \x1b[30m${name}: The "switch-multi-repeat" accessory is now deprecated and shall be removed in the future. Check out the updated "switch" documentation at http://github.com/lprhodes/homebridge-broadlink-rm`);
log(`\x1b[33m[Warning] \x1b[0m${name}: The "switch-multi-repeat" accessory is now deprecated and shall be removed in the future. Check out the updated "switch" documentation at http://github.com/lprhodes/homebridge-broadlink-rm`);
}, 1600)

this.serviceManager = new ServiceManagerTypes[serviceManagerType](name, Service.Switch, this.log);
Expand Down
2 changes: 1 addition & 1 deletion accessories/switchRepeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SwitchRepeatAccessory extends SwitchAccessory {
const { data, log, name, config, serviceManagerType } = this;

setTimeout(() => {
log(`\x1b[33m[Warning] \x1b[30m${name}: The "switch-repeat" accessory is now deprecated and shall be removed in the future. Check out the updated "switch" documentation at http://github.com/lprhodes/homebridge-broadlink-rm`);
log(`\x1b[33m[Warning] \x1b[0m${name}: The "switch-repeat" accessory is now deprecated and shall be removed in the future. Check out the updated "switch" documentation at http://github.com/lprhodes/homebridge-broadlink-rm`);
}, 1600)

this.serviceManager = new ServiceManagerTypes[serviceManagerType](name, Service.Switch, this.log);
Expand Down
12 changes: 6 additions & 6 deletions helpers/sendData.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ const { getDevice } = require('./getDevice');
const convertProntoCode = require('./convertProntoCode')

module.exports = ({ host, hexData, log, name, debug }) => {
assert(hexData && typeof hexData === 'string', `\x1b[31m[ERROR]: \x1b[30m${name} sendData (HEX value is missing)`);
assert(hexData && typeof hexData === 'string', `\x1b[31m[ERROR]: \x1b[0m${name} sendData (HEX value is missing)`);

// Check for pronto code
if (hexData.substring(0, 4) === '0000') {
if (debug) log(`${name} sendHex (Converting Pronto code "${hexData}" to Broadlink code)`);
hexData = convertProntoCode(hexData)
if (debug) log(`${name} sendHex (Pronto code successfuly converted: "${hexData}")`);

if (!hexData) return log(`\x1b[31m[ERROR] \x1b[30m${name} sendData (A Pronto code was detected however its conversion to a Broadlink code failed.)`);
if (!hexData) return log(`\x1b[31m[ERROR] \x1b[0m${name} sendData (A Pronto code was detected however its conversion to a Broadlink code failed.)`);

}

// Get the Broadlink device
const device = getDevice({ host, log });

if (!device) {
if (!host) return log(`\x1b[31m[ERROR] \x1b[30m${name} sendData (no auto-discovered device found and no "host" option set)`);
if (!host) return log(`\x1b[31m[ERROR] \x1b[0m${name} sendData (no auto-discovered device found and no "host" option set)`);

return log(`\x1b[31m[ERROR] \x1b[30m${name} sendData (no device found at ${host})`);
return log(`\x1b[31m[ERROR] \x1b[0m${name} sendData (no device found at ${host})`);
}

if (!device.sendData) return log(`\x1b[31m[ERROR] \x1b[30mThe device at ${device.host.address} (${device.host.macAddress}) doesn't support the sending of IR or RF codes.`);
if (hexData.includes('5aa5aa555')) return log('\x1b[31m[ERROR] \x1b[30mThis type of hex code (5aa5aa555...) is no longer valid. Use the included "Learn Code" accessory to find new (decrypted) codes.');
if (!device.sendData) return log(`\x1b[31m[ERROR] \x1b[0mThe device at ${device.host.address} (${device.host.macAddress}) doesn't support the sending of IR or RF codes.`);
if (hexData.includes('5aa5aa555')) return log('\x1b[31m[ERROR] \x1b[0mThis type of hex code (5aa5aa555...) is no longer valid. Use the included "Learn Code" accessory to find new (decrypted) codes.');

const hexDataBuffer = new Buffer(hexData, 'hex');
device.sendData(hexDataBuffer, debug, hexData);
Expand Down

0 comments on commit af6a9b8

Please sign in to comment.