Merge pull request #458 from MichaelDvP/dev

mqtt HA uses only json, disable single
This commit is contained in:
Proddy
2022-04-08 13:42:15 +02:00
committed by GitHub
3 changed files with 48 additions and 32 deletions

View File

@@ -183,45 +183,49 @@ const MqttSettingsForm: FC = () => {
control={<Checkbox name="send_response" checked={data.send_response} onChange={updateFormValue} />} control={<Checkbox name="send_response" checked={data.send_response} onChange={updateFormValue} />}
label="Publish command output to a 'response' topic" label="Publish command output to a 'response' topic"
/> />
<Grid container spacing={1} direction="row" justifyContent="flex-start" alignItems="flex-start"> {!data.ha_enabled && (
<Grid item> <Grid container spacing={1} direction="row" justifyContent="flex-start" alignItems="flex-start">
<BlockFormControlLabel
control={<Checkbox name="publish_single" checked={data.publish_single} onChange={updateFormValue} />}
label="Publish single value topics on change"
/>
</Grid>
{data.publish_single && (
<Grid item> <Grid item>
<BlockFormControlLabel <BlockFormControlLabel
control={ control={<Checkbox name="publish_single" checked={data.publish_single} onChange={updateFormValue} />}
<Checkbox name="publish_single2cmd" checked={data.publish_single2cmd} onChange={updateFormValue} /> label="Publish single value topics on change"
}
label="Publish to command topics (ioBroker)"
/> />
</Grid> </Grid>
)} {data.publish_single && (
</Grid> <Grid item>
<Grid container spacing={1} direction="row" justifyContent="flex-start" alignItems="flex-start"> <BlockFormControlLabel
<Grid item> control={
<BlockFormControlLabel <Checkbox name="publish_single2cmd" checked={data.publish_single2cmd} onChange={updateFormValue} />
control={<Checkbox name="ha_enabled" checked={data.ha_enabled} onChange={updateFormValue} />} }
label="Enable MQTT Discovery (Home Assistant, Domoticz)" label="Publish to command topics (ioBroker)"
/> />
</Grid>
)}
</Grid> </Grid>
{data.ha_enabled && ( )}
<Grid item xs={6}> {!data.publish_single && (
<ValidatedTextField <Grid container spacing={1} direction="row" justifyContent="flex-start" alignItems="flex-start">
name="discovery_prefix" <Grid item>
label="Prefix for the Discovery topics" <BlockFormControlLabel
fullWidth control={<Checkbox name="ha_enabled" checked={data.ha_enabled} onChange={updateFormValue} />}
variant="outlined" label="Enable MQTT Discovery (Home Assistant, Domoticz)"
value={data.discovery_prefix}
onChange={updateFormValue}
margin="normal"
/> />
</Grid> </Grid>
)} {data.ha_enabled && (
</Grid> <Grid item xs={6}>
<ValidatedTextField
name="discovery_prefix"
label="Prefix for the Discovery topics"
fullWidth
variant="outlined"
value={data.discovery_prefix}
onChange={updateFormValue}
margin="normal"
/>
</Grid>
)}
</Grid>
)}
<Typography sx={{ pt: 2 }} variant="h6" color="primary"> <Typography sx={{ pt: 2 }} variant="h6" color="primary">
Publish Intervals (in seconds, 0=automatic) Publish Intervals (in seconds, 0=automatic)
</Typography> </Typography>

View File

@@ -228,7 +228,15 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
changed = true; changed = true;
} }
// if both settings are stored from older version, HA has priority
if (newSettings.ha_enabled && newSettings.publish_single) {
newSettings.publish_single = false;
}
if (newSettings.publish_single != settings.publish_single) { if (newSettings.publish_single != settings.publish_single) {
if (newSettings.publish_single) {
newSettings.ha_enabled = false;
}
changed = true; changed = true;
} }
@@ -242,6 +250,9 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
if (newSettings.ha_enabled != settings.ha_enabled) { if (newSettings.ha_enabled != settings.ha_enabled) {
emsesp::EMSESP::mqtt_.ha_enabled(newSettings.ha_enabled); emsesp::EMSESP::mqtt_.ha_enabled(newSettings.ha_enabled);
if (newSettings.ha_enabled) {
newSettings.publish_single = false;
}
changed = true; changed = true;
} }

View File

@@ -961,6 +961,7 @@ bool System::command_settings(const char * value, const int8_t id, JsonObject &
node["publish_time_other"] = settings.publish_time_other; node["publish_time_other"] = settings.publish_time_other;
node["publish_time_sensor"] = settings.publish_time_sensor; node["publish_time_sensor"] = settings.publish_time_sensor;
node["publish_single"] = settings.publish_single; node["publish_single"] = settings.publish_single;
node["publish_2_command"] = settings.publish_single2cmd;
node["send_response"] = settings.send_response; node["send_response"] = settings.send_response;
}); });