Search in sources :

Example 11 with ChannelUID

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);
        }
    }
}
Also used : ChannelUID(org.openhab.core.thing.ChannelUID) Channel(org.openhab.core.thing.Channel) PercentType(org.openhab.core.library.types.PercentType) Thing(org.openhab.core.thing.Thing)

Example 12 with ChannelUID

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);
        }
    }
}
Also used : ChannelUID(org.openhab.core.thing.ChannelUID) Channel(org.openhab.core.thing.Channel) Thing(org.openhab.core.thing.Thing)

Example 13 with ChannelUID

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;
    }
}
Also used : HashMap(java.util.HashMap) ChannelUID(org.openhab.core.thing.ChannelUID)

Example 14 with ChannelUID

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);
    }
}
Also used : CaddxMessageType(org.openhab.binding.caddx.internal.CaddxMessageType) CaddxProperty(org.openhab.binding.caddx.internal.CaddxProperty) ChannelUID(org.openhab.core.thing.ChannelUID) CaddxMessage(org.openhab.binding.caddx.internal.CaddxMessage)

Example 15 with ChannelUID

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);
        }
    }
}
Also used : ChannelUID(org.openhab.core.thing.ChannelUID) Thing(org.openhab.core.thing.Thing)

Aggregations

ChannelUID (org.openhab.core.thing.ChannelUID)573 Channel (org.openhab.core.thing.Channel)185 Test (org.junit.jupiter.api.Test)154 Thing (org.openhab.core.thing.Thing)125 ChannelTypeUID (org.openhab.core.thing.type.ChannelTypeUID)88 ArrayList (java.util.ArrayList)80 State (org.openhab.core.types.State)79 StringType (org.openhab.core.library.types.StringType)68 ThingUID (org.openhab.core.thing.ThingUID)67 Nullable (org.eclipse.jdt.annotation.Nullable)59 DecimalType (org.openhab.core.library.types.DecimalType)59 ThingBuilder (org.openhab.core.thing.binding.builder.ThingBuilder)55 Command (org.openhab.core.types.Command)55 HashMap (java.util.HashMap)50 Bridge (org.openhab.core.thing.Bridge)47 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)46 Configuration (org.openhab.core.config.core.Configuration)46 StateOption (org.openhab.core.types.StateOption)43 ThingStatus (org.openhab.core.thing.ThingStatus)40 OnOffType (org.openhab.core.library.types.OnOffType)39