int currentRoom = 0;
String currentRoomName = null;
while ((m = c.reqObjectProperties(Message.OBJ_TYPE_UNIT, objnum, 1, ObjectProperties.FILTER_1_NAMED,
ObjectProperties.FILTER_2_AREA_ALL, ObjectProperties.FILTER_3_ANY_LOAD)).getMessageType() == Message.MESG_TYPE_OBJ_PROP) {
UnitProperties o = ((UnitProperties) m);
objnum = o.getNumber();
boolean isInRoom = false;
boolean isRoomController = false;
if(o.getUnitType() == UnitProperties.UNIT_TYPE_HLC_ROOM ||
o.getObjectType() == UnitProperties.UNIT_TYPE_VIZIARF_ROOM){
currentRoom = objnum;
//Lights_LivingRoom
currentRoomName = cleanString(groupName + "_" + o.getName());
//Make Sure we don't already have a group called this
currentRoomName = addUniqueGroup(currentRoomName);
groups.append(String.format(groupString,currentRoomName,o.getName(),groupName));
rooms.put(currentRoomName, new LinkedList<SiteItem>());
isInRoom = true;
isRoomController = true;
} else if(objnum < currentRoom + 8){
isInRoom = true;
}
//clean the name to remove things like spaces
String objName = cleanString(o.getName());
String group = isInRoom ? currentRoomName : groupName;
//name will be the room name for the first device and roomName_deviceName for sub devices
String name = isRoomController ? objName : group + "_" + objName;
//the label does not have to be cleaned, so set it from the object
String label = o.getName() + " [%d%%]";
SiteItem light = new SiteItem(name, o.getName(), label);
items.append(String.format(itemString,"Dimmer",name + "_Switch",label,group,objnum));
if(isRoomController)
items.append(String.format(itemString,"String",name + "_String",o.getName() + " [%s]",group,objnum));
if(isInRoom)
rooms.get(currentRoomName).add(light);
else
lights.add(light);