Skip to content

Commit

Permalink
renamed class SBH20IO to PureSpaIO and added support for Intex PureSp…
Browse files Browse the repository at this point in the history
…a model SJB-HS
  • Loading branch information
jnsbyr committed May 28, 2023
1 parent 6e2c66c commit c185f1f
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 123 deletions.
38 changes: 22 additions & 16 deletions MQTTPublisher.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* project: Intex PureSpa SB-H20 WiFi Controller
* project: Intex PureSpa WiFi Controller
*
* file: MQTTPublisher.cpp
*
Expand Down Expand Up @@ -27,14 +27,14 @@
#include "MQTTPublisher.h"

#include "MQTTClient.h"
#include "SBH20IO.h"
#include "PureSpaIO.h"
#include "NTCThermometer.h"
#include "common.h"


MQTTPublisher::MQTTPublisher(MQTTClient& mqttClient, SBH20IO& poolIO, NTCThermometer& thermometer) :
MQTTPublisher::MQTTPublisher(MQTTClient& mqttClient, PureSpaIO& pureSpaIO, NTCThermometer& thermometer) :
mqttClient(mqttClient),
poolIO(poolIO),
pureSpaIO(pureSpaIO),
thermometer(thermometer),
retainAll(false)
{
Expand Down Expand Up @@ -122,26 +122,32 @@ void MQTTPublisher::loop()
forcedStateUpdate = true;
}

if (poolIO.isOnline())
if (pureSpaIO.isOnline())
{
publishIfDefined(MQTT_TOPIC::BUBBLE, poolIO.isBubbleOn(), SBH20IO::UNDEF::BOOL);
publishIfDefined(MQTT_TOPIC::FILTER, poolIO.isFilterOn(), SBH20IO::UNDEF::BOOL);
publishIfDefined(MQTT_TOPIC::POWER, poolIO.isPowerOn(), SBH20IO::UNDEF::BOOL);
publishIfDefined(MQTT_TOPIC::BUBBLE, pureSpaIO.isBubbleOn(), PureSpaIO::UNDEF::BOOL);
publishIfDefined(MQTT_TOPIC::FILTER, pureSpaIO.isFilterOn(), PureSpaIO::UNDEF::BOOL);
publishIfDefined(MQTT_TOPIC::POWER, pureSpaIO.isPowerOn(), PureSpaIO::UNDEF::BOOL);

bool b = poolIO.isHeaterOn();
if (b != SBH20IO::UNDEF::BOOL)
if (pureSpaIO.getModel() == PureSpaIO::MODEL::SJBHS)
{
mqttClient.publish(MQTT_TOPIC::HEATER, b? (poolIO.isHeaterStandby()? "standby" : "on") : "off", retainAll);
publishIfDefined(MQTT_TOPIC::FILTER, pureSpaIO.isDisinfectionOn(), PureSpaIO::UNDEF::BOOL);
publishIfDefined(MQTT_TOPIC::BUBBLE, pureSpaIO.isJetOn(), PureSpaIO::UNDEF::BOOL);
}

publishIfDefined(MQTT_TOPIC::WATER_ACT, poolIO.getActWaterTempCelsius(), (int)SBH20IO::UNDEF::USHORT);
publishIfDefined(MQTT_TOPIC::WATER_SET, poolIO.getDesiredWaterTempCelsius(), (int)SBH20IO::UNDEF::USHORT);
bool b = pureSpaIO.isHeaterOn();
if (b != PureSpaIO::UNDEF::BOOL)
{
mqttClient.publish(MQTT_TOPIC::HEATER, b? (pureSpaIO.isHeaterStandby()? "standby" : "on") : "off", retainAll);
}

publishIfDefined(MQTT_TOPIC::WATER_ACT, pureSpaIO.getActWaterTempCelsius(), (int)PureSpaIO::UNDEF::USHORT);
publishIfDefined(MQTT_TOPIC::WATER_SET, pureSpaIO.getDesiredWaterTempCelsius(), (int)PureSpaIO::UNDEF::USHORT);

#ifdef SERIAL_DEBUG
publishIfDefined("pool/telegram/led", poolIO.getRawLedValue(), SBH20IO::UNDEF::USHORT);
publishIfDefined("pool/telegram/led", pureSpaIO.getRawLedValue(), PureSpaIO::UNDEF::USHORT);
#endif

unsigned int errorVal = poolIO.getErrorValue();
unsigned int errorVal = pureSpaIO.getErrorValue();
if (errorVal == 0)
{
mqttClient.publish(MQTT_TOPIC::STATE, "online", retainAll, forcedStateUpdate);
Expand All @@ -150,7 +156,7 @@ void MQTTPublisher::loop()
{
mqttClient.publish(MQTT_TOPIC::STATE, "error", retainAll, forcedStateUpdate);
}
mqttClient.publish(MQTT_TOPIC::ERROR, poolIO.getErrorMessage(errorVal).c_str(), retainAll);
mqttClient.publish(MQTT_TOPIC::ERROR, pureSpaIO.getErrorMessage(errorVal).c_str(), retainAll);
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions MQTTPublisher.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* project: Intex PureSpa SB-H20 WiFi Controller
* project: Intex PureSpa WiFi Controller
*
* file: MQTTPublisher.h
*
Expand Down Expand Up @@ -30,19 +30,19 @@
#include <c_types.h>

class MQTTClient;
class SBH20IO;
class PureSpaIO;
class NTCThermometer;


class MQTTPublisher
{
public:
MQTTPublisher(MQTTClient& mqttClient, SBH20IO& poolIO, NTCThermometer& thermometer);
MQTTPublisher(MQTTClient& mqttClient, PureSpaIO& PureSpaIO, NTCThermometer& thermometer);

public:
void setRetainAll(bool retain);
bool isRetainAll() const;

public:
void loop();

Expand All @@ -61,7 +61,7 @@ class MQTTPublisher

private:
MQTTClient& mqttClient;
SBH20IO& poolIO;
PureSpaIO& pureSpaIO;
NTCThermometer& thermometer;
bool retainAll;

Expand Down
Loading

0 comments on commit c185f1f

Please sign in to comment.