Skip to content

Commit

Permalink
version 0.3.0, added support for WHO=2 Automation
Browse files Browse the repository at this point in the history
  • Loading branch information
mvalla committed Sep 9, 2020
1 parent 7151b12 commit e2689db
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [0.3.0] - 2020-09-09

### Added
- Support for WHO=2 Automation
- OpenConnector.getLastCmdFrameSentTs() and OpenGateway.isCmdConnectionReady()

## [0.2.0] - 2020-08-07

### Added
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Supported features:
Supported frames:

* `WHO=1` Lighting
* `WHO=2` Automation
* `WHO=13` Gateway Management

Supported Open Web Net gateways:
Expand All @@ -22,7 +23,7 @@ Supported Open Web Net gateways:

- [x] Support numeric passwords (OPEN handshake)
- [x] Support alphanumeric passwords (HMAC handshake)
- [ ] Add `WHO=2` Automation (shutters)
- [x] Support for `WHO=2` Automation (shutters)
- [ ] Add other `WHOs` (Energy, Thermo, CEN/CEN+, AUX, etc.)
- [ ] extend OpenConnector.listener to multiple listeners
- [ ] ZigBee: check isOldFirmware and related gw bugfixes
Expand All @@ -34,7 +35,7 @@ Supported Open Web Net gateways:
<dependency>
<groupId>com.github.openwebnet4j</groupId>
<artifactId>openwebnet4j</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.openwebnet4j</groupId>
<artifactId>openwebnet4j</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
<packaging>jar</packaging>

<name>openwebnet4j OpenWebNet Java library</name>
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/openwebnet4j/BUSGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.openwebnet4j.communication.BUSConnector;
import org.openwebnet4j.communication.OWNException;
import org.openwebnet4j.communication.Response;
import org.openwebnet4j.message.Automation;
import org.openwebnet4j.message.Lighting;
import org.openwebnet4j.message.OpenMessage;
import org.openwebnet4j.message.Where;
Expand Down Expand Up @@ -106,6 +107,20 @@ protected void discoverDevicesInternal() throws OWNException {
}
}
}
// DISCOVER AUTOMATION - request status for all automations: *#2*0##
logger.debug("##BUS## ----- AUTOMATION discovery");
res = sendInternal(Automation.requestStatus(WhereLightAutom.GENERAL.value()));
for (OpenMessage msg : res.getResponseMessages()) {
if (msg instanceof Automation) {
Automation amsg = ((Automation) msg);
OpenDeviceType type = amsg.detectDeviceType();
if (type != null) {
Where w = amsg.getWhere();
notifyListeners((listener) -> listener.onNewDevice(w, type, amsg));
}

}
}
} catch (OWNException e) {
logger.error("##BUS## ----- # OWNException while discovering devices: {}", e.getMessage());
isDiscovering = false;
Expand Down
213 changes: 213 additions & 0 deletions src/main/java/org/openwebnet4j/message/Automation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
/**
* Copyright (c) 2020 Contributors to the openwebnet4j project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
*/
package org.openwebnet4j.message;

import static java.lang.String.format;

import java.util.HashMap;
import java.util.Map;

import org.openwebnet4j.OpenDeviceType;

/**
* OpenWebNet Automation messages (WHO=2)
*
* @author M. Valla - Initial contribution
*/
public class Automation extends BaseOpenMessage {

public enum WHAT implements What {
STOP(0),
UP(1),
DOWN(2);

private static Map<Integer, WHAT> mapping;

private final int value;

private WHAT(int value) {
this.value = value;
}

private static void initMapping() {
mapping = new HashMap<Integer, WHAT>();
for (WHAT w : values()) {
mapping.put(w.value, w);
}
}

public static WHAT fromValue(int i) {
if (mapping == null) {
initMapping();
}
return mapping.get(i);
}

@Override
public Integer value() {
return value;
}

}

@Override
protected What whatFromValue(int i) {
return WHAT.fromValue(i);
}

public enum DIM implements Dim {
DIMMER_LEVEL_100(1);

private static Map<Integer, DIM> mapping;

private final int value;

private DIM(Integer value) {
this.value = value;
}

private static void initMapping() {
mapping = new HashMap<Integer, DIM>();
for (DIM d : values()) {
mapping.put(d.value, d);
}
}

public static DIM fromValue(int i) {
if (mapping == null) {
initMapping();
}
return mapping.get(i);
}

@Override
public Integer value() {
return value;
}

}

@Override
protected Dim dimFromValue(int i) {
return DIM.fromValue(i);
}

private static final int WHO = org.openwebnet4j.message.Who.AUTOMATION.value();

protected Automation(String value) {
super(value);
}

/**
* OpenWebNet message request to send <i>STOP</i> <b>*2*0*WHERE##</b>.
*
* @param w WHERE string
* @return message
*/
public static Automation requestStop(String w) {
return new Automation(format(FORMAT_REQUEST, WHO, WHAT.STOP.value, w));
}

/**
* OpenWebNet message request to send <i>UP</i> <b>*2*1*WHERE##</b>.
*
* @param w WHERE string
* @return message
*/
public static Automation requestMoveUp(String w) {
return new Automation(format(FORMAT_REQUEST, WHO, WHAT.UP.value, w));
}

/**
* OpenWebNet message request to send <i>DOWN</i> <b>*2*2*WHERE##</b>.
*
* @param w WHERE string
* @return message
*/
public static Automation requestMoveDown(String w) {
return new Automation(format(FORMAT_REQUEST, WHO, WHAT.DOWN.value, w));
}

/**
* OpenWebNet message request automation status <b>*#2*WHERE##</b>.
*
* @param w WHERE string
* @return message
*/
public static Automation requestStatus(String w) {
return new Automation(format(FORMAT_STATUS, WHO, w));
}

/**
* Verify OpenWebNet message is <i>STOP</i> (WHAT=0).
*
* @return true if message is "STOP"
*/
public boolean isStop() {
if (getWhat() == null) {
return false;
} else {
return getWhat().equals(WHAT.STOP);
}
}

/**
* Verify OpenWebNet message is <i>UP</i> (WHAT=1).
*
* @return true if message is "UP"
*/
public boolean isUp() {
if (getWhat() == null) {
return false;
} else {
return getWhat().equals(WHAT.UP);
}
}

/**
* Verify OpenWebNet message is <i>DOWN</i> (WHAT=2).
*
* @return true if message is "DOWN"
*/
public boolean isDown() {
if (getWhat() == null) {
return false;
} else {
return getWhat().equals(WHAT.DOWN);
}
}

@Override
protected void parseWhere() throws FrameException {
if (whereStr == null) {
throw new FrameException("Frame has no WHERE part: " + whereStr);
} else {
if (whereStr.endsWith(WhereZigBee.ZB_NETWORK)) {
where = new WhereZigBee(whereStr);
} else {
where = new WhereLightAutom(whereStr);
}
}
}

@Override
public OpenDeviceType detectDeviceType() {
if (isCommand()) { // ignore status/dimension frames for detecting device type
return OpenDeviceType.SCS_SHUTTER_CONTROL;
} else {
return null;
}
}
}
11 changes: 9 additions & 2 deletions src/main/java/org/openwebnet4j/message/BaseOpenMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ protected static BaseOpenMessage parseWho(String whoPart, String frame) throws F
case LIGHTING:
baseopenmsg = new Lighting(frame);
break;
case AUTOMATION:
baseopenmsg = new Automation(frame);
break;
default:
break;
}
Expand Down Expand Up @@ -300,10 +303,11 @@ protected void parseDim() throws FrameException {
/**
* Check if message is a command translation (*WHO*1000#WHAT*...##)
*
* @return true if the WHAT part is prefixed with command translation 1000#
* @return true if the WHAT part is prefixed with command translation: 1000#
* @throws FrameException
*/
public boolean isCommandTranslation() throws FrameException {
if (what == null) {
if (isCommand && what == null) {
parseWhat();
}
return commandTranslation;
Expand All @@ -313,6 +317,7 @@ public boolean isCommandTranslation() throws FrameException {
* Returns message command parameters (*WHO*WHAT#Par1#Par2...#ParN*...), or null if no parameters are present
*
* @return int[] of command parameters, or null if no parameters
* @throws FrameException
*/
public int[] getCommandParams() throws FrameException {
if (what == null) {
Expand All @@ -325,6 +330,7 @@ public int[] getCommandParams() throws FrameException {
* Returns an array with DIM parameters PAR1..PARN (*#WHO*DIM#PAR1..#PARN*...##)
*
* @return a int[] of DIM parameters
* @throws FrameException
*/
public int[] getDimParams() throws FrameException {
if (dim == null) {
Expand All @@ -349,6 +355,7 @@ protected void setDimParams(String[] params) throws NumberFormatException {
* Returns and array with DIM values
*
* @return a String[] of DIM values
* @throws FrameException
*/
public String[] getDimValues() throws FrameException {
if (dim == null) {
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/org/openwebnet4j/test/MessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.openwebnet4j.message.Automation;
import org.openwebnet4j.message.BaseOpenMessage;
import org.openwebnet4j.message.FrameException;
import org.openwebnet4j.message.GatewayMgmt;
Expand Down Expand Up @@ -58,6 +59,24 @@ public void testLightingCommandTranslationAndParams() {
}
}

@Test
public void testAutomation() {
Automation automMsg;
try {
automMsg = (Automation) BaseOpenMessage.parse("*2*1000#0*55##");
assertNotNull(automMsg);
assertTrue(automMsg.isCommand());
assertTrue(automMsg.isCommandTranslation());
assertEquals("55", automMsg.getWhere().value());
assertEquals(Automation.WHAT.STOP, automMsg.getWhat());
assertTrue(automMsg.isStop());
assertFalse(automMsg.isUp());
System.out.println(automMsg.toStringVerbose());
} catch (FrameException e) {
Assertions.fail();
}
}

@Test
public void testZigBeeLightingWhere() {
Lighting lightMsg;
Expand Down

0 comments on commit e2689db

Please sign in to comment.