Skip to content

Commit

Permalink
Merge pull request #4647 from tonhuisman/feature/P093-add-get-config-…
Browse files Browse the repository at this point in the history
…value-support

[P093] Add support for retrieving all device values
  • Loading branch information
TD-er committed May 7, 2023
2 parents c9e3ad7 + 4de3759 commit dae038d
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 15 deletions.
7 changes: 7 additions & 0 deletions docs/source/Plugin/P093.rst
Expand Up @@ -109,6 +109,13 @@ Please check `here <https://espeasy.readthedocs.io/en/latest/Reference/Command.h

Please `check <https://community.openhab.org/t/mitsubishi-heat-pump/91765>`_ for an example integration with openHAB.

Get Config Values
-----------------

Get Config Values retrieves values or settings from the sensor or plugin, and can be used in Rules, Display plugins, Formula's etc. The square brackets **are** part of the variable. Replace ``<taskname>`` by the **Name** of the task.

.. include:: P093_config_values.repl

Special thanks
--------------

Expand Down
54 changes: 54 additions & 0 deletions docs/source/Plugin/P093_config_values.repl
@@ -0,0 +1,54 @@
.. csv-table::
:header: "Config value", "Information"
:widths: 20, 30

"
| ``[<taskname>#roomTemperature]``
","
| Value as received from the connected device, includes 1 decimal.
"
"
| ``[<taskname>#wideVane]``
","
| Value as received from the connected device.
"
"
| ``[<taskname>#power]``
","
| Value as received from the connected device.
"
"
| ``[<taskname>#mode]``
","
| Value as received from the connected device.
"
"
| ``[<taskname>#fan]``
","
| Value as received from the connected device.
"
"
| ``[<taskname>#vane]``
","
| Value as received from the connected device.
"
"
| ``[<taskname>#iSee]``
","
| Value as received from the connected device, 1 = on/enabled, 0 = off/disabled.
"
"
| ``[<taskname>#temperature]``
","
| Value as received from the connected device, includes 1 decimal.
"
"
| ``[<taskname>#operating]``
","
| Value as received from the connected device, when ``Include AC status`` is enabled, 1 = on, 0 = off.
"
"
| ``[<taskname>#compressorFrequency]``
","
| Value as received from the connected device, when ``Include AC status`` is enabled.
"
33 changes: 32 additions & 1 deletion src/_P093_MitsubishiHP.ino
Expand Up @@ -2,9 +2,30 @@
#ifdef USES_P093

// #######################################################################################################
// ################################ Plugin 090: Mitsubishi Heat Pump #####################################
// ################################ Plugin 093: Mitsubishi Heat Pump #####################################
// #######################################################################################################

/** Changelog:
* 2023-05-04 tonhuisman: Add support for PLUGIN_GET_CONFIG_VALUE to enable fetching all available values (as included in the json)
* 2023-05-04 tonhuisman: Start Changelog
*/

/** Get Config values:
* Usage: [<taskname>#<configName>]
* Supported configNames are: (not case-sensitive)
* - roomTemperature
* - wideVane
* - power
* - mode
* - fan
* - vane
* - iSee
* - temperature
* With 'Include AC status' checkbox enabled:
* - operating
* - compressorFrequency
*/

# include "src/PluginStructs/P093_data_struct.h"

# define PLUGIN_093
Expand Down Expand Up @@ -111,6 +132,16 @@ boolean Plugin_093(uint8_t function, struct EventStruct *event, String& string)
}
break;
}

case PLUGIN_GET_CONFIG_VALUE:
{
P093_data_struct *heatPump = static_cast<P093_data_struct *>(getPluginTaskData(event->TaskIndex));

if (heatPump != nullptr) {
success = heatPump->plugin_get_config_value(event, string);
}
break;
}
}

return success;
Expand Down
64 changes: 54 additions & 10 deletions src/src/PluginStructs/P093_data_struct.cpp
Expand Up @@ -47,7 +47,7 @@ bool P093_data_struct::sync() {
}

bool P093_data_struct::read(String& result) const {
if (_valuesInitialized == false) {
if (!_valuesInitialized) {
return false;
}

Expand Down Expand Up @@ -80,9 +80,53 @@ bool P093_data_struct::read(String& result) const {
result += F(",\"temperature\":");
result += toString(_currentValues.temperature, 1) + '}';

return true;
}

bool P093_data_struct::plugin_get_config_value(struct EventStruct *event,
String & string) {
if (!_valuesInitialized) {
return false;
}
bool success = true;
const String command = parseString(string, 1);

if (equals(command, F("roomtemperature"))) {
string = toString(_currentValues.roomTemperature, 1);
} else
if (equals(command, F("widevane"))) {
string = map_list(_currentValues.wideVane, _mappings.wideVane);
} else
if (equals(command, F("power"))) {
string = map_list(_currentValues.power, _mappings.power);
} else
if (equals(command, F("mode"))) {
string = map_list(_currentValues.mode, _mappings.mode);
} else
if (equals(command, F("fan"))) {
string = map_list(_currentValues.fan, _mappings.fan);
} else
if (equals(command, F("vane"))) {
string = map_list(_currentValues.vane, _mappings.vane);
} else
if (equals(command, F("isee"))) {
string = _currentValues.iSee ? '1' : '0';
} else
if (equals(command, F("temperature"))) {
string = toString(_currentValues.temperature, 1);
} else
if (_includeStatus && equals(command, F("operating"))) {
string = _currentValues.operating ? '1' : '0';
} else
if (_includeStatus && equals(command, F("compressorfrequency"))) {
string = _currentValues.compressorFrequency;
} else {
success = false;
}

# undef map_list

return true;
return success;
}

void P093_data_struct::write(const String& command, const String& value) {
Expand Down Expand Up @@ -264,7 +308,7 @@ void P093_data_struct::responseReceived() {
void P093_data_struct::updateStatus() {
# ifdef PLUGIN_093_DEBUG
addLog(LOG_LEVEL_DEBUG, String(F("M-AC: US: ")) + _infoModeIndex);
#endif
# endif // ifdef PLUGIN_093_DEBUG

uint8_t packet[PACKET_LEN] = { 0xfc, 0x42, 0x01, 0x30, 0x10 };

Expand Down Expand Up @@ -323,7 +367,7 @@ void P093_data_struct::applySettings() {
void P093_data_struct::connect() {
# ifdef PLUGIN_093_DEBUG
addLog(LOG_LEVEL_DEBUG, String(F("M-AC: Connect ")) + getBaudRate());
#endif
# endif // ifdef PLUGIN_093_DEBUG

_serial.begin(getBaudRate(), SERIAL_8E1);
const uint8_t buffer[] = { 0xfc, 0x5a, 0x01, 0x30, 0x02, 0xca, 0x01, 0xa8 };
Expand Down Expand Up @@ -351,7 +395,7 @@ void P093_data_struct::addByteToReadBuffer(uint8_t value) {
} else {
# ifdef PLUGIN_093_DEBUG
addLog(LOG_LEVEL_DEBUG, F("M-AC: ABTRB(0)"));
#endif
# endif // ifdef PLUGIN_093_DEBUG
_readPos = 0;
}
}
Expand All @@ -376,7 +420,7 @@ bool P093_data_struct::readIncommingBytes() {
} else {
# ifdef PLUGIN_093_DEBUG
addLog(LOG_LEVEL_DEBUG, String(F("M-AC: RIB(0) ")) + formatToHex(value));
#endif
# endif // ifdef PLUGIN_093_DEBUG
}
} else if ((_readPos <= DATA_LEN_INDEX) || (_readPos <= DATA_LEN_INDEX + _readBuffer[DATA_LEN_INDEX])) {
// Read header + data part - data length is at index 4.
Expand Down Expand Up @@ -419,7 +463,7 @@ bool P093_data_struct::parseValues(const uint8_t *data, size_t length) {
if (length == 0) {
# ifdef PLUGIN_093_DEBUG
addLog(LOG_LEVEL_DEBUG, F("M-AC: PV(0)"));
#endif
# endif // ifdef PLUGIN_093_DEBUG
return false;
}

Expand Down Expand Up @@ -470,7 +514,7 @@ bool P093_data_struct::parseValues(const uint8_t *data, size_t length) {
}
# ifdef PLUGIN_093_DEBUG
addLog(LOG_LEVEL_DEBUG, F("M-AC: PV(1)"));
#endif
# endif // ifdef PLUGIN_093_DEBUG
return false;
}

Expand All @@ -482,7 +526,7 @@ P093_data_struct::State P093_data_struct::checkIncomingPacket(const uint8_t *pac
if ((packet[2] != 0x01) || (packet[3] != 0x30)) {
# ifdef PLUGIN_093_DEBUG
addLog(LOG_LEVEL_DEBUG, F("M-AC: CIP(0)"));
#endif
# endif // ifdef PLUGIN_093_DEBUG
return Invalid;
}

Expand All @@ -491,7 +535,7 @@ P093_data_struct::State P093_data_struct::checkIncomingPacket(const uint8_t *pac
if (calculatedChecksum != checksum) {
# ifdef PLUGIN_093_DEBUG
addLog(LOG_LEVEL_DEBUG, String(F("M-AC: CIP(1) ")) + calculatedChecksum);
#endif
# endif // ifdef PLUGIN_093_DEBUG
return Invalid;
}

Expand Down
10 changes: 6 additions & 4 deletions src/src/PluginStructs/P093_data_struct.h
Expand Up @@ -5,9 +5,9 @@
#ifdef USES_P093


#ifndef BUILD_NO_DEBUG
# define PLUGIN_093_DEBUG
#endif
# ifndef BUILD_NO_DEBUG
# define PLUGIN_093_DEBUG
# endif // ifndef BUILD_NO_DEBUG


/*
Expand Down Expand Up @@ -36,7 +36,7 @@ struct P093_data_struct : public PluginTaskData_base {
const int16_t serialTx,
bool includeStatus);

P093_data_struct() = delete;
P093_data_struct() = delete;
virtual ~P093_data_struct() = default;

void init();
Expand All @@ -47,6 +47,8 @@ struct P093_data_struct : public PluginTaskData_base {

void write(const String& command,
const String& value);
bool plugin_get_config_value(struct EventStruct *event,
String & string);

private:

Expand Down

0 comments on commit dae038d

Please sign in to comment.