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

ZwaveJS scene controller #2178

Merged
Merged
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
34 changes: 34 additions & 0 deletions server/services/zwavejs-ui/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {
DEVICE_FEATURE_TYPES,
OPENING_SENSOR_STATE,
STATE,
BUTTON_STATUS,
COVER_STATE,
DEVICE_FEATURE_UNITS,
} = require('../../../utils/constants');
Expand Down Expand Up @@ -47,6 +48,28 @@ const STATES = {
},
],
},
central_scene: {
scene: [
{
converter: (val) => {
switch (val) {
case 0:
return BUTTON_STATUS.CLICK;
case 1:
return BUTTON_STATUS.RELEASE;
case 2:
return BUTTON_STATUS.HOLD_CLICK;
case 3:
return BUTTON_STATUS.DOUBLE_CLICK;
case 4:
return BUTTON_STATUS.TRIPLE;
default:
return null;
}
},
},
],
},
multilevel_sensor: {
air_temperature: [{ converter: (val) => val }],
power: [{ converter: (val) => val }],
Expand Down Expand Up @@ -263,6 +286,17 @@ const EXPOSES = {
has_feedback: false,
},
},
central_scene: {
scene: {
category: DEVICE_FEATURE_CATEGORIES.BUTTON,
type: DEVICE_FEATURE_TYPES.BUTTON.CLICK,
min: 0,
max: 4,
keep_history: false,
read_only: true,
has_feedback: true,
},
},
multilevel_sensor: {
air_temperature: {
category: DEVICE_FEATURE_CATEGORIES.TEMPERATURE_SENSOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function onNodeValueUpdated(message) {
// A value has been updated: https://zwave-js.github.io/node-zwave-js/#/api/node?id=quotvalue-addedquot-quotvalue-updatedquot-quotvalue-removedquot
const messageNode = message.data[0];
const updatedValue = message.data[1];
const { commandClassName, propertyName, propertyKeyName, endpoint, newValue } = updatedValue;
const { commandClassName, propertyName, propertyKeyName, endpoint = 0, newValue } = updatedValue;

const nodeId = `zwavejs-ui:${messageNode.id}`;
const node = this.getDevice(nodeId);
Expand All @@ -27,7 +27,9 @@ function onNodeValueUpdated(message) {
return Promise.resolve();
}

const valueConverters = getProperty(STATES, commandClassName, propertyName, propertyKeyName, zwaveJSNode.deviceClass);
const valueConverters =
getProperty(STATES, commandClassName, propertyName, propertyKeyName, zwaveJSNode.deviceClass) ||
getProperty(STATES, commandClassName, propertyName, '', zwaveJSNode.deviceClass);

if (!valueConverters) {
return Promise.resolve();
Expand Down
46 changes: 28 additions & 18 deletions server/services/zwavejs-ui/utils/convertToGladysDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,19 @@ const convertToGladysDevice = (serviceId, zwaveJsDevice) => {
// Foreach value, we check if there is a matching feature in Gladys
Object.keys(zwaveJsDevice.values).forEach((valueKey) => {
const value = zwaveJsDevice.values[valueKey];
const { commandClass, commandClassName, propertyName, propertyKeyName, endpoint, commandClassVersion = 1 } = value;
const {
commandClass,
commandClassName,
propertyName,
propertyKeyName,
endpoint = 0,
commandClassVersion = 1,
} = value;

let exposes = getProperty(EXPOSES, commandClassName, propertyName, propertyKeyName, zwaveJsDevice.deviceClass);
let exposes =
getProperty(EXPOSES, commandClassName, propertyName, propertyKeyName, zwaveJsDevice.deviceClass) ||
// We try to get a higher EXPOSEd node (to handle Scene Controllers for example).
getProperty(EXPOSES, commandClassName, propertyName, '', zwaveJsDevice.deviceClass);
if (exposes) {
if (!Array.isArray(exposes)) {
exposes = [
Expand All @@ -60,25 +70,25 @@ const convertToGladysDevice = (serviceId, zwaveJsDevice) => {
}

exposes.forEach((exposeFound) => {
// Let's check we effectively found a valid EXPOSE and not
// just a higher node
if (!exposeFound.feature.category) {
return;
}
const deviceFeatureId = getDeviceFeatureId(
zwaveJsDevice.id,
commandClassName,
endpoint,
propertyName,
propertyKeyName,
exposeFound.name,
);

features.push({
...exposeFound.feature,
name: `${value.id}${exposeFound.name !== '' ? `:${exposeFound.name}` : ''}`,
external_id: getDeviceFeatureId(
zwaveJsDevice.id,
commandClassName,
endpoint,
propertyName,
propertyKeyName,
exposeFound.name,
),
selector: getDeviceFeatureId(
zwaveJsDevice.id,
commandClassName,
endpoint,
propertyName,
propertyKeyName,
exposeFound.name,
),
external_id: deviceFeatureId,
selector: deviceFeatureId,
node_id: zwaveJsDevice.id,
// These are custom properties only available on the object in memory (not in DB)
command_class_version: commandClassVersion,
Expand Down
Loading
Loading