Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental parsing for color temp support from Plejd API #298

Open
wants to merge 4 commits into
base: feature/DWN-dimmable-fix
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions plejd/MqttClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ const getOutputDeviceDiscoveryPayload = (
sw_version: device.version,
},
...(device.type === MQTT_TYPES.LIGHT ? { brightness: device.dimmable, schema: 'json' } : {}),
...(device.type === MQTT_TYPES.LIGHT &&
device.colorTempSettings &&
device.colorTempSettings.behavior === 'adjustable'
? {
color_mode: true,
min_mireds: 1000000 / device.colorTempSettings.minTemperatureLimit,
max_mireds: 1000000 / device.colorTempSettings.maxTemperatureLimit,
supported_color_modes: ['color_temp'],
}
: {}),
});

const getSceneDiscoveryPayload = (
Expand Down Expand Up @@ -321,9 +331,6 @@ class MqttClient extends EventEmitter {
`Sent discovery message for ${outputDevice.typeName} (${outputDevice.type}) named ${outputDevice.name} (${outputDevice.bleOutputAddress} : ${outputDevice.uniqueId}).`,
);




// -------- CLEANUP RETAINED MESSAGES FOR OUTPUT DEVICES -------------

logger.debug(
Expand Down Expand Up @@ -354,7 +361,6 @@ class MqttClient extends EventEmitter {

logger.debug(`Removal messages sent for ${outputDevice.name}`);


logger.debug(`Setting device as AVAILABILITY = ONLINE: ${outputDevice.name}`);

this.client.publish(
Expand Down Expand Up @@ -441,8 +447,6 @@ class MqttClient extends EventEmitter {
);
});



// -------- SUBSCRIBE TO INCOMING MESSAGES -------------

this.client.subscribe(
Expand Down
22 changes: 17 additions & 5 deletions plejd/PlejdApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ const API_SITE_LIST_URL = 'functions/getSiteList';
const API_SITE_DETAILS_URL = 'functions/getSiteById';

const TRAITS = {
NO_LOAD: 0, // 0b0000
NON_DIMMABLE: 9, // 0b1001
DIMMABLE: 11, // 0b1011
DIMMABLE_COLORTEMP: 15, // 0b1111
NO_LOAD: 0, // 0b0000
NON_DIMMABLE: 9, // 0b1001
DIMMABLE: 11, // 0b1011
DIMMABLE_COLORTEMP: 15, // 0b1111
};

const logger = Logger.getLogger('plejd-api');
Expand Down Expand Up @@ -339,8 +339,10 @@ class PlejdApi {
description: 'Dali broadcast with dimmer and tuneable white support',
type: 'light',
dimmable: true,
colorTemp: true,
broadcastClicks: false,
};
// 13: Non-dimmable generic light
case 14:
return {
name: 'DIM-01',
Expand Down Expand Up @@ -388,6 +390,7 @@ class PlejdApi {
description: '1-channel LED dimmer/driver with tuneable white, 10 W',
type: 'light',
dimmable: true,
colorTemp: true,
broadcastClicks: false,
};
case 167:
Expand All @@ -396,6 +399,7 @@ class PlejdApi {
description: 'Smart tunable downlight with a built-in dimmer function, 8W',
type: 'light',
dimmable: true,
colorTemp: true,
broadcastClicks: false,
};
case 199:
Expand All @@ -404,6 +408,7 @@ class PlejdApi {
description: 'Smart tunable downlight with a built-in dimmer function, 8W',
type: 'light',
dimmable: true,
colorTemp: true,
broadcastClicks: false,
};
// PLEASE CREATE AN ISSUE WITH THE HARDWARE ID if you own one of these devices!
Expand Down Expand Up @@ -481,7 +486,10 @@ class PlejdApi {
// 2. outputSettings.dimCurve NOT IN ["NonDimmable", "RelayNormal"]: Dimmable
// 3. outputSettings.predefinedLoad !== null && outputSettings.predefinedLoad.loadType === "DWN": Dimmable

const colorTemp = outputSettings.colorTemperature?.behavior === 'adjustable';
const colorTemp =
outputSettings &&
outputSettings.colorTemperature &&
outputSettings.colorTemperature.behavior === 'adjustable';

try {
const decodedDeviceType = this._getDeviceType(plejdDevice);
Expand All @@ -499,6 +507,8 @@ class PlejdApi {
/** @type {import('types/DeviceRegistry').OutputDevice} */
const outputDevice = {
bleOutputAddress,
colorTemp,
colorTempSettings: outputSettings ? outputSettings.colorTemperature : null,
deviceId: device.deviceId,
dimmable,
name: device.title,
Expand Down Expand Up @@ -604,6 +614,7 @@ class PlejdApi {
const newDevice = {
bleOutputAddress: roomAddress,
deviceId: null,
colorTemp: false,
dimmable,
name: room.title,
output: undefined,
Expand Down Expand Up @@ -633,6 +644,7 @@ class PlejdApi {
/** @type {import('types/DeviceRegistry').OutputDevice} */
const newScene = {
bleOutputAddress: sceneNum,
colorTemp: false,
deviceId: undefined,
dimmable: false,
name: scene.title,
Expand Down
11 changes: 11 additions & 0 deletions plejd/types/ApiSite.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export interface OutputSetting {
deviceParseId: string;
siteId: string;
predefinedLoad: OutputSettingPredefinedLoad;
colorTemperature: OutputSettingColorTemperature;
createdAt: Date;
updatedAt: Date;
dimMin: number;
Expand Down Expand Up @@ -322,6 +323,16 @@ export interface OutputSettingPredefinedLoad {
filters?: Filters;
}

export interface OutputSettingColorTemperature {
"minTemperature": number,
"maxTemperature": number,
"slewRate": number,
"minTemperatureLimit": number,
"maxTemperatureLimit": number,
"behavior": "adjustable" | "UNKNOWN", // Todo: Fill with alternate values after finding more site jsons. UNKNOWN is placeholder for now.
"startTemperature": number
}

export interface PredefinedLoadACL {
'*': Empty;
}
Expand Down
4 changes: 4 additions & 0 deletions plejd/types/DeviceRegistry.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/* eslint-disable no-use-before-define */

import { OutputSettingColorTemperature } from "./ApiSite";

export type OutputDevices = { [deviceIdAndOutput: string]: OutputDevice };

export interface OutputDevice {
bleOutputAddress: number;
colorTemp: boolean;
colorTempSettings?: OutputSettingColorTemperature
deviceId: string;
dim?: number;
dimmable: boolean;
Expand Down