use of org.openhab.binding.gce.internal.model.PortData in project openhab-addons by openhab.
the class Ipx800v3Handler method dataReceived.
@Override
public void dataReceived(String port, double value) {
updateStatus(ThingStatus.ONLINE);
Channel channel = thing.getChannel(PortDefinition.asChannelId(port));
if (channel != null) {
String channelId = channel.getUID().getId();
String groupId = channel.getUID().getGroupId();
PortData portData = portDatas.get(channelId);
if (portData != null && groupId != null) {
ZonedDateTime now = ZonedDateTime.now(ZoneId.systemDefault());
long sinceLastChange = Duration.between(portData.getTimestamp(), now).toMillis();
Configuration configuration = channel.getConfiguration();
PortDefinition portDefinition = PortDefinition.fromGroupId(groupId);
if (ignoreCondition(value, portData, configuration, portDefinition, now)) {
logger.debug("Ignore condition met for port '{}' with data '{}'", port, value);
return;
}
logger.debug("About to update port '{}' with data '{}'", port, value);
State state = UnDefType.UNDEF;
switch(portDefinition) {
case COUNTER:
state = new DecimalType(value);
break;
case RELAY:
state = value == 1 ? OnOffType.ON : OnOffType.OFF;
break;
case ANALOG:
state = new DecimalType(value);
updateState(channelId + PROPERTY_SEPARATOR + CHANNEL_VOLTAGE, new QuantityType<>(value * ANALOG_SAMPLING, Units.VOLT));
break;
case CONTACT:
DigitalInputConfiguration config = configuration.as(DigitalInputConfiguration.class);
portData.cancelPulsing();
state = value == 1 ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
switch((OpenClosedType) state) {
case CLOSED:
if (config.longPressTime != 0 && !portData.isInitializing()) {
scheduler.schedule(new LongPressEvaluator(channel, port, portData), config.longPressTime, TimeUnit.MILLISECONDS);
} else if (config.pulsePeriod != 0) {
portData.setPulsing(scheduler.scheduleWithFixedDelay(() -> {
triggerPushButtonChannel(channel, EVENT_PULSE);
}, config.pulsePeriod, config.pulsePeriod, TimeUnit.MILLISECONDS));
if (config.pulseTimeout != 0) {
scheduler.schedule(portData::cancelPulsing, config.pulseTimeout, TimeUnit.MILLISECONDS);
}
}
break;
case OPEN:
if (!portData.isInitializing() && config.longPressTime != 0 && sinceLastChange < config.longPressTime) {
triggerPushButtonChannel(channel, EVENT_SHORT_PRESS);
}
break;
}
if (!portData.isInitializing()) {
triggerPushButtonChannel(channel, value == 1 ? EVENT_PRESSED : EVENT_RELEASED);
}
break;
}
updateState(channelId, state);
if (!portData.isInitializing()) {
updateState(channelId + PROPERTY_SEPARATOR + CHANNEL_LAST_STATE_DURATION, new QuantityType<>(sinceLastChange / 1000, Units.SECOND));
}
portData.setData(value, now);
} else {
logger.debug("Received data '{}' for not configured port '{}'", value, port);
}
} else {
logger.debug("Received data '{}' for not configured channel '{}'", value, port);
}
}
use of org.openhab.binding.gce.internal.model.PortData in project openhab-addons by openhab.
the class Ipx800v3Handler method channelUnlinked.
@Override
public void channelUnlinked(ChannelUID channelUID) {
super.channelUnlinked(channelUID);
PortData portData = portDatas.remove(channelUID.getId());
if (portData != null) {
portData.destroy();
}
}
use of org.openhab.binding.gce.internal.model.PortData in project openhab-addons by openhab.
the class Ipx800v3Handler method channelLinked.
@Override
public void channelLinked(ChannelUID channelUID) {
logger.debug("channelLinked: {}", channelUID);
final String channelId = channelUID.getId();
if (isValidPortId(channelUID)) {
Channel channel = thing.getChannel(channelUID);
if (channel != null) {
PortData data = new PortData();
portDatas.put(channelId, data);
}
}
}
Aggregations