Skip to content

Commit

Permalink
added support for Basic Scenario (WHO=0) messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mvalla committed May 22, 2022
1 parent c9de1bc commit 138ad3b
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 2 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.9.0] - 2022-05-??

### Added
- Initial support for SCENARIOS (WHO=0)


## [0.8.1] - 2022-03-24

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

<groupId>io.github.openwebnet4j</groupId>
<artifactId>openwebnet4j</artifactId>
<version>0.8.1</version>
<version>0.9.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>openwebnet4j OpenWebNet Java library</name>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/openwebnet4j/OpenDeviceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public enum OpenDeviceType {
/** OpenWebNet Device types. See OWN ZigBee docs pages 50-51 */
UNKNOWN(0),
SCENARIO_CONTROL(2),
// basic scenario WHO=0 not defined by BTicino)
BASIC_SCENARIO(3),
// lighting
ZIGBEE_ON_OFF_SWITCH(256),
ZIGBEE_DIMMER_CONTROL(257),
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/openwebnet4j/message/BaseOpenMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ private static BaseOpenMessage parseWho(String whoPart, String frame)

BaseOpenMessage baseopenmsg = null;
switch (who) {
case SCENARIO:
baseopenmsg = new Scenario(frame);
break;
case GATEWAY_MANAGEMENT:
baseopenmsg = new GatewayMgmt(frame);
break;
Expand Down
127 changes: 127 additions & 0 deletions src/main/java/org/openwebnet4j/message/Scenario.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/**
* Copyright (c) 2022 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 java.util.HashMap;
import java.util.Map;

import org.openwebnet4j.OpenDeviceType;

/**
* OpenWebNet class for Scenario (WHO=0)
*
* @author M. Valla - Initial contribution
*/
public class Scenario extends BaseOpenMessage {
// private static final Logger logger = LoggerFactory.getLogger(Scenario.class);

public enum WhatScenario implements What {
// In F420 (03551) it is possible to program up to 16 scenarios.
// In the IR 3456 (88301) it is possible to recall up to 20 different scenarios.
SCENARIO_01(1),
SCENARIO_02(2),
SCENARIO_03(3),
SCENARIO_04(4),
SCENARIO_05(5),
SCENARIO_06(6),
SCENARIO_07(7),
SCENARIO_08(8),
SCENARIO_09(9),
SCENARIO_10(10),
SCENARIO_11(11),
SCENARIO_12(12),
SCENARIO_13(13),
SCENARIO_14(14),
SCENARIO_15(15),
SCENARIO_16(16),
// Supported only by module IR 3456 (88301):
SCENARIO_17(17),
SCENARIO_18(18),
SCENARIO_19(19),
SCENARIO_20(20),
// Commands only for F420:
START_RECORDING_SCENARIO(40),
END_RECORDING_SCENARIO(41),
ERASE_SCENARIO(42),
LOCK_SCENARIOS_CU(43),
UNLOCK_SCENARIOS_CU(44),
UNAVAILABLE_SCENARIO_CU(45),
MEMORY_FULL_CU(46);

private static Map<Integer, WhatScenario> mapping;

private final int value;

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

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

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

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

@Override
protected Dim dimFromValue(int i) {
// no Dims for this WHO
return null;
}

private static final int WHO = Who.SCENARIO.value();

protected Scenario(String value) {
super(value);
this.who = Who.SCENARIO;

}

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

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

@Override
public OpenDeviceType detectDeviceType() {
if (!isCommand()) { // ignore status/dimension frames for discovery
return null;
}
return OpenDeviceType.BASIC_SCENARIO;
}

}
37 changes: 36 additions & 1 deletion src/test/java/org/openwebnet4j/test/MessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.openwebnet4j.message.Lighting;
import org.openwebnet4j.message.MalformedFrameException;
import org.openwebnet4j.message.OpenMessage;
import org.openwebnet4j.message.Scenario;
import org.openwebnet4j.message.Thermoregulation;
import org.openwebnet4j.message.Thermoregulation.Function;
import org.openwebnet4j.message.Thermoregulation.OperationMode;
Expand All @@ -52,6 +53,7 @@
* @author Andrea Conte - Energy Management contribution
* @author G. Cocchi - Thermoregulation contribution
* @author G. Fabiani - Auxiliary contribution
* @author M. Valla - Alarm and Scenario contribution
*/
public class MessageTest {

Expand Down Expand Up @@ -327,7 +329,7 @@ public void testWhatThermo() {
assertEquals(OperationMode.SCENARIO_2, wt.getMode());
assertEquals("SCENARIO", wt.getMode().mode());
assertEquals(2, wt.getMode().programNumber());

} catch (FrameException e) {
Assertions.fail();
}
Expand Down Expand Up @@ -543,4 +545,37 @@ public void testAlarm() {
Assertions.fail();
}
}

@Test
public void testScenario() {
Scenario scenarioMsg;
try {
scenarioMsg = (Scenario) BaseOpenMessage.parse("*0*14*95##");
assertNotNull(scenarioMsg);
assertEquals(Who.SCENARIO, scenarioMsg.getWho());
assertTrue(scenarioMsg.isCommand());
assertNotNull(scenarioMsg.getWhere());
assertEquals("95", scenarioMsg.getWhere().value());
assertEquals(Scenario.WhatScenario.SCENARIO_14, scenarioMsg.getWhat());

scenarioMsg = (Scenario) BaseOpenMessage.parse("*0*2*05##");
assertNotNull(scenarioMsg);
assertEquals(Who.SCENARIO, scenarioMsg.getWho());
assertTrue(scenarioMsg.isCommand());
assertNotNull(scenarioMsg.getWhere());
assertEquals("05", scenarioMsg.getWhere().value());
assertEquals(Scenario.WhatScenario.SCENARIO_02, scenarioMsg.getWhat());

scenarioMsg = (Scenario) BaseOpenMessage.parse("*0*40#5*06##");
assertNotNull(scenarioMsg);
assertEquals(Who.SCENARIO, scenarioMsg.getWho());
assertTrue(scenarioMsg.isCommand());
assertNotNull(scenarioMsg.getWhere());
assertEquals("06", scenarioMsg.getWhere().value());

} catch (FrameException e) {
System.out.println(e.getMessage());
Assertions.fail();
}
}
}

0 comments on commit 138ad3b

Please sign in to comment.