2 * Copyright (c) 2010-2024 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.pentair.internal.handler;
15 import static org.openhab.binding.pentair.internal.PentairBindingConstants.*;
17 import org.openhab.binding.pentair.internal.PentairBindingConstants;
18 import org.openhab.binding.pentair.internal.PentairPacket;
19 import org.openhab.binding.pentair.internal.PentairPacketIntellichlor;
20 import org.openhab.core.library.types.DecimalType;
21 import org.openhab.core.thing.ChannelUID;
22 import org.openhab.core.thing.Thing;
23 import org.openhab.core.thing.ThingStatus;
24 import org.openhab.core.types.Command;
25 import org.openhab.core.types.RefreshType;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 * The {@link PentairIntelliChlorHandler} is responsible for implementation of the Intellichlor Salt generator. It will
32 * Intellichlor commands and set the appropriate channel states. There are currently no commands implemented for this
33 * Thing to receive from the framework.
35 * @author Jeff James - Initial contribution
37 public class PentairIntelliChlorHandler extends PentairBaseThingHandler {
38 private final Logger logger = LoggerFactory.getLogger(PentairIntelliChlorHandler.class);
40 protected PentairPacketIntellichlor pic3cur = new PentairPacketIntellichlor();
41 protected PentairPacketIntellichlor pic4cur = new PentairPacketIntellichlor();
43 public PentairIntelliChlorHandler(Thing thing) {
48 public void initialize() {
49 logger.debug("Initializing IntelliChlor - Thing ID: {}.", this.getThing().getUID());
51 id = 0; // Intellichlor doesn't have ID
53 updateStatus(ThingStatus.ONLINE);
57 public void dispose() {
58 logger.debug("Thing {} disposed.", getThing().getUID());
62 public void handleCommand(ChannelUID channelUID, Command command) {
63 if (command instanceof RefreshType) {
64 logger.debug("IntelliChlor received refresh command");
65 updateChannel(channelUID.getId(), null);
70 public void processPacketFrom(PentairPacket p) {
71 PentairPacketIntellichlor pic = (PentairPacketIntellichlor) p;
73 switch (pic.getLength()) {
75 if (pic.getCmd() != 0x11) { // only packets with 0x11 have valid saltoutput numbers.
79 PentairPacketIntellichlor pic3Old = pic3cur;
82 updateChannel(INTELLICHLOR_SALTOUTPUT, pic3Old);
86 if (pic.getCmd() != 0x12) {
90 PentairPacketIntellichlor pic4Old = pic4cur;
93 updateChannel(INTELLICHLOR_SALINITY, pic4Old);
98 logger.debug("Intellichlor command: {}", pic);
102 * Helper function to compare and update channel if needed. The class variables p29_cur and phsp_cur are used to
103 * determine the appropriate state of the channel.
105 * @param channel name of channel to be updated, corresponds to channel name in {@link PentairBindingConstants}
106 * @param p Packet representing the former state. If null, no compare is done and state is updated.
108 public void updateChannel(String channel, PentairPacket p) {
109 PentairPacketIntellichlor pic = (PentairPacketIntellichlor) p;
112 case INTELLICHLOR_SALINITY:
113 if (pic == null || (pic.salinity != pic4cur.salinity)) {
114 updateState(channel, new DecimalType(pic4cur.salinity));
117 case INTELLICHLOR_SALTOUTPUT:
118 if (pic == null || (pic.saltoutput != pic3cur.saltoutput)) {
119 updateState(channel, new DecimalType(pic3cur.saltoutput));