Skip to content

Commit

Permalink
Fixed Adaptive Lightning
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaquu committed Jun 20, 2024
1 parent 348011e commit aa625f9
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 43 deletions.
12 changes: 7 additions & 5 deletions build/nodes/service.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@
<div class="form-row">
<label for="node-input-adaptiveLightingOptionsMode"><i class="fa fa-hand-o-up"></i> Mode</label>
<select id="node-input-adaptiveLightingOptionsMode">
<option value="0" selected="selected">AUTOMATIC</option>
<option value="1" disabled>MANUAL</option>
<option value="1" selected="selected">AUTOMATIC</option>
<option value="2" disabled>MANUAL</option>
</select>
</div>
<div class="form-row">
<label for="node-input-adaptiveLightingOptionsCustomTemperatureAdjustment"><i class="fa fa-thermometer-quarter"></i> Custom Temperature Adjustment</label>
<input type="text" id="node-input-adaptiveLightingOptionsCustomTemperatureAdjustment">
<input type="number" id="node-input-adaptiveLightingOptionsCustomTemperatureAdjustment">
</div>
</div>

Expand Down Expand Up @@ -498,10 +498,12 @@ <h2 id="toc_8">Characteristic Properties</h2>
value: false,
},
adaptiveLightingOptionsMode: {
value: 0,
value: 1,
validate: RED.validators.number()
},
adaptiveLightingOptionsCustomTemperatureAdjustment: {
value: undefined,
value: 0,
validate: RED.validators.number()
},
},
inputs: 1,
Expand Down
12 changes: 7 additions & 5 deletions build/nodes/service2.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@
<div class="form-row">
<label for="node-input-adaptiveLightingOptionsMode"><i class="fa fa-hand-o-up"></i> Mode</label>
<select id="node-input-adaptiveLightingOptionsMode">
<option value="0" selected="selected">AUTOMATIC</option>
<option value="1" disabled>MANUAL</option>
<option value="1" selected="selected">AUTOMATIC</option>
<option value="2" disabled>MANUAL</option>
</select>
</div>
<div class="form-row">
<label for="node-input-adaptiveLightingOptionsCustomTemperatureAdjustment"><i class="fa fa-thermometer-quarter"></i> Custom Temperature Adjustment</label>
<input type="text" id="node-input-adaptiveLightingOptionsCustomTemperatureAdjustment">
<input type="number" id="node-input-adaptiveLightingOptionsCustomTemperatureAdjustment">
</div>
</div>

Expand Down Expand Up @@ -508,10 +508,12 @@ <h2 id="toc_8">Characteristic Properties</h2>
value: false,
},
adaptiveLightingOptionsMode: {
value: 0,
value: 1,
validate: RED.validators.number()
},
adaptiveLightingOptionsCustomTemperatureAdjustment: {
value: undefined,
value: 0,
validate: RED.validators.number()
},
},
inputs: 1,
Expand Down
44 changes: 23 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-homekit-bridged",
"version": "1.7.0-dev.2",
"version": "1.7.0-dev.3",
"description": "Node-RED nodes to simulate Apple HomeKit devices.",
"main": "build/nodes/nrchkb.js",
"scripts": {
Expand Down Expand Up @@ -42,7 +42,7 @@
},
"homepage": "https://github.com/NRCHKB/node-red-contrib-homekit-bridged#readme",
"dependencies": {
"@nrchkb/logger": "^2.0.2",
"@nrchkb/logger": "^3.0.0",
"hap-nodejs": "0.12.2",
"node-persist": "^4.0.1",
"semver": "^7.6.2",
Expand Down
32 changes: 22 additions & 10 deletions src/lib/utils/ServiceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Accessory,
AdaptiveLightingController,
AdaptiveLightingControllerMode,
AdaptiveLightingOptions,
Characteristic,
CharacteristicChange,
CharacteristicGetCallback,
Expand Down Expand Up @@ -474,24 +475,35 @@ module.exports = function (node: HAPServiceNodeType) {

const configureAdaptiveLightning = () => {
if (
node.service.name === 'Lightbulb' &&
node.service.UUID === Service.Lightbulb.UUID &&
node.config.adaptiveLightingOptionsEnable
) {
try {
node.service.getCharacteristic(Characteristic.Brightness)
node.service.getCharacteristic(Characteristic.ColorTemperature)

const options: AdaptiveLightingOptions = {
controllerMode: node.config.adaptiveLightingOptionsMode
? +node.config.adaptiveLightingOptionsMode
: AdaptiveLightingControllerMode.AUTOMATIC,
customTemperatureAdjustment: node.config
.adaptiveLightingOptionsCustomTemperatureAdjustment
? +node.config
.adaptiveLightingOptionsCustomTemperatureAdjustment
: undefined,
}

log.trace(
`Configuring Adaptive Lighting with options: ${options}`
)

const adaptiveLightingController =
new AdaptiveLightingController(node.service, {
controllerMode:
node.config.adaptiveLightingOptionsMode ??
AdaptiveLightingControllerMode.AUTOMATIC,
customTemperatureAdjustment:
node.config
.adaptiveLightingOptionsCustomTemperatureAdjustment,
})
new AdaptiveLightingController(node.service, options)

node.accessory.configureController(adaptiveLightingController)
} catch (error) {
log.error(
`Failed to configure adaptive lightning due to ${error}`
`Failed to configure Adaptive Lightning due to ${error}`
)
}
}
Expand Down

0 comments on commit aa625f9

Please sign in to comment.