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.pentair.internal.handler;
15 import static org.openhab.binding.pentair.internal.PentairBindingConstants.*;
17 import java.math.BigDecimal;
19 import org.openhab.binding.pentair.internal.PentairBindingConstants;
20 import org.openhab.binding.pentair.internal.PentairPacket;
21 import org.openhab.binding.pentair.internal.PentairPacketPumpStatus;
22 import org.openhab.core.library.types.DecimalType;
23 import org.openhab.core.library.types.OnOffType;
24 import org.openhab.core.thing.ChannelUID;
25 import org.openhab.core.thing.Thing;
26 import org.openhab.core.thing.ThingStatus;
27 import org.openhab.core.types.Command;
28 import org.openhab.core.types.RefreshType;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * The {@link PentairIntelliFloHandler} is responsible for implementation of the Intelliflo Pump. This will
35 * status packets to set the stat for various channels.
37 * @author Jeff James - Initial contribution
39 public class PentairIntelliFloHandler extends PentairBaseThingHandler {
41 private final Logger logger = LoggerFactory.getLogger(PentairIntelliFloHandler.class);
42 protected PentairPacketPumpStatus ppscur = new PentairPacketPumpStatus();
44 public PentairIntelliFloHandler(Thing thing) {
49 public void initialize() {
50 logger.debug("Initializing Intelliflo - Thing ID: {}.", this.getThing().getUID());
52 id = ((BigDecimal) getConfig().get("id")).intValue();
54 updateStatus(ThingStatus.ONLINE);
58 public void dispose() {
59 logger.debug("Thing {} disposed.", getThing().getUID());
63 public void handleCommand(ChannelUID channelUID, Command command) {
64 if (command instanceof RefreshType) {
65 logger.debug("Intellflo received refresh command");
66 updateChannel(channelUID.getId(), null);
71 public void processPacketFrom(PentairPacket p) {
72 switch (p.getAction()) {
73 case 1: // Pump command - A5 00 10 60 01 02 00 20
74 logger.trace("Pump command (ack): {}: ", p);
76 case 4: // Pump control panel on/off
77 logger.trace("Turn pump control panel (ack) {}: {} - {}", p.getSource(),
78 p.getByte(PentairPacket.STARTOFDATA), p);
80 case 5: // Set pump mode
81 logger.trace("Set pump mode (ack) {}: {} - {}", p.getSource(), p.getByte(PentairPacket.STARTOFDATA), p);
83 case 6: // Set run mode
84 logger.trace("Set run mode (ack) {}: {} - {}", p.getSource(), p.getByte(PentairPacket.STARTOFDATA), p);
86 case 7: // Pump status (after a request)
87 if (p.getLength() != 15) {
88 logger.debug("Expected length of 15: {}", p);
93 * P: A500 d=10 s=60 c=07 l=0f 0A0602024A08AC120000000A000F22 <028A>
96 * PMP 02 ? drive state
108 logger.debug("Pump status: {}", p);
111 * Save the previous state of the packet (p29cur) into a temp variable (p29old)
112 * Update the current state to the new packet we just received.
113 * Then call updateChannel which will compare the previous state (now p29old) to the new state (p29cur)
114 * to determine if updateState needs to be called
116 PentairPacketPumpStatus ppsOld = ppscur;
117 ppscur = new PentairPacketPumpStatus(p);
119 updateChannel(INTELLIFLO_RUN, ppsOld);
120 updateChannel(INTELLIFLO_MODE, ppsOld);
121 updateChannel(INTELLIFLO_DRIVESTATE, ppsOld);
122 updateChannel(INTELLIFLO_POWER, ppsOld);
123 updateChannel(INTELLIFLO_RPM, ppsOld);
124 updateChannel(INTELLIFLO_PPC, ppsOld);
125 updateChannel(INTELLIFLO_ERROR, ppsOld);
126 updateChannel(INTELLIFLO_TIMER, ppsOld);
130 logger.debug("Unhandled Intelliflo command: {}", p.toString());
136 * Helper function to compare and update channel if needed. The class variables p29_cur and phsp_cur are used to
137 * determine the appropriate state of the channel.
139 * @param channel name of channel to be updated, corresponds to channel name in {@link PentairBindingConstants}
140 * @param p Packet representing the former state. If null, no compare is done and state is updated.
142 public void updateChannel(String channel, PentairPacket p) {
143 // Only called from this class's processPacketFrom, so we are confident this will be a PentairPacketPumpStatus
144 PentairPacketPumpStatus pps = (PentairPacketPumpStatus) p;
148 if (pps == null || (pps.run != ppscur.run)) {
149 updateState(channel, (ppscur.run) ? OnOffType.ON : OnOffType.OFF);
152 case INTELLIFLO_MODE:
153 if (pps == null || (pps.mode != ppscur.mode)) {
154 updateState(channel, new DecimalType(ppscur.mode));
157 case INTELLIFLO_DRIVESTATE:
158 if (pps == null || (pps.drivestate != ppscur.drivestate)) {
159 updateState(channel, new DecimalType(ppscur.drivestate));
162 case INTELLIFLO_POWER:
163 if (pps == null || (pps.power != ppscur.power)) {
164 updateState(channel, new DecimalType(ppscur.power));
168 if (pps == null || (pps.rpm != ppscur.rpm)) {
169 updateState(channel, new DecimalType(ppscur.rpm));
173 if (pps == null || (pps.ppc != ppscur.ppc)) {
174 updateState(channel, new DecimalType(ppscur.ppc));
177 case INTELLIFLO_ERROR:
178 if (pps == null || (pps.error != ppscur.error)) {
179 updateState(channel, new DecimalType(ppscur.error));
182 case INTELLIFLO_TIMER:
183 if (pps == null || (pps.timer != ppscur.timer)) {
184 updateState(channel, new DecimalType(ppscur.timer));