Skip to content

Commit

Permalink
Refactor MQTT subscriptions #173
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Nov 1, 2021
1 parent 40a7026 commit 01bace4
Show file tree
Hide file tree
Showing 38 changed files with 857 additions and 926 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG_LATEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Added support for mDNS [#161](https://github.com/emsesp/EMS-ESP32/issues/161)
- Added last system ESP32 reset code to log (and `system info` output)
- Firmware Checker in WebUI [#168](https://github.com/emsesp/EMS-ESP32/issues/168)
- Added new MQTT setting for 'response' topic

## Fixed

Expand All @@ -29,13 +30,15 @@
## Changed

- Syslog BOM only for utf-8 messages [#91](https://github.com/emsesp/EMS-ESP32/issues/91)
- Check for KM200 by device-id 0x48, remove tx-delay[#90](https://github.com/emsesp/EMS-ESP32/issues/90)
- Check for KM200 by device-id 0x48, remove tx-delay [#90](https://github.com/emsesp/EMS-ESP32/issues/90)
- rename `fastheatupfactor` to `fastheatup` and add percent [#122]
- "unit" renamed to "uom" in API call to recall a Device Value
- initial backend React changes to replace the class components (HOCs) with React Hooks
- Use program-names instead of numbers
- Boiler's maintenancemessage always published in MQTT (to prevent HA missing entity)
- Unit of Measure 'times' added to MQTT Fails, Rx fails, Rx received, Tx fails, Tx reads & Tx writes
- Improved API. Restful HTTP API works in the same way as MQTT calls
- Removed settings for MQTT subscribe format [#173](https://github.com/emsesp/EMS-ESP32/issues/173)

## **BREAKING CHANGES**

Expand Down
27 changes: 10 additions & 17 deletions interface/src/mqtt/MqttSettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,23 +187,16 @@ class MqttSettingsForm extends React.Component<MqttSettingsFormProps> {
<MenuItem value={1}>Nested on a single topic</MenuItem>
<MenuItem value={2}>As individual topics</MenuItem>
</SelectValidator>
<SelectValidator
name="subscribe_format"
label="Subscribe Topics"
value={data.subscribe_format}
fullWidth
variant="outlined"
onChange={handleValueChange('subscribe_format')}
margin="normal"
>
<MenuItem value={0}>one topic per device</MenuItem>
<MenuItem value={1}>
topics for each device and it's values (main heating circuit only)
</MenuItem>
<MenuItem value={2}>
topic for each device and it's values (all heating circuits)
</MenuItem>
</SelectValidator>
<BlockFormControlLabel
control={
<Checkbox
checked={data.send_response}
onChange={handleValueChange('send_response')}
value="send_response"
/>
}
label="Publish command output to a 'response' topic"
/>
<BlockFormControlLabel
control={
<Checkbox
Expand Down
2 changes: 1 addition & 1 deletion interface/src/mqtt/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ export interface MqttSettings {
ha_enabled: boolean;
ha_climate_format: number;
nested_format: number;
subscribe_format: number;
send_response: boolean;
}
10 changes: 5 additions & 5 deletions interface/src/project/EMSESPtypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ export interface EMSESPData {
}

export interface DeviceValue {
v: any;
u: number;
n: string;
c: string;
l: string[];
v: any; // value, in any format
u: number; // uom
n: string; // name
c: string; // command
l: string[]; // list
}

export interface EMSESPDeviceData {
Expand Down
6 changes: 3 additions & 3 deletions lib/framework/MqttSettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void MqttSettings::read(MqttSettings & settings, JsonObject & root) {
root["ha_climate_format"] = settings.ha_climate_format;
root["ha_enabled"] = settings.ha_enabled;
root["nested_format"] = settings.nested_format;
root["subscribe_format"] = settings.subscribe_format;
root["send_response"] = settings.send_response;
}

StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & settings) {
Expand Down Expand Up @@ -205,7 +205,7 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
newSettings.ha_climate_format = root["ha_climate_format"] | EMSESP_DEFAULT_HA_CLIMATE_FORMAT;
newSettings.ha_enabled = root["ha_enabled"] | EMSESP_DEFAULT_HA_ENABLED;
newSettings.nested_format = root["nested_format"] | EMSESP_DEFAULT_NESTED_FORMAT;
newSettings.subscribe_format = root["subscribe_format"] | EMSESP_DEFAULT_SUBSCRIBE_FORMAT;
newSettings.send_response = root["send_response"] | EMSESP_DEFAULT_SEND_RESPONSE;

if (newSettings.enabled != settings.enabled) {
changed = true;
Expand All @@ -220,7 +220,7 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
changed = true;
}

if (newSettings.subscribe_format != settings.subscribe_format) {
if (newSettings.send_response != settings.send_response) {
changed = true;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/framework/MqttSettingsService.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class MqttSettings {
uint8_t ha_climate_format;
bool ha_enabled;
uint8_t nested_format;
uint8_t subscribe_format;
bool send_response;

static void read(MqttSettings & settings, JsonObject & root);
static StateUpdateResult update(JsonObject & root, MqttSettings & settings);
Expand Down
2 changes: 1 addition & 1 deletion lib_standalone/ESP8266React.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DummySettings {
uint8_t ha_climate_format = 1;
bool ha_enabled = true;
String base = "ems-esp";
uint8_t subscribe_format = 0;
bool send_response = true;

String hostname = "ems-esp";
String jwtSecret = "ems-esp";
Expand Down
2 changes: 1 addition & 1 deletion mock-api/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const mqtt_settings = {
ha_climate_format: 1,
ha_enabled: true,
nested_format: 1,
subscribe_format: 0,
send_response: true,
}
const mqtt_status = {
enabled: true,
Expand Down
Loading

0 comments on commit 01bace4

Please sign in to comment.