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;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
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.DmxOverEthernetPacket;
25 import org.openhab.binding.dmx.internal.dmxoverethernet.IpNode;
26 import org.openhab.core.thing.Bridge;
27 import org.openhab.core.thing.ThingStatus;
28 import org.openhab.core.thing.ThingStatusDetail;
29 import org.openhab.core.thing.ThingTypeUID;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * The {@link ArtnetBridgeHandler} is responsible for handling the communication
37 * @author Jan N. Klug - Initial contribution
40 public class ArtnetBridgeHandler extends DmxOverEthernetHandler {
41 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_ARTNET_BRIDGE);
42 public static final int MIN_UNIVERSE_ID = 0;
43 public static final int MAX_UNIVERSE_ID = 32767;
45 private final Logger logger = LoggerFactory.getLogger(ArtnetBridgeHandler.class);
47 public ArtnetBridgeHandler(Bridge artnetBridge) {
52 protected void updateConfiguration() {
53 ArtnetBridgeHandlerConfiguration configuration = getConfig().as(ArtnetBridgeHandlerConfiguration.class);
55 setUniverse(configuration.universe, MIN_UNIVERSE_ID, MAX_UNIVERSE_ID);
56 DmxOverEthernetPacket packetTemplate = this.packetTemplate;
57 if (packetTemplate == null) {
58 packetTemplate = new ArtnetPacket();
59 this.packetTemplate = packetTemplate;
61 packetTemplate.setUniverse(universe.getUniverseId());
63 receiverNodes.clear();
64 if (configuration.address.isEmpty()) {
65 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
66 "Could not initialize sender (address not set)");
68 logger.debug("remote address not set for {}", this.thing.getUID());
72 receiverNodes = IpNode.fromString(configuration.address, ArtnetNode.DEFAULT_PORT);
73 logger.debug("using unicast mode to {} for {}", receiverNodes.toString(), this.thing.getUID());
74 } catch (IllegalArgumentException e) {
75 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
80 if (!configuration.localaddress.isEmpty()) {
81 senderNode = new IpNode(configuration.localaddress);
83 logger.debug("originating address is {} for {}", senderNode, this.thing.getUID());
85 refreshAlways = configuration.refreshmode.equals("always");
87 logger.debug("refresh mode set to always: {}", refreshAlways);
89 updateStatus(ThingStatus.UNKNOWN);
90 super.updateConfiguration();
92 logger.debug("updated configuration for ArtNet bridge {}", this.thing.getUID());
96 public void initialize() {
97 logger.debug("initializing ArtNet bridge {}", this.thing.getUID());
99 packetTemplate = new ArtnetPacket();
100 updateConfiguration();