private class MessageListener implements HeatmiserEventListener {
HeatmiserThermostat thermostatPacket = null;
@Override
public void packetReceived(EventObject event, byte[] packet) {
thermostatPacket = new HeatmiserThermostat();
if(thermostatPacket.setData(packet) == false)
return;
for (HeatmiserThermostat thermostat: thermostatTable) {
if(thermostat.getAddress() == thermostatPacket.getAddress()) {
// Found the thermostat
thermostat.setData(packet);
processItems(thermostat);
return;
}
}
// Thermostat not found in the list of known devices
// Create a new thermostat and add it to the array
HeatmiserThermostat newThermostat = null;
switch(thermostatPacket.getModel()) {
case PRT:
case PRTE:
newThermostat = new HeatmiserPRT();
break;
case PRTHW:
newThermostat = new HeatmiserPRTHW();
break;
default:
logger.error("Unknown heatmiser thermostat type {} at address {}", thermostatPacket.getModel(), thermostatPacket.getAddress());
break;
}
// Add the new thermostat to the list
if(newThermostat != null) {
newThermostat.setData(packet);
thermostatTable.add(newThermostat);
processItems(newThermostat);
}
}