0.17.0 release - improve startup and fix color temp (#324)
* Add working support for color temperature * Lint fixes * Fix to config json version to make it build * Clean up and BLE constants and prepare for lightlevel UUID * Eagerly send HA discovery, standardize colorTemp, clean up MQTT subscribe * Fix typo in MqttClient * Listen to HA birth messages to make devices available after HA restart - Extract constants to common file * Prepare for 0.17.0 release
This commit is contained in:
parent
d801410200
commit
1766afb2e0
14 changed files with 650 additions and 165 deletions
2
plejd/types/DeviceRegistry.d.ts
vendored
2
plejd/types/DeviceRegistry.d.ts
vendored
|
|
@ -6,7 +6,7 @@ export type OutputDevices = { [deviceIdAndOutput: string]: OutputDevice };
|
|||
|
||||
export interface OutputDevice {
|
||||
bleOutputAddress: number;
|
||||
colorTemp: boolean;
|
||||
colorTemp: number?;
|
||||
colorTempSettings?: OutputSettingColorTemperature
|
||||
deviceId: string;
|
||||
dim?: number;
|
||||
|
|
|
|||
2
plejd/types/Mqtt.d.ts
vendored
2
plejd/types/Mqtt.d.ts
vendored
|
|
@ -3,5 +3,5 @@
|
|||
export type TopicType = 'config' | 'state' | 'availability' | 'set';
|
||||
export type TOPIC_TYPES = { [key: string]: TopicType };
|
||||
|
||||
export type MqttType = 'light' | 'scene' | 'switch' | 'device_automation';
|
||||
export type MqttType = 'light' | 'scene' | 'switch' | 'device_automation' | 'sensor' | 'extender';
|
||||
export type MQTT_TYPES = { [key: string]: MqttType };
|
||||
|
|
|
|||
118
plejd/types/constants.d.ts
vendored
Normal file
118
plejd/types/constants.d.ts
vendored
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
import { MqttType, TopicType } from './Mqtt';
|
||||
|
||||
export interface MqttTypes {
|
||||
LIGHT: MqttType;
|
||||
SCENE: MqttType;
|
||||
SWITCH: MqttType;
|
||||
DEVICE_AUTOMATION: MqttType;
|
||||
SENSOR: MqttType;
|
||||
EXTENDER: MqttType;
|
||||
}
|
||||
|
||||
export interface TopicTypes {
|
||||
CONFIG: TopicType;
|
||||
STATE: TopicType;
|
||||
AVAILABILITY: TopicType;
|
||||
SET: TopicType;
|
||||
}
|
||||
|
||||
export interface MqttState {
|
||||
ON: 'ON';
|
||||
OFF: 'OFF';
|
||||
}
|
||||
|
||||
export interface DeviceTypes {
|
||||
SCENE: 'Scene';
|
||||
LIGHT: 'light';
|
||||
SWITCH: 'switch';
|
||||
SENSOR: 'sensor';
|
||||
EXTENDER: 'extender';
|
||||
}
|
||||
|
||||
export interface OutputTypes {
|
||||
LIGHT: 'LIGHT';
|
||||
}
|
||||
|
||||
export interface SceneStates {
|
||||
ON: 'On';
|
||||
OFF: 'Off';
|
||||
}
|
||||
|
||||
export interface Availability {
|
||||
ONLINE: 'online';
|
||||
OFFLINE: 'offline';
|
||||
}
|
||||
|
||||
export interface AutomationTypes {
|
||||
TRIGGER: 'trigger';
|
||||
BUTTON_SHORT_PRESS: 'button_short_press';
|
||||
}
|
||||
|
||||
export interface BluezIds {
|
||||
SERVICE_NAME: 'org.bluez';
|
||||
ADAPTER_ID: 'org.bluez.Adapter1';
|
||||
DEVICE_ID: 'org.bluez.Device1';
|
||||
GATT_SERVICE_ID: 'org.bluez.GattService1';
|
||||
GATT_CHAR_ID: 'org.bluez.GattCharacteristic1';
|
||||
}
|
||||
|
||||
export interface DbusInterface {
|
||||
OM_INTERFACE: 'org.freedesktop.DBus.ObjectManager';
|
||||
PROP_INTERFACE: 'org.freedesktop.DBus.Properties';
|
||||
}
|
||||
|
||||
export interface ApiEndpoints {
|
||||
APP_ID: string;
|
||||
BASE_URL: string;
|
||||
LOGIN_URL: string;
|
||||
SITE_LIST_URL: string;
|
||||
SITE_DETAILS_URL: string;
|
||||
}
|
||||
|
||||
export interface BleCommands {
|
||||
REMOTE_CLICK: number;
|
||||
TIME_UPDATE: number;
|
||||
SCENE_TRIGGER: number;
|
||||
STATE_CHANGE: number;
|
||||
DIM_CHANGE: number;
|
||||
COLOR_CHANGE: number;
|
||||
}
|
||||
|
||||
export interface Ble {
|
||||
UUID_SUFFIX: string;
|
||||
COMMANDS: BleCommands;
|
||||
BROADCAST_DEVICE_ID: number;
|
||||
}
|
||||
|
||||
export interface PlejdUuids {
|
||||
PLEJD_SERVICE: string;
|
||||
LIGHTLEVEL_UUID: string;
|
||||
DATA_UUID: string;
|
||||
LAST_DATA_UUID: string;
|
||||
AUTH_UUID: string;
|
||||
PING_UUID: string;
|
||||
}
|
||||
|
||||
export interface Commands {
|
||||
TURN_ON: string;
|
||||
TURN_OFF: string;
|
||||
DIM: string;
|
||||
COLOR: string;
|
||||
TRIGGER_SCENE: string;
|
||||
BUTTON_CLICK: string;
|
||||
}
|
||||
|
||||
export const MQTT_TYPES: MqttTypes;
|
||||
export const TOPIC_TYPES: TopicTypes;
|
||||
export const MQTT_STATE: MqttState;
|
||||
export const DEVICE_TYPES: DeviceTypes;
|
||||
export const AVAILABILITY: Availability;
|
||||
export const AUTOMATION_TYPES: AutomationTypes;
|
||||
export const BLE: Ble;
|
||||
export const PLEJD_UUIDS: PlejdUuids;
|
||||
export const COMMANDS: Commands;
|
||||
export const OUTPUT_TYPES: OutputTypes;
|
||||
export const SCENE_STATES: SceneStates;
|
||||
export const BLUEZ: BluezIds;
|
||||
export const DBUS: DbusInterface;
|
||||
export const API: ApiEndpoints;
|
||||
121
plejd/types/constants.js
Normal file
121
plejd/types/constants.js
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
/** @type {import('./Mqtt').MQTT_TYPES} */
|
||||
const MQTT_TYPES = {
|
||||
LIGHT: 'light',
|
||||
SCENE: 'scene',
|
||||
SWITCH: 'switch',
|
||||
DEVICE_AUTOMATION: 'device_automation',
|
||||
SENSOR: 'sensor',
|
||||
EXTENDER: 'extender',
|
||||
};
|
||||
|
||||
/** @type {import('./Mqtt').TOPIC_TYPES} */
|
||||
const TOPIC_TYPES = {
|
||||
CONFIG: 'config',
|
||||
STATE: 'state',
|
||||
AVAILABILITY: 'availability',
|
||||
SET: 'set',
|
||||
};
|
||||
|
||||
const MQTT_STATE = {
|
||||
ON: 'ON',
|
||||
OFF: 'OFF',
|
||||
};
|
||||
|
||||
const DEVICE_TYPES = {
|
||||
SCENE: 'scene',
|
||||
LIGHT: 'light',
|
||||
SWITCH: 'switch',
|
||||
SENSOR: 'sensor',
|
||||
EXTENDER: 'extender',
|
||||
};
|
||||
|
||||
const OUTPUT_TYPES = {
|
||||
LIGHT: 'LIGHT',
|
||||
};
|
||||
|
||||
const SCENE_STATES = {
|
||||
ON: 'On',
|
||||
OFF: 'Off',
|
||||
};
|
||||
|
||||
const AVAILABILITY = {
|
||||
ONLINE: 'online',
|
||||
OFFLINE: 'offline',
|
||||
};
|
||||
|
||||
const AUTOMATION_TYPES = {
|
||||
TRIGGER: 'trigger',
|
||||
BUTTON_SHORT_PRESS: 'button_short_press',
|
||||
};
|
||||
|
||||
const BLUEZ = {
|
||||
SERVICE_NAME: 'org.bluez',
|
||||
ADAPTER_ID: 'org.bluez.Adapter1',
|
||||
DEVICE_ID: 'org.bluez.Device1',
|
||||
GATT_SERVICE_ID: 'org.bluez.GattService1',
|
||||
GATT_CHAR_ID: 'org.bluez.GattCharacteristic1',
|
||||
};
|
||||
|
||||
const DBUS = {
|
||||
OM_INTERFACE: 'org.freedesktop.DBus.ObjectManager',
|
||||
PROP_INTERFACE: 'org.freedesktop.DBus.Properties',
|
||||
};
|
||||
|
||||
const API = {
|
||||
APP_ID: 'zHtVqXt8k4yFyk2QGmgp48D9xZr2G94xWYnF4dak',
|
||||
BASE_URL: 'https://cloud.plejd.com/parse/',
|
||||
LOGIN_URL: 'login',
|
||||
SITE_LIST_URL: 'functions/getSiteList',
|
||||
SITE_DETAILS_URL: 'functions/getSiteById',
|
||||
};
|
||||
|
||||
// BLE Protocol Constants
|
||||
const BLE = {
|
||||
UUID_SUFFIX: '6085-4726-be45-040c957391b5',
|
||||
COMMANDS: {
|
||||
REMOTE_CLICK: 0x0016,
|
||||
TIME_UPDATE: 0x001b,
|
||||
SCENE_TRIGGER: 0x0021,
|
||||
STATE_CHANGE: 0x0097,
|
||||
DIM_CHANGE: 0x00c8,
|
||||
COLOR_CHANGE: 0x0420,
|
||||
},
|
||||
BROADCAST_DEVICE_ID: 0x01,
|
||||
};
|
||||
|
||||
// Generate UUIDs
|
||||
const PLEJD_UUIDS = {
|
||||
PLEJD_SERVICE: `31ba0001-${BLE.UUID_SUFFIX}`,
|
||||
LIGHTLEVEL_UUID: `31ba0003-${BLE.UUID_SUFFIX}`,
|
||||
DATA_UUID: `31ba0004-${BLE.UUID_SUFFIX}`,
|
||||
LAST_DATA_UUID: `31ba0005-${BLE.UUID_SUFFIX}`,
|
||||
AUTH_UUID: `31ba0009-${BLE.UUID_SUFFIX}`,
|
||||
PING_UUID: `31ba000a-${BLE.UUID_SUFFIX}`,
|
||||
};
|
||||
|
||||
// Commands from original constants.js
|
||||
const COMMANDS = {
|
||||
TURN_ON: 'Turn on',
|
||||
TURN_OFF: 'Turn off',
|
||||
DIM: 'Dim',
|
||||
COLOR: 'Color',
|
||||
TRIGGER_SCENE: 'Trigger scene',
|
||||
BUTTON_CLICK: 'Button click',
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
MQTT_TYPES,
|
||||
TOPIC_TYPES,
|
||||
MQTT_STATE,
|
||||
DEVICE_TYPES,
|
||||
AVAILABILITY,
|
||||
AUTOMATION_TYPES,
|
||||
BLE,
|
||||
PLEJD_UUIDS,
|
||||
COMMANDS,
|
||||
OUTPUT_TYPES,
|
||||
SCENE_STATES,
|
||||
BLUEZ,
|
||||
DBUS,
|
||||
API,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue