Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

[satel] Support for troubles added #5162

Merged
merged 1 commit into from
Apr 22, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
package org.openhab.binding.satel.command;

import java.util.Arrays;

import org.openhab.binding.satel.internal.event.EventDispatcher;
import org.openhab.binding.satel.internal.event.IntegraStateEvent;
import org.openhab.binding.satel.internal.protocol.SatelMessage;
Expand All @@ -31,7 +33,7 @@ public class IntegraStateCommand extends SatelCommandBase {

/**
* Constructs new command instance for specified type of state.
*
*
* @param stateType
* type of state
* @param extended
Expand All @@ -48,7 +50,7 @@ public IntegraStateCommand(StateType stateType, boolean extended) {
* zones/outputs)
*/
public boolean isExtended() {
return EXTENDED_CMD_PAYLOAD.equals(this.getPayload());
return Arrays.equals(EXTENDED_CMD_PAYLOAD, this.getPayload());
}

/**
Expand All @@ -58,7 +60,8 @@ public boolean isExtended() {
public boolean handleResponse(EventDispatcher eventDispatcher, SatelMessage response) {
if (super.handleResponse(eventDispatcher, response)) {
// dispatch event
eventDispatcher.dispatchEvent(new IntegraStateEvent(this.stateType, response.getPayload()));
eventDispatcher
.dispatchEvent(new IntegraStateEvent(response.getCommand(), response.getPayload(), isExtended()));
return true;
} else {
return false;
Expand All @@ -72,25 +75,12 @@ protected boolean isResponseValid(SatelMessage response) {
logger.error("Invalid response code: {}", response.getCommand());
return false;
}
if (!isPayloadLengthValid(response.getPayload().length)) {
logger.error("Invalid payload length for this object type {}: {}", this.stateType.getObjectType(),
if (response.getPayload().length != this.stateType.getPayloadLength(isExtended())) {
logger.error("Invalid payload length for this state type {}: {}", this.stateType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a warn instead of an error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The level hasn't changed in this PR, it was always an error. But I can change it, if you wish.

response.getPayload().length);
return false;
}
return true;
}

private boolean isPayloadLengthValid(int length) {
switch (this.stateType.getObjectType()) {
case PARTITION:
return length == 4;
case ZONE:
case OUTPUT:
return isExtended() ? length == 32 : length == 16;
case DOORS:
return length == 8;
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.apache.commons.lang.ArrayUtils;
import org.openhab.binding.satel.SatelBindingConfig;
import org.openhab.binding.satel.command.ClearTroublesCommand;
import org.openhab.binding.satel.command.ControlObjectCommand;
import org.openhab.binding.satel.command.IntegraStateCommand;
import org.openhab.binding.satel.command.SatelCommand;
Expand All @@ -26,6 +27,8 @@
import org.openhab.binding.satel.internal.types.PartitionControl;
import org.openhab.binding.satel.internal.types.PartitionState;
import org.openhab.binding.satel.internal.types.StateType;
import org.openhab.binding.satel.internal.types.TroubleMemoryState;
import org.openhab.binding.satel.internal.types.TroubleState;
import org.openhab.binding.satel.internal.types.ZoneControl;
import org.openhab.binding.satel.internal.types.ZoneState;
import org.openhab.core.items.Item;
Expand Down Expand Up @@ -103,16 +106,24 @@ public static IntegraStateBindingConfig parseConfig(String bindingConfig) throws
case DOORS:
stateType = iterator.nextOfType(DoorsState.class, "doors state type");
break;
case TROUBLE:
stateType = iterator.nextOfType(TroubleState.class, "trouble state type");
break;
case TROUBLE_MEMORY:
stateType = iterator.nextOfType(TroubleMemoryState.class, "trouble memory state type");
break;
}

// parse object number, if provided
if (iterator.hasNext()) {
try {
int objectNumberMax = 8 * stateType.getBytesCount(true);
String[] objectNumbersStr = iterator.next().split(",");
objectNumbers = new int[objectNumbersStr.length];
for (int i = 0; i < objectNumbersStr.length; ++i) {
int objectNumber = Integer.parseInt(objectNumbersStr[i]);
if (objectNumber < 1 || objectNumber > 256) {
// range from parsed state type (number of state bytes)
if (objectNumber < 1 || objectNumber > objectNumberMax) {
throw new BindingConfigParseException(
String.format("Invalid object number: %s", bindingConfig));
}
Expand All @@ -136,7 +147,7 @@ public State convertEventToState(Item item, SatelEvent event) {
}

IntegraStateEvent stateEvent = (IntegraStateEvent) event;
if (stateEvent.getStateType() != this.stateType) {
if (!stateEvent.hasDataForState(this.stateType)) {
return null;
}

Expand All @@ -145,9 +156,9 @@ public State convertEventToState(Item item, SatelEvent event) {
boolean invertState = hasOptionEnabled(Options.INVERT_STATE)
&& (this.stateType.getObjectType() == ObjectType.ZONE
|| this.stateType.getObjectType() == ObjectType.OUTPUT);
return booleanToState(item, stateEvent.isSet(bitNbr) ^ invertState);
return booleanToState(item, stateEvent.isSet(this.stateType, bitNbr) ^ invertState);
} else if (this.objectNumbers.length == 0) {
int statesSet = stateEvent.statesSet();
int statesSet = stateEvent.statesSet(this.stateType);
if (item instanceof NumberItem) {
return new DecimalType(statesSet);
} else {
Expand All @@ -157,11 +168,11 @@ public State convertEventToState(Item item, SatelEvent event) {
// roller shutter support
int upBitNbr = this.objectNumbers[0] - 1;
int downBitNbr = this.objectNumbers[1] - 1;
if (stateEvent.isSet(upBitNbr)) {
if (!stateEvent.isSet(downBitNbr)) {
if (stateEvent.isSet(this.stateType, upBitNbr)) {
if (!stateEvent.isSet(this.stateType, downBitNbr)) {
return UpDownType.UP;
}
} else if (stateEvent.isSet(downBitNbr)) {
} else if (stateEvent.isSet(this.stateType, downBitNbr)) {
return UpDownType.DOWN;
}
}
Expand Down Expand Up @@ -259,6 +270,16 @@ public SatelCommand convertCommand(Command command, IntegraType integraType, Str
// do nothing for other types of state
break;
}

case TROUBLE:
case TROUBLE_MEMORY:
// clear troubles
if (switchOn) {
return null;
} else {
return new ClearTroublesCommand(userCode);
}

}
} else if (this.stateType.getObjectType() == ObjectType.OUTPUT && this.objectNumbers.length == 2) {
// roller shutter support
Expand Down
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
/**
* Copyright (c) 2010-2016 by the respective copyright holders.
*
* 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 org.openhab.binding.satel.config;

import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.List;

import org.openhab.binding.satel.SatelBindingConfig;
import org.openhab.model.item.binding.BindingConfigParseException;

/**
* Creates proper binding configuration class for given configuration string.
*
* @author Krzysztof Goworek
* @since 1.8.0
*/
public class SatelBindingConfigFactory {

private final List<Class<? extends SatelBindingConfig>> bindingConfigurationClasses = new LinkedList<Class<? extends SatelBindingConfig>>();

/**
* Constructs factory object. Adds all known types of configuration classes
* to internal registry.
*/
public SatelBindingConfigFactory() {
bindingConfigurationClasses.add(IntegraStateBindingConfig.class);
bindingConfigurationClasses.add(IntegraStatusBindingConfig.class);
bindingConfigurationClasses.add(ConnectionStatusBindingConfig.class);
}

/**
* Creates binding configuration class basing on given configuration string.
*
* @param bindingConfig
* configuration string
* @return an instance of {@link SatelBindingConfig}
* @throws BindingConfigParseException
* on any parsing error
*/
public SatelBindingConfig createBindingConfig(String bindingConfig) throws BindingConfigParseException {
try {
for (Class<? extends SatelBindingConfig> c : bindingConfigurationClasses) {
Method parseConfigMethod = c.getMethod("parseConfig", String.class);
SatelBindingConfig bc = (SatelBindingConfig) parseConfigMethod.invoke(null, bindingConfig);
if (bc != null) {
return bc;
}
}
// no more options, throw parse exception
} catch (Exception e) {
// throw parse exception in case of any error
}

throw new BindingConfigParseException(String.format("Invalid binding configuration: %s", bindingConfig));
}
}
/**
* Copyright (c) 2010-2016 by the respective copyright holders.
*
* 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 org.openhab.binding.satel.config;

import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.List;

import org.openhab.binding.satel.SatelBindingConfig;
import org.openhab.model.item.binding.BindingConfigParseException;

/**
* Creates proper binding configuration class for given configuration string.
*
* @author Krzysztof Goworek
* @since 1.8.0
*/
public class SatelBindingConfigFactory {

private final List<Class<? extends SatelBindingConfig>> bindingConfigurationClasses = new LinkedList<Class<? extends SatelBindingConfig>>();

/**
* Constructs factory object. Adds all known types of configuration classes
* to internal registry.
*/
public SatelBindingConfigFactory() {
bindingConfigurationClasses.add(IntegraStateBindingConfig.class);
bindingConfigurationClasses.add(IntegraStatusBindingConfig.class);
bindingConfigurationClasses.add(ConnectionStatusBindingConfig.class);
}

/**
* Creates binding configuration class basing on given configuration string.
*
* @param bindingConfig
* configuration string
* @return an instance of {@link SatelBindingConfig}
* @throws BindingConfigParseException
* on any parsing error
*/
public SatelBindingConfig createBindingConfig(String bindingConfig) throws BindingConfigParseException {
try {
for (Class<? extends SatelBindingConfig> c : bindingConfigurationClasses) {
Method parseConfigMethod = c.getMethod("parseConfig", String.class);
SatelBindingConfig bc = (SatelBindingConfig) parseConfigMethod.invoke(null, bindingConfig);
if (bc != null) {
return bc;
}
}
// no more options, throw parse exception
} catch (Exception e) {
// throw parse exception in case of any error
}

throw new BindingConfigParseException(String.format("Invalid binding configuration: %s", bindingConfig));
}
}
Loading