Skip to content

Commit

Permalink
Adaptive Lightning manual mode WIP, update event output
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaquu committed Jun 22, 2024
1 parent bd712d8 commit 271d027
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build/nodes/service.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
<select id="node-input-adaptiveLightingOptionsMode">
<option value="" selected hidden disabled>AUTOMATIC</option>
<option value="1">AUTOMATIC</option>
<option value="2" disabled>MANUAL</option>
<option value="2">MANUAL</option>
</select>
</div>
<div class="form-row">
Expand Down
2 changes: 1 addition & 1 deletion build/nodes/service2.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
<select id="node-input-adaptiveLightingOptionsMode">
<option value="" selected hidden disabled>AUTOMATIC</option>
<option value="1">AUTOMATIC</option>
<option value="2" disabled>MANUAL</option>
<option value="2">MANUAL</option>
</select>
</div>
<div class="form-row">
Expand Down
2 changes: 2 additions & 0 deletions src/lib/types/HAPServiceNodeType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Accessory,
AdaptiveLightingController,
Characteristic,
CharacteristicChange,
CharacteristicGetCallback,
Expand Down Expand Up @@ -56,6 +57,7 @@ type HAPServiceNodeType = NodeType & {
// Is Accessory reachable? On Linked Service it will be undefined. If is not true then NO_RESPONSE
reachable?: boolean
nodeStatusUtils: NodeStatusUtils
adaptiveLightingController?: AdaptiveLightingController
}

export default HAPServiceNodeType
49 changes: 48 additions & 1 deletion src/lib/utils/ServiceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as util from 'node:util'
import { logger } from '@nrchkb/logger'
import {
Accessory,
ActiveAdaptiveLightingTransition,
AdaptiveLightingController,
AdaptiveLightingControllerMode,
AdaptiveLightingOptions,
Expand Down Expand Up @@ -32,7 +33,7 @@ module.exports = function (node: HAPServiceNodeType) {

const NO_RESPONSE_MSG = 'NO_RESPONSE'

const prepareHapData = (context: any, connection?: HAPConnection) => {
const prepareHapData = (context?: any, connection?: HAPConnection) => {
const hap: { [key: string]: any } = {}

if (connection) {
Expand Down Expand Up @@ -262,6 +263,15 @@ module.exports = function (node: HAPServiceNodeType) {

Object.keys(msg.payload).map((key: string) => {
if (node.supported.indexOf(key) < 0) {
if (key === 'AdaptiveLightingController') {
const value = msg.payload?.[key]
const event = value?.event

if (event === 'disable') {
node.adaptiveLightingController?.disableAdaptiveLighting()
}
}

log.error(
`Instead of '${key}' try one of these characteristics: '${node.supported.join(
"', '"
Expand Down Expand Up @@ -500,7 +510,44 @@ module.exports = function (node: HAPServiceNodeType) {
const adaptiveLightingController =
new AdaptiveLightingController(node.service, options)

adaptiveLightingController.on('update', () => {
const activeAdaptiveLightingTransition: Partial<ActiveAdaptiveLightingTransition> =
{
transitionStartMillis:
adaptiveLightingController.getAdaptiveLightingStartTimeOfTransition(),
timeMillisOffset:
adaptiveLightingController.getAdaptiveLightingTimeOffset(),
transitionCurve:
adaptiveLightingController.getAdaptiveLightingTransitionCurve(),
brightnessAdjustmentRange:
adaptiveLightingController.getAdaptiveLightingBrightnessMultiplierRange(),
updateInterval:
adaptiveLightingController.getAdaptiveLightingUpdateInterval(),
notifyIntervalThreshold:
adaptiveLightingController.getAdaptiveLightingNotifyIntervalThreshold(),
}
node.send({
payload: {
AdaptiveLightingController: {
event: 'update',
data: activeAdaptiveLightingTransition,
},
},
})
})
adaptiveLightingController.on('disable', () => {
node.send({
payload: {
AdaptiveLightingController: {
event: 'disable',
},
},
})
})

node.accessory.configureController(adaptiveLightingController)

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

0 comments on commit 271d027

Please sign in to comment.