2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.dmx.internal.handler;
15 import static org.openhab.binding.dmx.internal.DmxBindingConstants.THING_TYPE_ARTNET_BRIDGE;
17 import java.util.Collections;
20 import org.openhab.binding.dmx.internal.config.ArtnetBridgeHandlerConfiguration;
21 import org.openhab.binding.dmx.internal.dmxoverethernet.ArtnetNode;
22 import org.openhab.binding.dmx.internal.dmxoverethernet.ArtnetPacket;
23 import org.openhab.binding.dmx.internal.dmxoverethernet.DmxOverEthernetHandler;
24 import org.openhab.binding.dmx.internal.dmxoverethernet.IpNode;
25 import org.openhab.core.thing.Bridge;
26 import org.openhab.core.thing.ThingStatus;
27 import org.openhab.core.thing.ThingStatusDetail;
28 import org.openhab.core.thing.ThingTypeUID;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * The {@link ArtnetBridgeHandler} is responsible for handling the communication
36 * @author Jan N. Klug - Initial contribution
38 public class ArtnetBridgeHandler extends DmxOverEthernetHandler {
39 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_ARTNET_BRIDGE);
40 public static final int MIN_UNIVERSE_ID = 0;
41 public static final int MAX_UNIVERSE_ID = 32767;
43 private final Logger logger = LoggerFactory.getLogger(ArtnetBridgeHandler.class);
45 public ArtnetBridgeHandler(Bridge artnetBridge) {
50 protected void updateConfiguration() {
51 ArtnetBridgeHandlerConfiguration configuration = getConfig().as(ArtnetBridgeHandlerConfiguration.class);
53 setUniverse(configuration.universe, MIN_UNIVERSE_ID, MAX_UNIVERSE_ID);
54 packetTemplate.setUniverse(universe.getUniverseId());
56 receiverNodes.clear();
57 if (configuration.address.isEmpty()) {
58 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
59 "Could not initialize sender (address not set)");
61 logger.debug("remote address not set for {}", this.thing.getUID());
65 receiverNodes = IpNode.fromString(configuration.address, ArtnetNode.DEFAULT_PORT);
66 logger.debug("using unicast mode to {} for {}", receiverNodes.toString(), this.thing.getUID());
67 } catch (IllegalArgumentException e) {
68 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
73 if (!configuration.localaddress.isEmpty()) {
74 senderNode = new IpNode(configuration.localaddress);
76 logger.debug("originating address is {} for {}", senderNode, this.thing.getUID());
78 refreshAlways = configuration.refreshmode.equals("always");
80 logger.debug("refresh mode set to always: {}", refreshAlways);
82 updateStatus(ThingStatus.UNKNOWN);
83 super.updateConfiguration();
85 logger.debug("updated configuration for ArtNet bridge {}", this.thing.getUID());
89 public void initialize() {
90 logger.debug("initializing ArtNet bridge {}", this.thing.getUID());
92 packetTemplate = new ArtnetPacket();
93 updateConfiguration();