Skip to content

Commit

Permalink
[caddx] Correct thing status on bridge initialization (openhab#10317)
Browse files Browse the repository at this point in the history
* Log event message construction improved

Signed-off-by: Georgios Moutsos <georgios.moutsos@gmail.com>

* Changed level to debug for some logs

Signed-off-by: Georgios Moutsos <georgios.moutsos@gmail.com>

* Added status request commands to b send when the bridge initializes

Signed-off-by: Georgios Moutsos <georgios.moutsos@gmail.com>

* Don't change the label of the zone

Signed-off-by: Georgios Moutsos <georgios.moutsos@gmail.com>

* Removed comment

Signed-off-by: Georgios Moutsos <georgios.moutsos@gmail.com>
Signed-off-by: John Marshall <john.marshall.au@gmail.com>
  • Loading branch information
jossuar authored and themillhousegroup committed May 10, 2021
1 parent cef0e0a commit eca5789
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
public class CaddxBridgeHandler extends BaseBridgeHandler implements CaddxPanelListener {
private final Logger logger = LoggerFactory.getLogger(CaddxBridgeHandler.class);

static final byte[] DISCOVERY_PARTITION_STATUS_REQUEST_0 = { 0x26, 0x00 };
static final byte[] DISCOVERY_ZONES_SNAPSHOT_REQUEST_00 = { 0x25, 0x00 }; // 1 - 16
static final byte[] DISCOVERY_ZONES_SNAPSHOT_REQUEST_10 = { 0x25, 0x01 }; // 17 - 32
static final byte[] DISCOVERY_ZONES_SNAPSHOT_REQUEST_20 = { 0x25, 0x02 }; // 33 - 48
Expand Down Expand Up @@ -156,8 +155,13 @@ public void initialize() {
comm.transmit(new CaddxMessage(DISCOVERY_ZONES_SNAPSHOT_REQUEST_B0, false));

// Send discovery commands for the partitions
comm.transmit(new CaddxMessage(DISCOVERY_PARTITION_STATUS_REQUEST_0, false));
comm.transmit(new CaddxMessage(DISCOVERY_PARTITIONS_SNAPSHOT_REQUEST, false));

// Send status commands to the zones and partitions
thingZonesMap.forEach((k, v) -> sendCommand(CaddxBindingConstants.ZONE_STATUS_REQUEST,
k.subtract(BigDecimal.ONE).toString()));
thingPartitionsMap.forEach((k, v) -> sendCommand(CaddxBindingConstants.PARTITION_STATUS_REQUEST,
k.subtract(BigDecimal.ONE).toString()));
}

// list all channels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,34 @@ public String toString() {
int eventType = Integer.parseInt(type);
logger.trace("eventType received: {}", eventType);
LogEventType logEventType = LogEventType.valueOfLogEventType(eventType);
if (logEventType == null) {
return "Unknown log event type received";
}

// Date
sb.append(String.format("%02d", Integer.parseInt(day))).append('-')
.append(String.format("%02d", Integer.parseInt(month))).append(' ')
.append(String.format("%02d", Integer.parseInt(hour))).append(':')
.append(String.format("%02d", Integer.parseInt(minute))).append(' ');

sb.append(logEventType.description);
if (logEventType.isPartitionValid) {
sb.append(" Partition ").append(Integer.parseInt(partition) + 1);
}
if (logEventType == null) {
sb.append("Unknown log event type");
} else {
sb.append(logEventType.description);
if (logEventType.isPartitionValid) {
sb.append(" Partition ").append(Integer.parseInt(partition) + 1);
}

switch (logEventType.zud) {
case None:
break;
case Zone:
sb.append(" Zone ").append(Integer.parseInt(zud) + 1);
break;
case User:
sb.append(" User ").append(Integer.parseInt(zud) + 1);
break;
case Device:
sb.append(" Device ").append(zud);
break;
switch (logEventType.zud) {
case None:
break;
case Zone:
sb.append(" Zone ").append(Integer.parseInt(zud) + 1);
break;
case User:
sb.append(" User ").append(Integer.parseInt(zud) + 1);
break;
case Device:
sb.append(" Device ").append(zud);
break;
}
}

return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void updateChannel(ChannelUID channelUID, String data) {

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
logger.trace("handleCommand(): Command Received - {} {}.", channelUID, command);
logger.debug("handleCommand(): Command Received - {} {}.", channelUID, command);

String cmd = null;
String data = null;
Expand Down Expand Up @@ -167,10 +167,12 @@ private void handleLogEventMessage(CaddxMessage message) {

// get the channel id from the map
HashMap<String, String> logMap = panelLogMessagesMap;
String id = logMap.get(eventNumberString);
if (logMap != null && id != null) {
ChannelUID channelUID = new ChannelUID(getThing().getUID(), id);
updateChannel(channelUID, logEventMessage.toString());
if (logMap != null) {
String id = logMap.get(eventNumberString);
if (id != null) {
ChannelUID channelUID = new ChannelUID(getThing().getUID(), id);
updateChannel(channelUID, logEventMessage.toString());
}
}

if (communicatorStackPointer != null && eventNumberString.equals(communicatorStackPointer)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public ThingHandlerZone(Thing thing) {
@Override
public void updateChannel(ChannelUID channelUID, String data) {
if (channelUID.getId().equals(CaddxBindingConstants.ZONE_NAME)) {
getThing().setLabel(data);
updateState(channelUID, new StringType(data));

logger.trace(" updateChannel: {} = {}", channelUID, data);
Expand All @@ -71,7 +70,7 @@ public void updateChannel(ChannelUID channelUID, String data) {

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
logger.trace("handleCommand(): Command Received - {} {}.", channelUID, command);
logger.debug("handleCommand(): Command Received - {} {}.", channelUID, command);

String cmd1 = null;
String cmd2 = null;
Expand Down Expand Up @@ -124,9 +123,9 @@ public void caddxEventReceived(CaddxEvent event, Thing thing) {
logger.trace(" updateChannel: {} = {}", channelUID, value);
}
}

updateStatus(ThingStatus.ONLINE);
}

updateStatus(ThingStatus.ONLINE);
}

@Override
Expand Down

0 comments on commit eca5789

Please sign in to comment.