Skip to content

Commit

Permalink
Ca commence à bien prendre forme.
Browse files Browse the repository at this point in the history
On sauvegarde le travail effectué.

Signed-off-by: Gaël L'hopital <gael@lhopital.org>
  • Loading branch information
clinique committed Apr 14, 2019
1 parent fafd69c commit a7ad91b
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 100 deletions.
58 changes: 29 additions & 29 deletions addons/binding/org.openhab.binding.gce/ESH-INF/thing/channels.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,42 @@
<label>Digital Input 1</label></channel>
<channel id="1-event" typeId="pushButtonTrigger" />
<channel id="1-timestamp" typeId="timestamp" />
<channel id="1-duration" typeId="lastStateDuration" />
<channel id="1-duration" typeId="duration" />
<channel id="2" typeId="digitalInput" >
<label>Digital Input 2</label></channel>
<channel id="2-event" typeId="pushButtonTrigger" />
<channel id="2-timestamp" typeId="timestamp" />
<channel id="2-duration" typeId="lastStateDuration" />
<channel id="2-duration" typeId="duration" />
<channel id="3" typeId="digitalInput" >
<label>Digital Input 3</label></channel>
<channel id="3-event" typeId="pushButtonTrigger" />
<channel id="3-timestamp" typeId="timestamp" />
<channel id="3-duration" typeId="lastStateDuration" />
<channel id="3-duration" typeId="duration" />
<channel id="4" typeId="digitalInput" >
<label>Digital Input 4</label></channel>
<channel id="4-event" typeId="pushButtonTrigger" />
<channel id="4-timestamp" typeId="timestamp" />
<channel id="4-duration" typeId="lastStateDuration" />
<channel id="4-duration" typeId="duration" />
<channel id="5" typeId="digitalInput" >
<label>Digital Input 5</label></channel>
<channel id="5-event" typeId="pushButtonTrigger" />
<channel id="5-timestamp" typeId="timestamp" />
<channel id="5-duration" typeId="lastStateDuration" />
<channel id="5-duration" typeId="duration" />
<channel id="6" typeId="digitalInput" >
<label>Digital Input 6</label></channel>
<channel id="6-event" typeId="pushButtonTrigger" />
<channel id="6-timestamp" typeId="timestamp" />
<channel id="6-duration" typeId="lastStateDuration" />
<channel id="6-duration" typeId="duration" />
<channel id="7" typeId="digitalInput" >
<label>Digital Input 7</label></channel>
<channel id="7-event" typeId="pushButtonTrigger" />
<channel id="7-timestamp" typeId="timestamp" />
<channel id="7-duration" typeId="lastStateDuration" />
<channel id="7-duration" typeId="duration" />
<channel id="8" typeId="digitalInput" >
<label>Digital Input 8</label></channel>
<channel id="8-event" typeId="pushButtonTrigger" />
<channel id="8-timestamp" typeId="timestamp" />
<channel id="8-duration" typeId="lastStateDuration" />
<channel id="8-duration" typeId="duration" />
</channels>
</channel-group-type>

Expand All @@ -57,35 +57,35 @@
<channel id="1" typeId="digitalOutput" >
<label>Digital Output 1</label></channel>
<channel id="1-timestamp" typeId="timestamp" />
<channel id="1-duration" typeId="lastStateDuration" />
<channel id="1-duration" typeId="duration" />
<channel id="2" typeId="digitalOutput" >
<label>Digital Output 2</label></channel>
<channel id="2-timestamp" typeId="timestamp" />
<channel id="2-duration" typeId="lastStateDuration" />
<channel id="2-duration" typeId="duration" />
<channel id="3" typeId="digitalOutput" >
<label>Digital Output 3</label></channel>
<channel id="3-timestamp" typeId="timestamp" />
<channel id="3-duration" typeId="lastStateDuration" />
<channel id="3-duration" typeId="duration" />
<channel id="4" typeId="digitalOutput" >
<label>Digital Output 4</label></channel>
<channel id="4-timestamp" typeId="timestamp" />
<channel id="4-duration" typeId="lastStateDuration" />
<channel id="4-duration" typeId="duration" />
<channel id="5" typeId="digitalOutput" >
<label>Digital Output 5</label></channel>
<channel id="5-timestamp" typeId="timestamp" />
<channel id="5-duration" typeId="lastStateDuration" />
<channel id="5-duration" typeId="duration" />
<channel id="6" typeId="digitalOutput" >
<label>Digital Output 6</label></channel>
<channel id="6-timestamp" typeId="timestamp" />
<channel id="6-duration" typeId="lastStateDuration" />
<channel id="6-duration" typeId="duration" />
<channel id="7" typeId="digitalOutput" >
<label>Digital Output 7</label></channel>
<channel id="7-timestamp" typeId="timestamp" />
<channel id="7-duration" typeId="lastStateDuration" />
<channel id="7-duration" typeId="duration" />
<channel id="8" typeId="digitalOutput" >
<label>Digital Output 8</label></channel>
<channel id="8-timestamp" typeId="timestamp" />
<channel id="8-duration" typeId="lastStateDuration" />
<channel id="8-duration" typeId="duration" />
</channels>
</channel-group-type>

Expand All @@ -95,35 +95,35 @@
<channel id="1" typeId="counter" >
<label>Counter 1</label></channel>
<channel id="1-timestamp" typeId="timestamp" />
<channel id="1-duration" typeId="lastStateDuration" />
<channel id="1-duration" typeId="duration" />
<channel id="2" typeId="counter">
<label>Counter 2</label></channel>
<channel id="2-timestamp" typeId="timestamp" />
<channel id="2-duration" typeId="lastStateDuration" />
<channel id="2-duration" typeId="duration" />
<channel id="3" typeId="counter">
<label>Counter 3</label></channel>
<channel id="3-timestamp" typeId="timestamp" />
<channel id="3-duration" typeId="lastStateDuration" />
<channel id="3-duration" typeId="duration" />
<channel id="4" typeId="counter">
<label>Counter 4</label></channel>
<channel id="4-timestamp" typeId="timestamp" />
<channel id="4-duration" typeId="lastStateDuration" />
<channel id="4-duration" typeId="duration" />
<channel id="5" typeId="counter">
<label>Counter 5</label></channel>
<channel id="5-timestamp" typeId="timestamp" />
<channel id="5-duration" typeId="lastStateDuration" />
<channel id="5-duration" typeId="duration" />
<channel id="6" typeId="counter">
<label>Counter 6</label></channel>
<channel id="6-timestamp" typeId="timestamp" />
<channel id="6-duration" typeId="lastStateDuration" />
<channel id="6-duration" typeId="duration" />
<channel id="7" typeId="counter">
<label>Counter 7</label></channel>
<channel id="7-timestamp" typeId="timestamp" />
<channel id="7-duration" typeId="lastStateDuration" />
<channel id="7-duration" typeId="duration" />
<channel id="8" typeId="counter">
<label>Counter 8</label></channel>
<channel id="8-timestamp" typeId="timestamp" />
<channel id="8-duration" typeId="lastStateDuration" />
<channel id="8-duration" typeId="duration" />
</channels>
</channel-group-type>

Expand All @@ -133,19 +133,19 @@
<channel id="1" typeId="analogInput" >
<label>Analog Input 1</label></channel>
<channel id="1-timestamp" typeId="timestamp" />
<channel id="1-duration" typeId="lastStateDuration" />
<channel id="1-duration" typeId="duration" />
<channel id="2" typeId="analogInput" >
<label>Analog Input 2</label></channel>
<channel id="2-timestamp" typeId="timestamp" />
<channel id="2-duration" typeId="lastStateDuration" />
<channel id="2-duration" typeId="duration" />
<channel id="3" typeId="analogInput" >
<label>Analog Input 3</label></channel>
<channel id="3-timestamp" typeId="timestamp" />
<channel id="3-duration" typeId="lastStateDuration" />
<channel id="3-duration" typeId="duration" />
<channel id="4" typeId="analogInput" >
<label>Analog Input 4</label></channel>
<channel id="4-timestamp" typeId="timestamp" />
<channel id="4-duration" typeId="lastStateDuration" />
<channel id="4-duration" typeId="duration" />
</channels>
</channel-group-type>

Expand Down Expand Up @@ -211,7 +211,7 @@
<state readOnly="true" />
</channel-type>

<channel-type id="lastStateDuration" advanced="true">
<channel-type id="duration" advanced="true">
<item-type>Number:Time</item-type>
<label>Previous State Duration</label>
<description>Duration of previous state before state change.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class GCEBindingConstants {
public static final String GROUP_RELAY_OUTPUT = "O";

public static final String TIMESTAMP_CHANNEL_NAME = "timestamp";
public static final String LAST_STATE_DURATION_CHANNEL_NAME = "lastStateDuration";
public static final String LAST_STATE_DURATION_CHANNEL_NAME = "duration";
public static final String CHANNEL_TYPE_PUSH_BUTTON_TRIGGER = "pushButtonTrigger";

public static final String EVENT_PRESSED = "PRESSED";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public void run() {
private void handleException(Exception e) {
if (e instanceof SocketTimeoutException) {
sendKeepalive();
return;
} else if (e instanceof IOException) {
logger.warn(e.getMessage() + " will retry in " + config.reconnectTimeout + "ms");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ public void initialize() {

@Override
public void dispose() {
connector.destroyAndExit();
if (connector != null) {
connector.destroyAndExit();
}
super.dispose();
}

Expand All @@ -122,7 +124,7 @@ protected void doInitialization() {
parser = new Ipx800MessageParser(connector);
parser.addEventListener(this);
updateStatus(ThingStatus.ONLINE);
// connector.run();
connector.run();
}

@Override
Expand All @@ -149,77 +151,86 @@ private void cancelIfPulsing(PortData portData) {
@Override
public void dataReceived(String port, Double value) {
Channel channel = getChannelForPort(port);
PortData portData = portDatas.get(channel.getUID().getId());
if (portData != null) {
if (value.equals(portData.value)) {
return;
}

ZonedDateTime now = ZonedDateTime.now(ZoneId.systemDefault());
boolean initializing = portData.value == -1;
long sinceLastChange = Duration.between(portData.timestamp, now).toMillis();
Configuration configuration = channel.getConfiguration();
State state = UnDefType.UNDEF;
switch (channel.getUID().getGroupId()) {
case GROUP_COUNTER:
state = new DecimalType(value);
break;
case GROUP_ANALOG_INPUT:
AnalogInputConfiguration config = configuration.as(AnalogInputConfiguration.class);
long histeresis = config.histeresis / 2;
if ((value < portData.value + histeresis || value > portData.value - histeresis) && !initializing) {
return;
}
state = new DecimalType(value);
break;
case GROUP_DIGITAL_INPUT:
DigitalInputConfiguration config2 = configuration.as(DigitalInputConfiguration.class);
if (config2.debouncePeriod != 0
&& now.isBefore(portData.timestamp.plus(config2.debouncePeriod, ChronoUnit.MILLIS))) {
return;
}
cancelIfPulsing(portData);
if (value == 1) {
state = OpenClosedType.CLOSED;
if (portData.value != -1) {
triggerPushButtonChannel(channel, EVENT_PRESSED);
}
if (config2.longPressTime != 0 && !initializing) {
scheduler.schedule(new LongPressEvaluator(channel, port, portData), config2.longPressTime,
TimeUnit.MILLISECONDS);
} else if (config2.pulsePeriod != 0) {
portData.pulsing = scheduler.scheduleAtFixedRate(() -> {
triggerPushButtonChannel(channel, EVENT_PULSE);
}, config2.pulsePeriod, config2.pulsePeriod, TimeUnit.MILLISECONDS);
if (config2.pulseTimeout != 0) {
scheduler.schedule(() -> {
cancelIfPulsing(portData);
}, config2.pulseTimeout, TimeUnit.MILLISECONDS);
if (channel != null) {
PortData portData = portDatas.get(channel.getUID().getId());
if (portData != null) {
if (value.equals(portData.value)) {
return;
}

ZonedDateTime now = ZonedDateTime.now(ZoneId.systemDefault());
boolean initializing = portData.value == -1;
long sinceLastChange = Duration.between(portData.timestamp, now).toMillis();
Configuration configuration = channel.getConfiguration();
State state = UnDefType.UNDEF;
String groupId = channel.getUID().getGroupId();
if (groupId != null) {
switch (groupId) {
case GROUP_COUNTER:
state = new DecimalType(value);
break;
case GROUP_ANALOG_INPUT:
AnalogInputConfiguration config = configuration.as(AnalogInputConfiguration.class);
long histeresis = config.histeresis / 2;
if ((value < portData.value + histeresis || value > portData.value - histeresis)
&& !initializing) {
return;
}
}
} else {
state = OpenClosedType.OPEN;
triggerPushButtonChannel(channel, EVENT_RELEASED);
if (config2.longPressTime != 0 && sinceLastChange < config2.longPressTime && !initializing) {
triggerPushButtonChannel(channel, EVENT_SHORT_PRESS);
}
state = new DecimalType(value);
break;
case GROUP_DIGITAL_INPUT:
DigitalInputConfiguration config2 = configuration.as(DigitalInputConfiguration.class);
if (config2.debouncePeriod != 0 && now
.isBefore(portData.timestamp.plus(config2.debouncePeriod, ChronoUnit.MILLIS))) {
return;
}
cancelIfPulsing(portData);
if (value == 1) {
state = OpenClosedType.CLOSED;
if (portData.value != -1) {
triggerPushButtonChannel(channel, EVENT_PRESSED);
}
if (config2.longPressTime != 0 && !initializing) {
scheduler.schedule(new LongPressEvaluator(channel, port, portData),
config2.longPressTime, TimeUnit.MILLISECONDS);
} else if (config2.pulsePeriod != 0) {
portData.pulsing = scheduler.scheduleAtFixedRate(() -> {
triggerPushButtonChannel(channel, EVENT_PULSE);
}, config2.pulsePeriod, config2.pulsePeriod, TimeUnit.MILLISECONDS);
if (config2.pulseTimeout != 0) {
scheduler.schedule(() -> {
cancelIfPulsing(portData);
}, config2.pulseTimeout, TimeUnit.MILLISECONDS);
}
}
} else {
state = OpenClosedType.OPEN;
triggerPushButtonChannel(channel, EVENT_RELEASED);
if (config2.longPressTime != 0 && sinceLastChange < config2.longPressTime
&& !initializing) {
triggerPushButtonChannel(channel, EVENT_SHORT_PRESS);
}
}
break;
case GROUP_RELAY_OUTPUT:
state = value == 1 ? OnOffType.ON : OnOffType.OFF;
break;
}
break;
case GROUP_RELAY_OUTPUT:
state = value == 1 ? OnOffType.ON : OnOffType.OFF;
break;
}
updateState(channel.getUID().getId(), state);
if (!initializing) {
updateState(channel.getUID().getId() + PROPERTY_SEPARATOR + TIMESTAMP_CHANNEL_NAME,
new DateTimeType(now));
updateState(channel.getUID().getId() + PROPERTY_SEPARATOR + LAST_STATE_DURATION_CHANNEL_NAME,
new QuantityType<>(sinceLastChange / 1000, SmartHomeUnits.SECOND));
}
updateState(channel.getUID().getId(), state);
if (!initializing) {
updateState(channel.getUID().getId() + PROPERTY_SEPARATOR + TIMESTAMP_CHANNEL_NAME,
new DateTimeType(now));
updateState(channel.getUID().getId() + PROPERTY_SEPARATOR + LAST_STATE_DURATION_CHANNEL_NAME,
new QuantityType<>(sinceLastChange / 1000, SmartHomeUnits.SECOND));
}
portData.value = value;
portData.timestamp = now;
} else {
logger.debug("Received data '{}' for not configured port '{}'", value, port);
}
portData.value = value;
portData.timestamp = now;
} else {
logger.info("Received data '{}' for not configured port '{}'", value, port);
logger.debug("Received data '{}' for not configured channel '{}'", value, port);
}
}

Expand All @@ -235,7 +246,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
String groupId = channelUID.getGroupId();
String channelName = channelUID.getIdWithoutGroup();

if (channelName.chars().allMatch(Character::isDigit)) {
if (channelName.chars().allMatch(Character::isDigit) && groupId != null) {
switch (groupId) {
case GROUP_RELAY_OUTPUT:
if (command instanceof OnOffType) {
Expand Down

0 comments on commit a7ad91b

Please sign in to comment.