mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
all dashboard changes uses commands
This commit is contained in:
@@ -3,7 +3,6 @@ import { IconContext } from 'react-icons/lib';
|
|||||||
import { toast } from 'react-toastify';
|
import { toast } from 'react-toastify';
|
||||||
|
|
||||||
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
|
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
|
||||||
import CircleIcon from '@mui/icons-material/Circle';
|
|
||||||
import EditIcon from '@mui/icons-material/Edit';
|
import EditIcon from '@mui/icons-material/Edit';
|
||||||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
||||||
import UnfoldLessIcon from '@mui/icons-material/UnfoldLess';
|
import UnfoldLessIcon from '@mui/icons-material/UnfoldLess';
|
||||||
@@ -27,7 +26,7 @@ import { AuthenticatedContext } from 'contexts/authentication';
|
|||||||
import { useI18nContext } from 'i18n/i18n-react';
|
import { useI18nContext } from 'i18n/i18n-react';
|
||||||
import { useInterval } from 'utils';
|
import { useInterval } from 'utils';
|
||||||
|
|
||||||
import { readDashboard, writeDeviceValue, writeSchedule } from '../../api/app';
|
import { readDashboard, writeDeviceValue } from '../../api/app';
|
||||||
import DeviceIcon from './DeviceIcon';
|
import DeviceIcon from './DeviceIcon';
|
||||||
import DevicesDialog from './DevicesDialog';
|
import DevicesDialog from './DevicesDialog';
|
||||||
import { formatValue } from './deviceValue';
|
import { formatValue } from './deviceValue';
|
||||||
@@ -35,8 +34,7 @@ import {
|
|||||||
type DashboardItem,
|
type DashboardItem,
|
||||||
DeviceEntityMask,
|
DeviceEntityMask,
|
||||||
DeviceType,
|
DeviceType,
|
||||||
type DeviceValue,
|
type DeviceValue
|
||||||
type Schedule
|
|
||||||
} from './types';
|
} from './types';
|
||||||
import { deviceValueItemValidation } from './validators';
|
import { deviceValueItemValidation } from './validators';
|
||||||
|
|
||||||
@@ -63,13 +61,6 @@ const Dashboard = () => {
|
|||||||
initialData: []
|
initialData: []
|
||||||
});
|
});
|
||||||
|
|
||||||
const { send: updateSchedule } = useRequest(
|
|
||||||
(data: Schedule) => writeSchedule(data),
|
|
||||||
{
|
|
||||||
immediate: false
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const { loading: submitting, send: sendDeviceValue } = useRequest(
|
const { loading: submitting, send: sendDeviceValue } = useRequest(
|
||||||
(data: { id: number; c: string; v: unknown }) => writeDeviceValue(data),
|
(data: { id: number; c: string; v: unknown }) => writeDeviceValue(data),
|
||||||
{
|
{
|
||||||
@@ -114,6 +105,11 @@ const Dashboard = () => {
|
|||||||
border-top: 1px solid #177ac9;
|
border-top: 1px solid #177ac9;
|
||||||
border-bottom: 1px solid #177ac9;
|
border-bottom: 1px solid #177ac9;
|
||||||
}
|
}
|
||||||
|
`,
|
||||||
|
BaseCell: `
|
||||||
|
&:nth-of-type(2) {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -196,39 +192,13 @@ const Dashboard = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (di.dv) {
|
if (di.dv) {
|
||||||
return (
|
return <span style="color:lightgrey">{di.dv.id.slice(2)}</span>;
|
||||||
// ids for scheduler, and sensors are between 9600 and 9900
|
|
||||||
<span style="color:lightgrey">
|
|
||||||
{di.id >= 9600 && di.id < 9900 ? di.dv.id : di.dv.id.slice(2)}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasMask = (id: string, mask: number) =>
|
const hasMask = (id: string, mask: number) =>
|
||||||
(parseInt(id.slice(0, 2), 16) & mask) === mask;
|
(parseInt(id.slice(0, 2), 16) & mask) === mask;
|
||||||
|
|
||||||
const toggleSchedule = async (di: DashboardItem) => {
|
|
||||||
// create a dummy record, the id=0 picks it up
|
|
||||||
await updateSchedule({
|
|
||||||
schedule: {
|
|
||||||
id: 0, // special number for only changing the active flag
|
|
||||||
active: !di.dv?.v,
|
|
||||||
flags: 0, // unused
|
|
||||||
time: '', // unused
|
|
||||||
cmd: '', // unused
|
|
||||||
value: '', // unused
|
|
||||||
name: di.dv?.id ?? ''
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error: Error) => {
|
|
||||||
toast.error(error.message);
|
|
||||||
})
|
|
||||||
.finally(async () => {
|
|
||||||
await fetchDashboard();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const editDashboardValue = (di: DashboardItem) => {
|
const editDashboardValue = (di: DashboardItem) => {
|
||||||
setSelectedDashboardItem(di);
|
setSelectedDashboardItem(di);
|
||||||
setDeviceValueDialogOpen(true);
|
setDeviceValueDialogOpen(true);
|
||||||
@@ -325,25 +295,7 @@ const Dashboard = () => {
|
|||||||
</Cell>
|
</Cell>
|
||||||
|
|
||||||
<Cell stiff pinRight>
|
<Cell stiff pinRight>
|
||||||
{me.admin && di.id < 9700 && di.id >= 9600 ? (
|
{me.admin &&
|
||||||
<IconButton
|
|
||||||
size="small"
|
|
||||||
onClick={() => toggleSchedule(di)}
|
|
||||||
>
|
|
||||||
{di.dv?.v ? (
|
|
||||||
<CircleIcon
|
|
||||||
color="success"
|
|
||||||
sx={{ fontSize: 16, verticalAlign: 'middle' }}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<CircleIcon
|
|
||||||
color="error"
|
|
||||||
sx={{ fontSize: 16, verticalAlign: 'middle' }}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</IconButton>
|
|
||||||
) : (
|
|
||||||
me.admin &&
|
|
||||||
di.dv?.c &&
|
di.dv?.c &&
|
||||||
!hasMask(di.dv.id, DeviceEntityMask.DV_READONLY) && (
|
!hasMask(di.dv.id, DeviceEntityMask.DV_READONLY) && (
|
||||||
<IconButton
|
<IconButton
|
||||||
@@ -355,7 +307,6 @@ const Dashboard = () => {
|
|||||||
sx={{ fontSize: 16 }}
|
sx={{ fontSize: 16 }}
|
||||||
/>
|
/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
)
|
|
||||||
)}
|
)}
|
||||||
</Cell>
|
</Cell>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ import {
|
|||||||
MdOutlineSensors,
|
MdOutlineSensors,
|
||||||
MdThermostatAuto
|
MdThermostatAuto
|
||||||
} from 'react-icons/md';
|
} from 'react-icons/md';
|
||||||
import { TiFlowSwitch } from 'react-icons/ti';
|
import { PiFan, PiGauge } from 'react-icons/pi';
|
||||||
|
import { TiFlowSwitch, TiThermometer } from 'react-icons/ti';
|
||||||
import { VscVmConnect } from 'react-icons/vsc';
|
import { VscVmConnect } from 'react-icons/vsc';
|
||||||
|
|
||||||
import type { SvgIconProps } from '@mui/material';
|
import type { SvgIconProps } from '@mui/material';
|
||||||
@@ -20,8 +21,8 @@ import { DeviceType } from './types';
|
|||||||
const deviceIconLookup: {
|
const deviceIconLookup: {
|
||||||
[key in DeviceType]: React.ComponentType<SvgIconProps> | undefined;
|
[key in DeviceType]: React.ComponentType<SvgIconProps> | undefined;
|
||||||
} = {
|
} = {
|
||||||
[DeviceType.TEMPERATURESENSOR]: MdOutlineSensors,
|
[DeviceType.TEMPERATURESENSOR]: TiThermometer,
|
||||||
[DeviceType.ANALOGSENSOR]: MdOutlineSensors,
|
[DeviceType.ANALOGSENSOR]: PiGauge,
|
||||||
[DeviceType.BOILER]: CgSmartHomeBoiler,
|
[DeviceType.BOILER]: CgSmartHomeBoiler,
|
||||||
[DeviceType.HEATSOURCE]: CgSmartHomeBoiler,
|
[DeviceType.HEATSOURCE]: CgSmartHomeBoiler,
|
||||||
[DeviceType.THERMOSTAT]: MdThermostatAuto,
|
[DeviceType.THERMOSTAT]: MdThermostatAuto,
|
||||||
@@ -37,11 +38,11 @@ const deviceIconLookup: {
|
|||||||
[DeviceType.WATER]: GiTap,
|
[DeviceType.WATER]: GiTap,
|
||||||
[DeviceType.POOL]: MdOutlinePool,
|
[DeviceType.POOL]: MdOutlinePool,
|
||||||
[DeviceType.CUSTOM]: MdPlaylistAdd,
|
[DeviceType.CUSTOM]: MdPlaylistAdd,
|
||||||
[DeviceType.UNKNOWN]: undefined,
|
[DeviceType.UNKNOWN]: MdOutlineSensors,
|
||||||
[DeviceType.SYSTEM]: undefined,
|
[DeviceType.SYSTEM]: undefined,
|
||||||
[DeviceType.SCHEDULER]: MdMoreTime,
|
[DeviceType.SCHEDULER]: MdMoreTime,
|
||||||
[DeviceType.GENERIC]: undefined,
|
[DeviceType.GENERIC]: MdOutlineSensors,
|
||||||
[DeviceType.VENTILATION]: undefined
|
[DeviceType.VENTILATION]: PiFan
|
||||||
};
|
};
|
||||||
|
|
||||||
const DeviceIcon = ({ type_id }: { type_id: DeviceType }) => {
|
const DeviceIcon = ({ type_id }: { type_id: DeviceType }) => {
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ void WebDataService::core_data(AsyncWebServerRequest * request) {
|
|||||||
uint8_t customEntities = EMSESP::webCustomEntityService.count_entities();
|
uint8_t customEntities = EMSESP::webCustomEntityService.count_entities();
|
||||||
if (customEntities) {
|
if (customEntities) {
|
||||||
JsonObject obj = devices.add<JsonObject>();
|
JsonObject obj = devices.add<JsonObject>();
|
||||||
obj["id"] = 99; // the last unique id
|
obj["id"] = EMSdevice::DeviceTypeUniqueID::CUSTOM_UID;
|
||||||
obj["tn"] = Helpers::translated_word(FL_(custom_device)); // translated device type name
|
obj["tn"] = Helpers::translated_word(FL_(custom_device)); // translated device type name
|
||||||
obj["t"] = EMSdevice::DeviceType::CUSTOM; // device type number
|
obj["t"] = EMSdevice::DeviceType::CUSTOM; // device type number
|
||||||
obj["b"] = Helpers::translated_word(FL_(na)); // brand
|
obj["b"] = Helpers::translated_word(FL_(na)); // brand
|
||||||
@@ -194,7 +194,7 @@ void WebDataService::device_data(AsyncWebServerRequest * request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
if (id == 99) {
|
if (id == EMSdevice::DeviceTypeUniqueID::CUSTOM_UID) {
|
||||||
JsonObject output = response->getRoot();
|
JsonObject output = response->getRoot();
|
||||||
EMSESP::webCustomEntityService.generate_value_web(output);
|
EMSESP::webCustomEntityService.generate_value_web(output);
|
||||||
response->setLength();
|
response->setLength();
|
||||||
@@ -224,16 +224,41 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
|
|||||||
}
|
}
|
||||||
|
|
||||||
// using the unique ID from the web find the real device type
|
// using the unique ID from the web find the real device type
|
||||||
|
uint8_t device_type = EMSdevice::DeviceType::UNKNOWN;
|
||||||
|
switch (unique_id) {
|
||||||
|
case EMSdevice::DeviceTypeUniqueID::CUSTOM_UID:
|
||||||
|
device_type = EMSdevice::DeviceType::CUSTOM;
|
||||||
|
break;
|
||||||
|
case EMSdevice::DeviceTypeUniqueID::SCHEDULER_UID:
|
||||||
|
device_type = EMSdevice::DeviceType::SCHEDULER;
|
||||||
|
break;
|
||||||
|
case EMSdevice::DeviceTypeUniqueID::TEMPERATURESENSOR_UID:
|
||||||
|
device_type = EMSdevice::DeviceType::TEMPERATURESENSOR;
|
||||||
|
break;
|
||||||
|
case EMSdevice::DeviceTypeUniqueID::ANALOGSENSOR_UID:
|
||||||
|
device_type = EMSdevice::DeviceType::ANALOGSENSOR;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||||
if (emsdevice->unique_id() == unique_id) {
|
if (emsdevice->unique_id() == unique_id) {
|
||||||
|
device_type = emsdevice->device_type();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (device_type == EMSdevice::DeviceType::UNKNOWN) {
|
||||||
|
EMSESP::logger().warning("Write command failed, bad device id: %d", unique_id);
|
||||||
|
AsyncWebServerResponse * response = request->beginResponse(400); // bad request
|
||||||
|
request->send(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// create JSON for output
|
// create JSON for output
|
||||||
auto * response = new AsyncJsonResponse(false);
|
auto * response = new AsyncJsonResponse(false);
|
||||||
JsonObject output = response->getRoot();
|
JsonObject output = response->getRoot();
|
||||||
|
|
||||||
// the data could be in any format, but we need string
|
// the data could be in any format, but we need string
|
||||||
// authenticated is always true
|
// authenticated is always true
|
||||||
uint8_t return_code = CommandRet::NOT_FOUND;
|
uint8_t return_code = CommandRet::NOT_FOUND;
|
||||||
uint8_t device_type = emsdevice->device_type();
|
|
||||||
// parse the command as it could have a hc or dhw prefixed, e.g. hc2/seltemp
|
// parse the command as it could have a hc or dhw prefixed, e.g. hc2/seltemp
|
||||||
int8_t id = -1; // default
|
int8_t id = -1; // default
|
||||||
if (device_type >= EMSdevice::DeviceType::BOILER) {
|
if (device_type >= EMSdevice::DeviceType::BOILER) {
|
||||||
@@ -253,7 +278,8 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
|
|||||||
|
|
||||||
// write log
|
// write log
|
||||||
if (return_code != CommandRet::OK) {
|
if (return_code != CommandRet::OK) {
|
||||||
EMSESP::logger().err("Write command failed %s (%s)", (const char *)output["message"], Command::return_code_string(return_code));
|
// is already logged by command and message contains code
|
||||||
|
// EMSESP::logger().err("Write command failed %s (%s)", (const char *)output["message"], Command::return_code_string(return_code));
|
||||||
} else {
|
} else {
|
||||||
#if defined(EMSESP_DEBUG)
|
#if defined(EMSESP_DEBUG)
|
||||||
EMSESP::logger().debug("Write command successful");
|
EMSESP::logger().debug("Write command successful");
|
||||||
@@ -265,42 +291,8 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
|
|||||||
request->send(response);
|
request->send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// special check for custom entities (which have a unique id of 99)
|
EMSESP::logger().warning("Write command failed, bad json");
|
||||||
if (unique_id == 99) {
|
|
||||||
auto * response = new AsyncJsonResponse(false);
|
|
||||||
JsonObject output = response->getRoot();
|
|
||||||
uint8_t return_code = CommandRet::NOT_FOUND;
|
|
||||||
uint8_t device_type = EMSdevice::DeviceType::CUSTOM;
|
|
||||||
// parse the command as it could have a hc or dhw prefixed, e.g. hc2/seltemp
|
|
||||||
int8_t id = -1;
|
|
||||||
if (device_type >= EMSdevice::DeviceType::BOILER) {
|
|
||||||
cmd = Command::parse_command_string(cmd, id); // extract hc or dhw
|
|
||||||
}
|
|
||||||
if (data.is<const char *>()) {
|
|
||||||
return_code = Command::call(device_type, cmd, data.as<const char *>(), true, id, output);
|
|
||||||
} else if (data.is<int>()) {
|
|
||||||
char s[10];
|
|
||||||
return_code = Command::call(device_type, cmd, Helpers::render_value(s, data.as<int32_t>(), 0), true, id, output);
|
|
||||||
} else if (data.is<float>()) {
|
|
||||||
char s[10];
|
|
||||||
return_code = Command::call(device_type, cmd, Helpers::render_value(s, data.as<float>(), 1), true, id, output);
|
|
||||||
}
|
|
||||||
if (return_code != CommandRet::OK) {
|
|
||||||
EMSESP::logger().err("Write command failed %s (%s)", (const char *)output["message"], Command::return_code_string(return_code));
|
|
||||||
} else {
|
|
||||||
#if defined(EMSESP_DEBUG)
|
|
||||||
EMSESP::logger().debug("Write command successful");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
response->setCode((return_code == CommandRet::OK) ? 200 : 400); // bad request
|
|
||||||
response->setLength();
|
|
||||||
request->send(response);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if we reach here, fail
|
// if we reach here, fail
|
||||||
AsyncWebServerResponse * response = request->beginResponse(400); // bad request
|
AsyncWebServerResponse * response = request->beginResponse(400); // bad request
|
||||||
@@ -393,7 +385,7 @@ void WebDataService::dashboard_data(AsyncWebServerRequest * request) {
|
|||||||
node["id"] = (EMSdevice::DeviceTypeUniqueID::TEMPERATURESENSOR_UID * 100) + count++;
|
node["id"] = (EMSdevice::DeviceTypeUniqueID::TEMPERATURESENSOR_UID * 100) + count++;
|
||||||
|
|
||||||
JsonObject dv = node["dv"].to<JsonObject>();
|
JsonObject dv = node["dv"].to<JsonObject>();
|
||||||
dv["id"] = sensor.name();
|
dv["id"] = "00" + sensor.name();
|
||||||
if (EMSESP::system_.fahrenheit()) {
|
if (EMSESP::system_.fahrenheit()) {
|
||||||
if (Helpers::hasValue(sensor.temperature_c)) {
|
if (Helpers::hasValue(sensor.temperature_c)) {
|
||||||
dv["v"] = (float)sensor.temperature_c * 0.18 + 32;
|
dv["v"] = (float)sensor.temperature_c * 0.18 + 32;
|
||||||
@@ -421,8 +413,19 @@ void WebDataService::dashboard_data(AsyncWebServerRequest * request) {
|
|||||||
node["id"] = (EMSdevice::DeviceTypeUniqueID::ANALOGSENSOR_UID * 100) + count++;
|
node["id"] = (EMSdevice::DeviceTypeUniqueID::ANALOGSENSOR_UID * 100) + count++;
|
||||||
|
|
||||||
JsonObject dv = node["dv"].to<JsonObject>();
|
JsonObject dv = node["dv"].to<JsonObject>();
|
||||||
dv["id"] = sensor.name();
|
dv["id"] = "00" + sensor.name();
|
||||||
dv["v"] = Helpers::transformNumFloat(sensor.value(), 0); // is optional and is a float
|
if (sensor.type() == AnalogSensor::AnalogType::DIGITAL_OUT || sensor.type() == AnalogSensor::AnalogType::DIGITAL_IN) {
|
||||||
|
char s[12];
|
||||||
|
dv["v"] = Helpers::render_boolean(s, sensor.value() != 0, true);
|
||||||
|
JsonArray l = dv["l"].to<JsonArray>();
|
||||||
|
l.add(Helpers::render_boolean(s, false, true));
|
||||||
|
l.add(Helpers::render_boolean(s, true, true));
|
||||||
|
} else {
|
||||||
|
dv["v"] = Helpers::transformNumFloat(sensor.value(), 0);
|
||||||
|
}
|
||||||
|
if (sensor.type() == AnalogSensor::AnalogType::COUNTER || sensor.type() >= AnalogSensor::AnalogType::DIGITAL_OUT) {
|
||||||
|
dv["c"] = sensor.name();
|
||||||
|
}
|
||||||
dv["u"] = sensor.uom();
|
dv["u"] = sensor.uom();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -444,8 +447,13 @@ void WebDataService::dashboard_data(AsyncWebServerRequest * request) {
|
|||||||
node["id"] = (EMSdevice::DeviceTypeUniqueID::SCHEDULER_UID * 100) + count++;
|
node["id"] = (EMSdevice::DeviceTypeUniqueID::SCHEDULER_UID * 100) + count++;
|
||||||
|
|
||||||
JsonObject dv = node["dv"].to<JsonObject>();
|
JsonObject dv = node["dv"].to<JsonObject>();
|
||||||
dv["id"] = scheduleItem.name;
|
dv["id"] = "00" + scheduleItem.name;
|
||||||
dv["v"] = scheduleItem.flags != SCHEDULEFLAG_SCHEDULE_IMMEDIATE ? scheduleItem.active : false; // value is active
|
dv["c"] = scheduleItem.name;
|
||||||
|
char s[12];
|
||||||
|
dv["v"] = Helpers::render_boolean(s, scheduleItem.active, true);
|
||||||
|
JsonArray l = dv["l"].to<JsonArray>();
|
||||||
|
l.add(Helpers::render_boolean(s, false, true));
|
||||||
|
l.add(Helpers::render_boolean(s, true, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -462,5 +470,4 @@ void WebDataService::dashboard_data(AsyncWebServerRequest * request) {
|
|||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace emsesp
|
} // namespace emsesp
|
||||||
@@ -65,29 +65,6 @@ void WebScheduler::read(WebScheduler & webScheduler, JsonObject root) {
|
|||||||
// call on initialization and also when the Schedule web page is saved
|
// call on initialization and also when the Schedule web page is saved
|
||||||
// this loads the data into the internal class
|
// this loads the data into the internal class
|
||||||
StateUpdateResult WebScheduler::update(JsonObject root, WebScheduler & webScheduler) {
|
StateUpdateResult WebScheduler::update(JsonObject root, WebScheduler & webScheduler) {
|
||||||
// check if we're only toggling it on/off via the Dashboard
|
|
||||||
// if it is a single schedule object and id is 0
|
|
||||||
if (root["schedule"].is<JsonObject>()) {
|
|
||||||
JsonObject si = root["schedule"];
|
|
||||||
if (si["id"] == 0) {
|
|
||||||
// find the item, matching the name
|
|
||||||
for (ScheduleItem & scheduleItem : webScheduler.scheduleItems) {
|
|
||||||
std::string name = si["name"].as<std::string>();
|
|
||||||
if (scheduleItem.name == name) {
|
|
||||||
scheduleItem.active = si["active"];
|
|
||||||
EMSESP::webSchedulerService.publish(true);
|
|
||||||
return StateUpdateResult::CHANGED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return StateUpdateResult::UNCHANGED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// otherwise we're updating and saving the whole list again
|
|
||||||
if (!root["schedule"].is<JsonArray>()) {
|
|
||||||
return StateUpdateResult::ERROR; // invalid format
|
|
||||||
}
|
|
||||||
|
|
||||||
// reset the list
|
// reset the list
|
||||||
Command::erase_device_commands(EMSdevice::DeviceType::SCHEDULER);
|
Command::erase_device_commands(EMSdevice::DeviceType::SCHEDULER);
|
||||||
webScheduler.scheduleItems.clear();
|
webScheduler.scheduleItems.clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user