Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.whizzosoftware.wzwave.commandclass;

import com.whizzosoftware.wzwave.node.NodeContext;
import com.whizzosoftware.wzwave.util.ByteUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CentralSceneCommandClass extends CommandClass {
private final Logger logger = LoggerFactory.getLogger(getClass());

public static final byte ID = 0x5B;
public static final byte CENTRAL_SCENE_NOTIFICATION = 0x03;

private Integer sequenceNumber;
private Integer sceneNumber;
private SceneCommand sceneCommand;
private Integer pushCount;
private Boolean slowRefresh;

@Override
public byte getId() {
return ID;
}

@Override
public String getName() {
return "COMMAND_CLASS_CENTRAL_SCENE";
}

@Override
public void onApplicationCommand(NodeContext context, byte[] ccb, int startIndex) {
if(ccb[startIndex + 1] != CENTRAL_SCENE_NOTIFICATION) {
logger.warn("Ignoring unsupported command: {}", ByteUtil.createString(ccb[startIndex + 1]));
return;
}
switch(getVersion()) {
case 3:
slowRefresh = (ccb[startIndex + 3] & 0x80) == 0x80;
case 1:
case 2:
sequenceNumber = (int) ccb[startIndex + 2];
sceneNumber = (int) ccb[startIndex + 4];
int attributes = ccb[3] & 0x07;
switch(attributes) {
case 0x01:
sceneCommand = SceneCommand.RELEASED_AFTER_HOLD;
pushCount = null;
break;
case 0x02:
sceneCommand = SceneCommand.BEING_HELD;
pushCount = null;
break;
default:
sceneCommand = SceneCommand.PUSHED;
pushCount = attributes == 0x00 ? 1 : attributes - 1;
break;
}
}
}

@Override
public int queueStartupMessages(NodeContext context, byte nodeId) {
return 0;
}

public Integer getSequenceNumber() {
return sequenceNumber;
}

public Integer getSceneNumber() {
return sceneNumber;
}

public SceneCommand getSceneCommand() {
return sceneCommand;
}

public Integer getPushCount() {
return pushCount;
}

public Boolean getSlowRefresh() {
return slowRefresh;
}

public enum SceneCommand {
PUSHED, BEING_HELD, RELEASED_AFTER_HOLD
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ public static ZWaveNode createNode(NodeInfo info, boolean listening, NodeListene
}
}

case PortableSceneController.ID: {
switch (info.getSpecificDeviceClass()) {
default:
return new PortableSceneController(info, listening, listener);
}
}

default:
throw new NodeCreationException("Unable to create node " + info.getNodeId() + " due to unknown generic device class: " + ByteUtil.createString(info.getGenericDeviceClass()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
*******************************************************************************
* Copyright (c) 2013 Whizzo Software, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************
*/
package com.whizzosoftware.wzwave.node.generic;

import com.whizzosoftware.wzwave.commandclass.*;
import com.whizzosoftware.wzwave.node.NodeInfo;
import com.whizzosoftware.wzwave.node.NodeListener;
import com.whizzosoftware.wzwave.node.ZWaveNode;
import com.whizzosoftware.wzwave.persist.PersistenceContext;


public class PortableSceneController extends ZWaveNode {
public static final byte ID = 0x01;

public PortableSceneController(NodeInfo info, boolean listening, NodeListener listener) {
super(info, listening, listener);

addCommandClass(BasicCommandClass.ID, new BasicCommandClass());
addCommandClass(VersionCommandClass.ID, new VersionCommandClass());
addCommandClass(BatteryCommandClass.ID, new BatteryCommandClass());
addCommandClass(CentralSceneCommandClass.ID, new CentralSceneCommandClass());
}

public PortableSceneController(PersistenceContext pctx, Byte nodeId, NodeListener listener) {
super(pctx, nodeId, listener);
}

public CommandClass getCommandClass(byte commandClassId) {
return super.getCommandClass(commandClassId);
}

@Override
protected void refresh(boolean deferIfNotListening) { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.whizzosoftware.wzwave.commandclass;

import org.junit.Test;

import static com.whizzosoftware.wzwave.commandclass.CentralSceneCommandClass.SceneCommand.BEING_HELD;
import static com.whizzosoftware.wzwave.commandclass.CentralSceneCommandClass.SceneCommand.PUSHED;
import static com.whizzosoftware.wzwave.commandclass.CentralSceneCommandClass.SceneCommand.RELEASED_AFTER_HOLD;
import static org.junit.Assert.*;

public class CentralSceneCommandClassTest {
@Test
public void testReport() {
CentralSceneCommandClass cc = new CentralSceneCommandClass();

cc.onApplicationCommand(null, new byte[] { 0x5B, 0x03, 0x01, 0x00, 0x01 }, 0);
assertEquals((Integer) 1, cc.getSceneNumber());
assertEquals(PUSHED, cc.getSceneCommand());
assertEquals((Integer) 1, cc.getPushCount());

cc.onApplicationCommand(null, new byte[] { 0x5B, 0x03, 0x02, 0x03, 0x02 }, 0);
assertEquals((Integer) 2, cc.getSceneNumber());
assertEquals(PUSHED, cc.getSceneCommand());
assertEquals((Integer) 2, cc.getPushCount());

cc.onApplicationCommand(null, new byte[] { 0x5B, 0x03, 0x03, 0x02, 0x03 }, 0);
assertEquals(BEING_HELD, cc.getSceneCommand());

cc.onApplicationCommand(null, new byte[] { 0x5B, 0x03, 0x04, 0x01, 0x03 }, 0);
assertEquals(RELEASED_AFTER_HOLD, cc.getSceneCommand());

cc.setVersion(3);
cc.onApplicationCommand(null, new byte[] { 0x5B, 0x03, 0x05, (byte) 0x83, 0x04 }, 0);
assertEquals((Integer) 4, cc.getSceneNumber());
assertEquals(PUSHED, cc.getSceneCommand());
assertEquals((Integer) 2, cc.getPushCount());
assertEquals(true, cc.getSlowRefresh());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.whizzosoftware.wzwave.commandclass.BinarySwitchCommandClass;
import com.whizzosoftware.wzwave.commandclass.CommandClass;
import com.whizzosoftware.wzwave.commandclass.NoOperationCommandClass;
import com.whizzosoftware.wzwave.node.generic.BinarySensor;
import com.whizzosoftware.wzwave.node.generic.BinarySwitch;
import com.whizzosoftware.wzwave.node.generic.MultilevelSwitch;
import com.whizzosoftware.wzwave.node.generic.StaticController;
import com.whizzosoftware.wzwave.node.generic.*;
import com.whizzosoftware.wzwave.node.specific.BinaryPowerSwitch;
import com.whizzosoftware.wzwave.node.specific.MultilevelPowerSwitch;
import com.whizzosoftware.wzwave.node.specific.PCController;
Expand All @@ -31,6 +28,8 @@ public void testCreateDiscoveredNode() throws Exception {

assertTrue(ZWaveNodeFactory.createNode(new NodeInfo((byte)0x01, (byte) 0x00, MultilevelSwitch.ID, (byte)0x00), false, null) instanceof MultilevelSwitch);
assertTrue(ZWaveNodeFactory.createNode(new NodeInfo((byte)0x01, (byte) 0x00, MultilevelSwitch.ID, MultilevelPowerSwitch.ID), false, null) instanceof MultilevelPowerSwitch);

assertTrue(ZWaveNodeFactory.createNode(new NodeInfo((byte)0x01, (byte)0x00, PortableSceneController.ID, (byte)0x02), false, null) instanceof PortableSceneController);
}

@Test
Expand Down