reworked some transitions stuff
This commit is contained in:
parent
38b8b8f79c
commit
8a2da6d46f
1 changed files with 39 additions and 39 deletions
|
|
@ -135,8 +135,7 @@ class PlejdService extends EventEmitter {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.adapter.StartDiscovery();
|
await this.adapter.StartDiscovery();
|
||||||
}
|
} catch (err) {
|
||||||
catch (err) {
|
|
||||||
console.log('plejd-ble: error: failed to start discovery. Make sure no other add-on is currently scanning.');
|
console.log('plejd-ble: error: failed to start discovery. Make sure no other add-on is currently scanning.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -166,8 +165,7 @@ class PlejdService extends EventEmitter {
|
||||||
plejd['device'] = this.devices.find(x => x.serialNumber === fixedPlejdPath);
|
plejd['device'] = this.devices.find(x => x.serialNumber === fixedPlejdPath);
|
||||||
|
|
||||||
logger('discovered ' + plejd['path'] + ' with rssi ' + plejd['rssi']);
|
logger('discovered ' + plejd['path'] + ' with rssi ' + plejd['rssi']);
|
||||||
}
|
} catch (err) {
|
||||||
catch (err) {
|
|
||||||
console.log('plejd-ble: failed inspecting ' + plejd['path'] + ' error: ' + err);
|
console.log('plejd-ble: failed inspecting ' + plejd['path'] + ' error: ' + err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -183,8 +181,7 @@ class PlejdService extends EventEmitter {
|
||||||
connectedDevice = plejd;
|
connectedDevice = plejd;
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
} catch (err) {
|
||||||
catch (err) {
|
|
||||||
console.log('plejd-ble: warning: unable to connect, will retry. ' + err);
|
console.log('plejd-ble: warning: unable to connect, will retry. ' + err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -205,8 +202,7 @@ class PlejdService extends EventEmitter {
|
||||||
try {
|
try {
|
||||||
const adapterObject = await this.bus.getProxyObject(BLUEZ_SERVICE_NAME, path);
|
const adapterObject = await this.bus.getProxyObject(BLUEZ_SERVICE_NAME, path);
|
||||||
return [path, adapterObject.getInterface(iface), adapterObject];
|
return [path, adapterObject.getInterface(iface), adapterObject];
|
||||||
}
|
} catch (err) {
|
||||||
catch (err) {
|
|
||||||
console.log('plejd-ble: error: failed to get interface \'' + iface + '\': ' + err);
|
console.log('plejd-ble: error: failed to get interface \'' + iface + '\': ' + err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -222,7 +218,9 @@ class PlejdService extends EventEmitter {
|
||||||
if (interfaceKeys.indexOf(BLUEZ_DEVICE_ID) > -1) {
|
if (interfaceKeys.indexOf(BLUEZ_DEVICE_ID) > -1) {
|
||||||
if (interfaces[BLUEZ_DEVICE_ID]['UUIDs'].value.indexOf(PLEJD_SERVICE) > -1) {
|
if (interfaces[BLUEZ_DEVICE_ID]['UUIDs'].value.indexOf(PLEJD_SERVICE) > -1) {
|
||||||
logger('found Plejd service on ' + path);
|
logger('found Plejd service on ' + path);
|
||||||
this.bleDevices.push({ 'path': path });
|
this.bleDevices.push({
|
||||||
|
'path': path
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log('uh oh, no Plejd device.');
|
console.log('uh oh, no Plejd device.');
|
||||||
}
|
}
|
||||||
|
|
@ -232,8 +230,7 @@ class PlejdService extends EventEmitter {
|
||||||
updateSettings(settings) {
|
updateSettings(settings) {
|
||||||
if (settings.debug) {
|
if (settings.debug) {
|
||||||
debug = 'console';
|
debug = 'console';
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
debug = '';
|
debug = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -263,8 +260,7 @@ class PlejdService extends EventEmitter {
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
}, 400);
|
}, 400);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this._turnOn(id, brightness);
|
this._turnOn(id, brightness);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -290,6 +286,8 @@ class PlejdService extends EventEmitter {
|
||||||
// we have a transition time, split the target brightness (which will be 0)
|
// we have a transition time, split the target brightness (which will be 0)
|
||||||
// into pieces spread of the transition time
|
// into pieces spread of the transition time
|
||||||
const initialBrightness = this.plejdDevices[id] ? this.plejdDevices[id].dim : 250;
|
const initialBrightness = this.plejdDevices[id] ? this.plejdDevices[id].dim : 250;
|
||||||
|
console.log('initial brightness for ' + id + ' is ' + initialBrightness);
|
||||||
|
|
||||||
const steps = command.transition * 2;
|
const steps = command.transition * 2;
|
||||||
const brightnessStep = initialBrightness / steps;
|
const brightnessStep = initialBrightness / steps;
|
||||||
let currentBrightness = initialBrightness;
|
let currentBrightness = initialBrightness;
|
||||||
|
|
@ -309,8 +307,7 @@ class PlejdService extends EventEmitter {
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this._turnOff(id);
|
this._turnOff(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -337,8 +334,7 @@ class PlejdService extends EventEmitter {
|
||||||
const response = this._createChallengeResponse(this.cryptoKey, Buffer.from(challenge));
|
const response = this._createChallengeResponse(this.cryptoKey, Buffer.from(challenge));
|
||||||
//logger('responding to authenticate');
|
//logger('responding to authenticate');
|
||||||
await this.characteristics.auth.WriteValue([...response], {});
|
await this.characteristics.auth.WriteValue([...response], {});
|
||||||
}
|
} catch (err) {
|
||||||
catch (err) {
|
|
||||||
console.log('plejd-ble: error: failed to authenticate: ' + err);
|
console.log('plejd-ble: error: failed to authenticate: ' + err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -361,8 +357,7 @@ class PlejdService extends EventEmitter {
|
||||||
console.log('plejd-ble: sending ' + data.length + ' byte(s) of data to Plejd');
|
console.log('plejd-ble: sending ' + data.length + ' byte(s) of data to Plejd');
|
||||||
const encryptedData = this._encryptDecrypt(this.cryptoKey, this.plejdService.addr, data);
|
const encryptedData = this._encryptDecrypt(this.cryptoKey, this.plejdService.addr, data);
|
||||||
await this.characteristics.data.WriteValue([...encryptedData], {});
|
await this.characteristics.data.WriteValue([...encryptedData], {});
|
||||||
}
|
} catch (err) {
|
||||||
catch (err) {
|
|
||||||
if (err.message === 'In Progress') {
|
if (err.message === 'In Progress') {
|
||||||
setTimeout(() => this.write(data, retry), 1000);
|
setTimeout(() => this.write(data, retry), 1000);
|
||||||
return;
|
return;
|
||||||
|
|
@ -411,8 +406,7 @@ class PlejdService extends EventEmitter {
|
||||||
try {
|
try {
|
||||||
await this.characteristics.ping.WriteValue([...ping], {});
|
await this.characteristics.ping.WriteValue([...ping], {});
|
||||||
pong = await this.characteristics.ping.ReadValue({});
|
pong = await this.characteristics.ping.ReadValue({});
|
||||||
}
|
} catch (err) {
|
||||||
catch (err) {
|
|
||||||
console.log('error: writing to plejd: ' + err);
|
console.log('error: writing to plejd: ' + err);
|
||||||
this.emit('pingFailed', 'write error');
|
this.emit('pingFailed', 'write error');
|
||||||
return;
|
return;
|
||||||
|
|
@ -476,17 +470,14 @@ class PlejdService extends EventEmitter {
|
||||||
if (chUuid === DATA_UUID) {
|
if (chUuid === DATA_UUID) {
|
||||||
logger('found DATA characteristic.');
|
logger('found DATA characteristic.');
|
||||||
this.characteristics.data = ch;
|
this.characteristics.data = ch;
|
||||||
}
|
} else if (chUuid === LAST_DATA_UUID) {
|
||||||
else if (chUuid === LAST_DATA_UUID) {
|
|
||||||
logger('found LAST_DATA characteristic.');
|
logger('found LAST_DATA characteristic.');
|
||||||
this.characteristics.lastData = ch;
|
this.characteristics.lastData = ch;
|
||||||
this.characteristics.lastDataProperties = prop;
|
this.characteristics.lastDataProperties = prop;
|
||||||
}
|
} else if (chUuid === AUTH_UUID) {
|
||||||
else if (chUuid === AUTH_UUID) {
|
|
||||||
logger('found AUTH characteristic.');
|
logger('found AUTH characteristic.');
|
||||||
this.characteristics.auth = ch;
|
this.characteristics.auth = ch;
|
||||||
}
|
} else if (chUuid === PING_UUID) {
|
||||||
else if (chUuid === PING_UUID) {
|
|
||||||
logger('found PING characteristic.');
|
logger('found PING characteristic.');
|
||||||
this.characteristics.ping = ch;
|
this.characteristics.ping = ch;
|
||||||
}
|
}
|
||||||
|
|
@ -583,23 +574,32 @@ class PlejdService extends EventEmitter {
|
||||||
state = parseInt(decoded.toString('hex', 5, 6), 10);
|
state = parseInt(decoded.toString('hex', 5, 6), 10);
|
||||||
dim = parseInt(decoded.toString('hex', 6, 8), 16) >> 8;
|
dim = parseInt(decoded.toString('hex', 6, 8), 16) >> 8;
|
||||||
|
|
||||||
|
this.plejdDevices[device] = {
|
||||||
|
state: state,
|
||||||
|
dim: dim
|
||||||
|
};
|
||||||
|
|
||||||
logger('d: ' + device + ' got state+dim update: ' + state + ' - ' + dim);
|
logger('d: ' + device + ' got state+dim update: ' + state + ' - ' + dim);
|
||||||
this.emit('stateChanged', device, { state: state, brightness: dim });
|
this.emit('stateChanged', device, {
|
||||||
}
|
state: state,
|
||||||
else if (cmd === BLE_CMD_STATE_CHANGE) {
|
brightness: dim
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
} else if (cmd === BLE_CMD_STATE_CHANGE) {
|
||||||
state = parseInt(decoded.toString('hex', 5, 6), 10);
|
state = parseInt(decoded.toString('hex', 5, 6), 10);
|
||||||
|
|
||||||
logger('d: ' + device + ' got state update: ' + state);
|
logger('d: ' + device + ' got state update: ' + state);
|
||||||
this.emit('stateChanged', device, { state: state });
|
this.emit('stateChanged', device, {
|
||||||
}
|
state: state
|
||||||
else if (cmd === BLE_CMD_SCENE_TRIG) {
|
});
|
||||||
|
} else if (cmd === BLE_CMD_SCENE_TRIG) {
|
||||||
const scene = parseInt(decoded.toString('hex', 5, 6), 10);
|
const scene = parseInt(decoded.toString('hex', 5, 6), 10);
|
||||||
this.emit('sceneTriggered', device, scene);
|
this.emit('sceneTriggered', device, scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.plejdDevices[device] = {
|
this.plejdDevices[device] = {
|
||||||
state: state,
|
state: state
|
||||||
dim: dim
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue