use of org.openhab.core.thing.ChannelUID in project openhab-addons by openhab.
the class CBusLightHandler method updateGroup.
public void updateGroup(int updateApplicationId, int updateGroupId, String value) {
if (updateGroupId == groupId && updateApplicationId == applicationId) {
Thing thing = getThing();
Channel channel = thing.getChannel(CBusBindingConstants.CHANNEL_STATE);
Channel channelLevel = thing.getChannel(CBusBindingConstants.CHANNEL_LEVEL);
if (channel != null && channelLevel != null) {
ChannelUID channelUID = channel.getUID();
ChannelUID channelLevelUID = channelLevel.getUID();
logger.debug("channel UID {} level UID {}", channelUID, channelLevelUID);
if ("on".equalsIgnoreCase(value) || "255".equalsIgnoreCase(value)) {
updateState(channelUID, OnOffType.ON);
updateState(channelLevelUID, new PercentType(100));
} else if ("off".equalsIgnoreCase(value) || "0".equalsIgnoreCase(value)) {
updateState(channelUID, OnOffType.OFF);
updateState(channelLevelUID, new PercentType(0));
} else {
try {
int v = Integer.parseInt(value);
updateState(channelUID, v > 0 ? OnOffType.ON : OnOffType.OFF);
updateState(channelLevelUID, new PercentType((int) (v * 100 / 255.0)));
} catch (NumberFormatException e) {
logger.warn("Invalid value presented to channel {}. Received {}, expected On/Off", channelUID, value);
}
}
logger.debug("Updating CBus Lighting Group {} with value {}", thing.getUID(), value);
} else {
logger.debug("Failed to Update CBus Lighting Group {} with value {}: No Channel", thing.getUID(), value);
}
}
}
use of org.openhab.core.thing.ChannelUID in project openhab-addons by openhab.
the class CBusTemperatureHandler method updateGroup.
public void updateGroup(int updateApplicationId, int updateGroupId, String value) {
if (updateGroupId == groupId && updateApplicationId == applicationId) {
Thing thing = getThing();
Channel channel = thing.getChannel(CBusBindingConstants.CHANNEL_TEMP);
if (channel != null) {
ChannelUID channelUID = channel.getUID();
updateState(channelUID, new QuantityType<>(Double.parseDouble(value), CELSIUS));
logger.trace("Updating CBus Temperature Group {} with value {}", thing.getUID(), value);
} else {
logger.trace("Failed to Update CBus Temperature Group {} with value {}: No Channel", thing.getUID(), value);
}
}
}
use of org.openhab.core.thing.ChannelUID in project openhab-addons by openhab.
the class ThingHandlerPanel method handleLogEventMessage.
/*
* This function handles the panel log messages.
* If the received event_number matches our communication stack pointer then this is the last panel message. The
* channel gets updated and the required log message requests are generated for the update of the other log message
* channels
*/
private void handleLogEventMessage(CaddxMessage message) {
// Get the bridge handler
CaddxBridgeHandler bridgeHandler = getCaddxBridgeHandler();
if (bridgeHandler == null) {
return;
}
String eventNumberString = message.getPropertyById("panel_log_event_number");
String eventSizeString = message.getPropertyById("panel_log_event_size");
// build the message
LogEventMessage logEventMessage = new LogEventMessage(message);
logger.trace("Log_event: {}", logEventMessage);
// get the channel id from the map
HashMap<String, String> logMap = panelLogMessagesMap;
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)) {
HashMap<String, String> map = new HashMap<String, String>();
int eventNumber = Integer.parseInt(eventNumberString);
int eventSize = Integer.parseInt(eventSizeString);
// Retrieve at maximum the 10 last log messages from the panel
int messagesToRetrieve = Math.min(eventSize, 10);
for (int i = 1; i < messagesToRetrieve; i++) {
eventNumber--;
if (eventNumber < 0) {
eventNumber = eventSize;
}
map.put(Integer.toString(eventNumber), "panel_log_message_n_" + i);
bridgeHandler.sendCommand(CaddxMessageContext.COMMAND, CaddxBindingConstants.PANEL_LOG_EVENT_REQUEST, Integer.toString(eventNumber));
}
communicatorStackPointer = null;
panelLogMessagesMap = map;
}
}
use of org.openhab.core.thing.ChannelUID in project openhab-addons by openhab.
the class ThingHandlerPanel method caddxEventReceived.
@Override
public void caddxEventReceived(CaddxEvent event, Thing thing) {
logger.trace("caddxEventReceived(): Event Received - {}.", event);
if (getThing().equals(thing)) {
CaddxMessage message = event.getCaddxMessage();
CaddxMessageType mt = message.getCaddxMessageType();
ChannelUID channelUID = null;
for (CaddxProperty p : mt.properties) {
if (!p.getId().isEmpty()) {
String value = message.getPropertyById(p.getId());
channelUID = new ChannelUID(getThing().getUID(), p.getId());
updateChannel(channelUID, value);
logger.trace("Updating panel channel: {}", channelUID.getAsString());
}
}
// Log event messages have special handling
if (CaddxMessageType.SYSTEM_STATUS_MESSAGE.equals(mt)) {
handleSystemStatusMessage(message);
} else if (CaddxMessageType.LOG_EVENT_MESSAGE.equals(mt)) {
handleLogEventMessage(message);
} else if (CaddxMessageType.ZONES_SNAPSHOT_MESSAGE.equals(mt)) {
handleZonesSnapshotMessage(message);
}
updateStatus(ThingStatus.ONLINE);
}
}
use of org.openhab.core.thing.ChannelUID in project openhab-addons by openhab.
the class ThingHandlerPanel method handleZonesSnapshotMessage.
private void handleZonesSnapshotMessage(CaddxMessage message) {
// Get the bridge handler
CaddxBridgeHandler bridgeHandler = getCaddxBridgeHandler();
if (bridgeHandler == null) {
return;
}
int zoneOffset = Integer.parseInt(message.getPropertyById("zone_offset"));
for (int i = 1; i <= 16; i++) {
int zoneNumber = zoneOffset * 16 + i;
String zoneFaulted = message.getPropertyById("zone_" + i + "_faulted");
String zoneBypassed = message.getPropertyById("zone_" + i + "_bypassed");
String zoneTrouble = message.getPropertyById("zone_" + i + "_trouble");
String zoneAlarmMemory = message.getPropertyById("zone_" + i + "_alarm_memory");
logger.debug("Flags for zone {}. faulted:{}, bypassed:{}, trouble:{}, alarm_memory:{}", zoneNumber, zoneFaulted, zoneBypassed, zoneTrouble, zoneAlarmMemory);
// Get thing
Thing thing = bridgeHandler.findThing(CaddxThingType.ZONE, null, zoneNumber, null);
if (thing != null) {
ChannelUID channelUID;
logger.debug("Thing found for zone {}.", zoneNumber);
channelUID = new ChannelUID(thing.getUID(), "zone_faulted");
updateChannel(channelUID, zoneFaulted);
channelUID = new ChannelUID(thing.getUID(), "zone_bypassed");
updateChannel(channelUID, zoneBypassed);
channelUID = new ChannelUID(thing.getUID(), "zone_trouble");
updateChannel(channelUID, zoneTrouble);
channelUID = new ChannelUID(thing.getUID(), "zone_alarm_memory");
updateChannel(channelUID, zoneAlarmMemory);
}
}
}
Aggregations