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.enphase.internal.handler;
15 import static org.openhab.binding.enphase.internal.EnphaseBindingConstants.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.enphase.internal.MessageTranslator;
20 import org.openhab.binding.enphase.internal.dto.InventoryJsonDTO.DeviceDTO;
21 import org.openhab.core.library.types.OpenClosedType;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.types.Command;
25 import org.openhab.core.types.RefreshType;
26 import org.openhab.core.types.UnDefType;
29 * The {@link EnphaseInverterHandler} is responsible for handling commands, which are
30 * sent to one of the channels.
32 * @author Hilbrand Bouwkamp - Initial contribution
35 public class EnphaseRelayHandler extends EnphaseDeviceHandler {
37 public EnphaseRelayHandler(final Thing thing, MessageTranslator messageTranslator) {
38 super(thing, messageTranslator);
42 public void handleCommand(final ChannelUID channelUID, final Command command) {
43 if (command instanceof RefreshType) {
44 final String channelId = channelUID.getId();
47 case RELAY_CHANNEL_RELAY:
48 refreshRelayChannel(lastKnownDeviceState);
50 case RELAY_CHANNEL_LINE_1_CONNECTED:
51 refreshLine1Connect(lastKnownDeviceState);
53 case RELAY_CHANNEL_LINE_2_CONNECTED:
54 refreshLine2Connect(lastKnownDeviceState);
56 case RELAY_CHANNEL_LINE_3_CONNECTED:
57 refreshLine3Connect(lastKnownDeviceState);
60 super.handleCommandRefresh(channelId);
66 private void refreshRelayChannel(@Nullable final DeviceDTO deviceDTO) {
67 updateState(RELAY_CHANNEL_RELAY, deviceDTO == null ? UnDefType.UNDEF
68 : (RELAY_STATUS_CLOSED.equals(deviceDTO.relay) ? OpenClosedType.CLOSED : OpenClosedType.OPEN));
71 private void refreshLine1Connect(@Nullable final DeviceDTO deviceDTO) {
72 updateState(RELAY_CHANNEL_LINE_1_CONNECTED, deviceDTO == null ? UnDefType.UNDEF
73 : (deviceDTO.line1Connected ? OpenClosedType.CLOSED : OpenClosedType.OPEN));
76 private void refreshLine2Connect(@Nullable final DeviceDTO deviceDTO) {
77 updateState(RELAY_CHANNEL_LINE_2_CONNECTED, deviceDTO == null ? UnDefType.UNDEF
78 : (deviceDTO.line2Connected ? OpenClosedType.CLOSED : OpenClosedType.OPEN));
81 private void refreshLine3Connect(@Nullable final DeviceDTO deviceDTO) {
82 updateState(RELAY_CHANNEL_LINE_3_CONNECTED, deviceDTO == null ? UnDefType.UNDEF
83 : (deviceDTO.line3Connected ? OpenClosedType.CLOSED : OpenClosedType.OPEN));
87 public void refreshDeviceState(@Nullable final DeviceDTO deviceDTO) {
88 refreshRelayChannel(deviceDTO);
89 refreshLine1Connect(deviceDTO);
90 refreshLine2Connect(deviceDTO);
91 refreshLine3Connect(deviceDTO);
92 super.refreshDeviceState(deviceDTO);