-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default generated names are consist of the model name and the device ID so it's easier to recognize them then adding new devices. Additionally this commit does: - Drop deprecated `updateReachability` and don't rely on it for initi phase - Use constructor to init accessories - Use object as a first argument so we can pass all props to classes - Use better function names
- Loading branch information
Showing
7 changed files
with
287 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,58 @@ | ||
const Brightness = ({ bright: b }) => Device => class extends Device { | ||
constructor(did, model, platform) { | ||
super(did, model, platform); | ||
this.bright = b; | ||
} | ||
const Brightness = ({ bright: b }) => Device => | ||
class extends Device { | ||
constructor(props, platform) { | ||
super(props, platform); | ||
this.bright = b; | ||
|
||
get bright() { | ||
return this._bright; | ||
} | ||
|
||
set bright(bright) { | ||
this._bright = Number(bright); | ||
} | ||
( | ||
this.service.getCharacteristic(global.Characteristic.Brightness) || | ||
this.service.addCharacteristic(global.Characteristic.Brightness) | ||
) | ||
.on('set', async (value, callback) => { | ||
try { | ||
await this.setBrightness(value); | ||
callback(null, value); | ||
} catch (err) { | ||
callback(err, this.bright); | ||
} | ||
}) | ||
.updateValue(this.bright); | ||
} | ||
|
||
setBrightness(brightness) { | ||
const { brightness: transition = 400 } = this.config.transitions || {}; | ||
const req = { | ||
method: 'set_bright', | ||
params: [ | ||
Math.max(brightness, 1), | ||
'smooth', | ||
transition, | ||
], | ||
}; | ||
return this.sendCmd(req).then(() => { this._bright = brightness; }); | ||
} | ||
get bright() { | ||
return this._bright; | ||
} | ||
|
||
updateStateFromProp(prop, value) { | ||
// There are different props being used for brightness | ||
// depending on the active_mode in Ceiling lamps | ||
if ( | ||
(this.activeMode === 0 && prop === 'bright') | ||
|| (this.activeMode === 1 && prop === 'nl_br') | ||
) { | ||
this.bright = value; | ||
this.service | ||
.getCharacteristic(global.Characteristic.Brightness) | ||
.updateValue(this.bright); | ||
return; | ||
set bright(bright) { | ||
this._bright = Number(bright); | ||
} | ||
super.updateStateFromProp(prop, value); | ||
} | ||
|
||
configureServices() { | ||
super.configureServices(); | ||
setBrightness(brightness) { | ||
const { brightness: transition = 400 } = this.config.transitions || {}; | ||
const req = { | ||
method: 'set_bright', | ||
params: [Math.max(brightness, 1), 'smooth', transition], | ||
}; | ||
return this.sendCmd(req).then(() => { | ||
this._bright = brightness; | ||
}); | ||
} | ||
|
||
(this.service.getCharacteristic(global.Characteristic.Brightness) | ||
|| this.service.addCharacteristic(global.Characteristic.Brightness)) | ||
.on('set', async (value, callback) => { | ||
try { | ||
await this.setBrightness(value); | ||
callback(null, value); | ||
} catch (err) { | ||
callback(err, this.bright); | ||
} | ||
}).updateValue(this.bright); | ||
} | ||
}; | ||
updateStateFromProp(prop, value) { | ||
// There are different props being used for brightness | ||
// depending on the active_mode in Ceiling lamps | ||
if ( | ||
(this.activeMode === 0 && prop === 'bright') || | ||
(this.activeMode === 1 && prop === 'nl_br') | ||
) { | ||
this.bright = value; | ||
this.service | ||
.getCharacteristic(global.Characteristic.Brightness) | ||
.updateValue(this.bright); | ||
return; | ||
} | ||
super.updateStateFromProp(prop, value); | ||
} | ||
}; | ||
|
||
module.exports = Brightness; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.