This commit is contained in:
MichaelDvP
2023-11-15 11:27:19 +01:00
13 changed files with 807 additions and 791 deletions

File diff suppressed because one or more lines are too long

View File

@@ -4,4 +4,4 @@ enableGlobalCache: false
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-4.0.1.cjs
yarnPath: .yarn/releases/yarn-4.0.2.cjs

View File

@@ -23,8 +23,8 @@
"@babel/core": "^7.23.3",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.14.16",
"@mui/material": "^5.14.17",
"@mui/icons-material": "^5.14.18",
"@mui/material": "^5.14.18",
"@table-library/react-table-library": "4.1.7",
"@types/imagemin": "^8.0.4",
"@types/lodash-es": "^4.17.11",
@@ -41,7 +41,7 @@
"react": "latest",
"react-dom": "latest",
"react-dropzone": "^14.2.3",
"react-icons": "^4.11.0",
"react-icons": "^4.12.0",
"react-router-dom": "^6.18.0",
"react-toastify": "^9.1.3",
"sockette": "^2.0.6",
@@ -65,7 +65,7 @@
"eslint-plugin-prettier": "alpha",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"preact": "^10.19.1",
"preact": "^10.19.2",
"prettier": "^3.1.0",
"rollup-plugin-visualizer": "^5.9.2",
"terser": "^5.24.0",
@@ -73,5 +73,5 @@
"vite-plugin-imagemin": "^0.6.1",
"vite-tsconfig-paths": "^4.2.1"
},
"packageManager": "yarn@4.0.1"
"packageManager": "yarn@4.0.2"
}

View File

@@ -350,7 +350,7 @@ const DashboardDevices: FC = () => {
const deviceValueDialogSave = async (devicevalue: DeviceValue) => {
const id = Number(device_select.state.id);
await writeDeviceValue({ id, devicevalue })
await writeDeviceValue({ id, c: devicevalue.c, v: devicevalue.v })
.then(() => {
toast.success(LL.WRITE_CMD_SENT());
})

View File

@@ -772,15 +772,15 @@ __metadata:
languageName: node
linkType: hard
"@floating-ui/react-dom@npm:^2.0.2":
version: 2.0.2
resolution: "@floating-ui/react-dom@npm:2.0.2"
"@floating-ui/react-dom@npm:^2.0.4":
version: 2.0.4
resolution: "@floating-ui/react-dom@npm:2.0.4"
dependencies:
"@floating-ui/dom": "npm:^1.5.1"
peerDependencies:
react: ">=16.8.0"
react-dom: ">=16.8.0"
checksum: 63a26f3c36f00a2bdede202cb7a3be74b3c6599463c0a069745f6aed3181a33ce72936158209f6fd1c284d85fd494aa656e6cbc4266c096f3189ce1c13f83dfe
checksum: 4240a718502c797fd2e174cd06dcd7321a6eda9c8966dbaf61864b9e16445e95649a59bfe7c19ee13f68c11f3693724d7970c7e618089a3d3915bd343639cfae
languageName: node
linkType: hard
@@ -882,14 +882,14 @@ __metadata:
languageName: node
linkType: hard
"@mui/base@npm:5.0.0-beta.23":
version: 5.0.0-beta.23
resolution: "@mui/base@npm:5.0.0-beta.23"
"@mui/base@npm:5.0.0-beta.24":
version: 5.0.0-beta.24
resolution: "@mui/base@npm:5.0.0-beta.24"
dependencies:
"@babel/runtime": "npm:^7.23.2"
"@floating-ui/react-dom": "npm:^2.0.2"
"@mui/types": "npm:^7.2.8"
"@mui/utils": "npm:^5.14.17"
"@floating-ui/react-dom": "npm:^2.0.4"
"@mui/types": "npm:^7.2.9"
"@mui/utils": "npm:^5.14.18"
"@popperjs/core": "npm:^2.11.8"
clsx: "npm:^2.0.0"
prop-types: "npm:^15.8.1"
@@ -900,20 +900,20 @@ __metadata:
peerDependenciesMeta:
"@types/react":
optional: true
checksum: 5219132b1e4ba027736cb8f2f22ecccc69a883016679f00db1cf79f82614b0cc6466b9f437bab67c043041ee9d5e01d84249896c2c8771a045da7e60639d4b44
checksum: 65d8a428d7e863885d5d5d6513ffa64982ebd7bd3a809b3024f669b907796c94a5d19ebac42ef383277acaccf30af3158c91f65c69fb0e7b2ddab925fc3293dd
languageName: node
linkType: hard
"@mui/core-downloads-tracker@npm:^5.14.17":
version: 5.14.17
resolution: "@mui/core-downloads-tracker@npm:5.14.17"
checksum: dfa5ffe6e370ad9490cbe03b964967271462f7fb74c09e29e6fe09042f15ddec9a976f5131ce01b003dba1d66b70a6af026b0a1929db50124c783d7df45b06b6
"@mui/core-downloads-tracker@npm:^5.14.18":
version: 5.14.18
resolution: "@mui/core-downloads-tracker@npm:5.14.18"
checksum: 3d367797282e4b93eacee997667d62bc4eeac979e9664724e9db8d632278d8629f2a141894cf53d706f1d2a9f19965bffe2858aa2bc9833722e674cd560b896e
languageName: node
linkType: hard
"@mui/icons-material@npm:^5.14.16":
version: 5.14.16
resolution: "@mui/icons-material@npm:5.14.16"
"@mui/icons-material@npm:^5.14.18":
version: 5.14.18
resolution: "@mui/icons-material@npm:5.14.18"
dependencies:
"@babel/runtime": "npm:^7.23.2"
peerDependencies:
@@ -923,20 +923,20 @@ __metadata:
peerDependenciesMeta:
"@types/react":
optional: true
checksum: e4dc4071eb68b06c54f25733cd00c749a18c69c16186defc467db5599ea46c32bfb8cc64e40b208e4b85f9186ab8b2e76f0553eac98727e8446c81461d665f58
checksum: 20da1445f033edf017d7d447c74fb27e90d4a9f3a631f617252a4806b69364792e01aa7010939c90e37d8ce7adf4218ec27066bd8ec0db40295f64365fd18a5e
languageName: node
linkType: hard
"@mui/material@npm:^5.14.17":
version: 5.14.17
resolution: "@mui/material@npm:5.14.17"
"@mui/material@npm:^5.14.18":
version: 5.14.18
resolution: "@mui/material@npm:5.14.18"
dependencies:
"@babel/runtime": "npm:^7.23.2"
"@mui/base": "npm:5.0.0-beta.23"
"@mui/core-downloads-tracker": "npm:^5.14.17"
"@mui/system": "npm:^5.14.17"
"@mui/types": "npm:^7.2.8"
"@mui/utils": "npm:^5.14.17"
"@mui/base": "npm:5.0.0-beta.24"
"@mui/core-downloads-tracker": "npm:^5.14.18"
"@mui/system": "npm:^5.14.18"
"@mui/types": "npm:^7.2.9"
"@mui/utils": "npm:^5.14.18"
"@types/react-transition-group": "npm:^4.4.8"
clsx: "npm:^2.0.0"
csstype: "npm:^3.1.2"
@@ -956,16 +956,16 @@ __metadata:
optional: true
"@types/react":
optional: true
checksum: 498797747d532f3909611aac04b07ac4067a70d282a238b7cfbebb1cf2004df40c51c10d9c5b1786916dc4c4c1cd722880aad3200c70ba13fc2610bf7bb72bab
checksum: 50c5ddbd8e6e39aa4cf904ea7061a1c9d91d906baa7b7626f3db22338872972bac8d176002e613f79e9171969e898ca268c024a143bc120f05e750035b25a8cb
languageName: node
linkType: hard
"@mui/private-theming@npm:^5.14.17":
version: 5.14.17
resolution: "@mui/private-theming@npm:5.14.17"
"@mui/private-theming@npm:^5.14.18":
version: 5.14.18
resolution: "@mui/private-theming@npm:5.14.18"
dependencies:
"@babel/runtime": "npm:^7.23.2"
"@mui/utils": "npm:^5.14.17"
"@mui/utils": "npm:^5.14.18"
prop-types: "npm:^15.8.1"
peerDependencies:
"@types/react": ^17.0.0 || ^18.0.0
@@ -973,13 +973,13 @@ __metadata:
peerDependenciesMeta:
"@types/react":
optional: true
checksum: a02bcf41de4d79f704b415e2d4346e84eb138e773a6ca622017d5631e25689eba2c860637cb8c8f0fd71032c52f2889a1b2ae33975929da77aca7cfe229aaf6b
checksum: cb2ae253c7aba571ae838b5c886f74cde0e4b3df49ed1d776ee355e87fc28efe6a23367d713ac6979378049aa67d3bffb65cba421818a11b65d4518742a8711b
languageName: node
linkType: hard
"@mui/styled-engine@npm:^5.14.17":
version: 5.14.17
resolution: "@mui/styled-engine@npm:5.14.17"
"@mui/styled-engine@npm:^5.14.18":
version: 5.14.18
resolution: "@mui/styled-engine@npm:5.14.18"
dependencies:
"@babel/runtime": "npm:^7.23.2"
"@emotion/cache": "npm:^11.11.0"
@@ -994,19 +994,19 @@ __metadata:
optional: true
"@emotion/styled":
optional: true
checksum: 0a86748dc45caffc7effab8e73dde31962f2f7b0cce063591e9ce1c7c096b1c02eb35cb29090ea23913a4e600d3bad4547af6ce63a8c922991cb01cf5fb2d0c7
checksum: 305128a623339cf0bb563cebb822363c19d9337221e7894c00130680e5b7a818c81a6df1d1f036a97641ce0f1bc336a0328ce3e2787d2dee1ff73bf0718aca63
languageName: node
linkType: hard
"@mui/system@npm:^5.14.17":
version: 5.14.17
resolution: "@mui/system@npm:5.14.17"
"@mui/system@npm:^5.14.18":
version: 5.14.18
resolution: "@mui/system@npm:5.14.18"
dependencies:
"@babel/runtime": "npm:^7.23.2"
"@mui/private-theming": "npm:^5.14.17"
"@mui/styled-engine": "npm:^5.14.17"
"@mui/types": "npm:^7.2.8"
"@mui/utils": "npm:^5.14.17"
"@mui/private-theming": "npm:^5.14.18"
"@mui/styled-engine": "npm:^5.14.18"
"@mui/types": "npm:^7.2.9"
"@mui/utils": "npm:^5.14.18"
clsx: "npm:^2.0.0"
csstype: "npm:^3.1.2"
prop-types: "npm:^15.8.1"
@@ -1022,28 +1022,28 @@ __metadata:
optional: true
"@types/react":
optional: true
checksum: 351040cfd4a698328e050397a8895e24ad93c37a2a72d6f8f4c8a652e43315a8ada26cc2b5dfda93b8cdf61b6e481474a7af7948d2752351184b99079f2f9c7b
checksum: 4e9a47342fc928506272a2b68d9f2592bbbc5a9f88176ee03b6050066f18f7d2df11355796d7ee5ef556d12779fe9e4d20520d0a0f1e24e2696193e4c13ce580
languageName: node
linkType: hard
"@mui/types@npm:^7.2.8":
version: 7.2.8
resolution: "@mui/types@npm:7.2.8"
"@mui/types@npm:^7.2.9":
version: 7.2.9
resolution: "@mui/types@npm:7.2.9"
peerDependencies:
"@types/react": ^17.0.0 || ^18.0.0
peerDependenciesMeta:
"@types/react":
optional: true
checksum: 47be368669d5bb5e43458d93d20c7e9f4f6ca2fec2bc7b541dcc7b59a0168ac6bfa6b88f51f5ad1d044c07a1fb247b803683bcaf969052aab559f25f11727ba5
checksum: f8a21c5a375373e03b9e7ef0c081fbcbfffb8e743955280d360ac37990448a587ac101b82e35539102ea46c994d23475c80be236b36deaabf38acc5e48c2bdef
languageName: node
linkType: hard
"@mui/utils@npm:^5.14.17":
version: 5.14.17
resolution: "@mui/utils@npm:5.14.17"
"@mui/utils@npm:^5.14.18":
version: 5.14.18
resolution: "@mui/utils@npm:5.14.18"
dependencies:
"@babel/runtime": "npm:^7.23.2"
"@types/prop-types": "npm:^15.7.9"
"@types/prop-types": "npm:^15.7.10"
prop-types: "npm:^15.8.1"
react-is: "npm:^18.2.0"
peerDependencies:
@@ -1052,7 +1052,7 @@ __metadata:
peerDependenciesMeta:
"@types/react":
optional: true
checksum: 98c8b38075a2e3c2882eee8dccbbd5648747af63688ff2200acb63a7c3589864b3ea8bc067380bb3e4f46b09cec8b0fa144309644c0b9166bf194f76d89bc6fe
checksum: abc699aab138a5650f7ba5f4c87511802bc35b8307331a9024d2d1769520a63ccccf952097ab8943104d6304107836cba580a7acbcc0138c263f77f97b1b3dd0
languageName: node
linkType: hard
@@ -1410,13 +1410,20 @@ __metadata:
languageName: node
linkType: hard
"@types/prop-types@npm:*, @types/prop-types@npm:^15.7.9":
"@types/prop-types@npm:*":
version: 15.7.9
resolution: "@types/prop-types@npm:15.7.9"
checksum: c7591d3ff7593e243908a07e1d3e2bb6e8879008af5800d8378115a90d0fdf669a1cae72a6d7f69e59c4fa7bb4c8ed61f6ebc1c520fe110c6f2b03ac02414072
languageName: node
linkType: hard
"@types/prop-types@npm:^15.7.10":
version: 15.7.10
resolution: "@types/prop-types@npm:15.7.10"
checksum: 39ecc2d9e439ed16b32937a08d98b84ed4a70f53bcd52c8564c0cd7a36fe1004ca83a1fb94b13c1b7a5c048760f06445c3c6a91a6972c8eff652c0b50c9424b1
languageName: node
linkType: hard
"@types/react-dom@npm:^18.2.15":
version: 18.2.15
resolution: "@types/react-dom@npm:18.2.15"
@@ -1647,8 +1654,8 @@ __metadata:
"@babel/core": "npm:^7.23.3"
"@emotion/react": "npm:^11.11.1"
"@emotion/styled": "npm:^11.11.0"
"@mui/icons-material": "npm:^5.14.16"
"@mui/material": "npm:^5.14.17"
"@mui/icons-material": "npm:^5.14.18"
"@mui/material": "npm:^5.14.18"
"@preact/compat": "npm:^17.1.2"
"@preact/preset-vite": "npm:^2.6.0"
"@table-library/react-table-library": "npm:4.1.7"
@@ -1678,12 +1685,12 @@ __metadata:
jwt-decode: "npm:^4.0.0"
lodash-es: "npm:^4.17.21"
mime-types: "npm:^2.1.35"
preact: "npm:^10.19.1"
preact: "npm:^10.19.2"
prettier: "npm:^3.1.0"
react: "npm:latest"
react-dom: "npm:latest"
react-dropzone: "npm:^14.2.3"
react-icons: "npm:^4.11.0"
react-icons: "npm:^4.12.0"
react-router-dom: "npm:^6.18.0"
react-toastify: "npm:^9.1.3"
rollup-plugin-visualizer: "npm:^5.9.2"
@@ -6758,10 +6765,10 @@ __metadata:
languageName: node
linkType: hard
"preact@npm:^10.19.1":
version: 10.19.1
resolution: "preact@npm:10.19.1"
checksum: 1dce5b00d9031aca2266ef64cc38b27a4696f1c4d78baecc1f66a9bf2798c022a792b97257d64db450723edb69c12bc967e993d3b516734eff57895b9258c419
"preact@npm:^10.19.2":
version: 10.19.2
resolution: "preact@npm:10.19.2"
checksum: 1519050e79f0dec61aa85daa5dcba4a5294e89fb09ab53d5e1a215ef8526dd5ccdbe82a02842cc4875fa3ea076eee9697a7421c32ffcc6159007d27b13a60a8f
languageName: node
linkType: hard
@@ -6906,12 +6913,12 @@ __metadata:
languageName: node
linkType: hard
"react-icons@npm:^4.11.0":
version: 4.11.0
resolution: "react-icons@npm:4.11.0"
"react-icons@npm:^4.12.0":
version: 4.12.0
resolution: "react-icons@npm:4.12.0"
peerDependencies:
react: "*"
checksum: 61f84c7a3f59120659f984828cac72b11c4baf9b78fb71261ab1ab5b2a9df4debd9fa5e9c30ccca23e4f0d9c0713bb5a339390073a8a01f4fe72c024fc526b5f
checksum: 5cc20509ca0b182f1e7bf42c271846c48f688c8922e2439f48728805adc93ba18476a13588cbe91ee43a2d03b2787e0dc0b5cc4b9c4e4ae3426f4464b3c1b734
languageName: node
linkType: hard

File diff suppressed because one or more lines are too long

View File

@@ -4,4 +4,4 @@ enableGlobalCache: false
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-4.0.1.cjs
yarnPath: .yarn/releases/yarn-4.0.2.cjs

View File

@@ -15,5 +15,5 @@
"express": "^4.18.2",
"multer": "^1.4.5-lts.1"
},
"packageManager": "yarn@4.0.1"
"packageManager": "yarn@4.0.2"
}

View File

@@ -2404,42 +2404,45 @@ rest_server.post(EMSESP_WRITE_ENTITIES_ENDPOINT, (req, res) => {
});
rest_server.post(EMSESP_WRITE_VALUE_ENDPOINT, async (req, res) => {
const devicevalue = req.body.devicevalue;
const command = req.body.c;
const value = req.body.v;
const id = req.body.id;
console.log('Write device value for id : ' + id);
console.log(' devicedata: ' + JSON.stringify(devicevalue));
console.log(' data: ' + JSON.stringify(req.body));
if (id === 1) {
objIndex = emsesp_devicedata_1.data.findIndex((obj) => obj.c == devicevalue.c);
emsesp_devicedata_1.data[objIndex] = devicevalue;
objIndex = emsesp_devicedata_1.data.findIndex((obj) => obj.c == command);
emsesp_devicedata_1.data[objIndex].v = value;
}
if (id === 2) {
objIndex = emsesp_devicedata_2.data.findIndex((obj) => obj.c == devicevalue.c);
emsesp_devicedata_2.data[objIndex] = devicevalue;
objIndex = emsesp_devicedata_2.data.findIndex((obj) => obj.c == command);
emsesp_devicedata_2.data[objIndex].v = value;
}
if (id === 3) {
objIndex = emsesp_devicedata_3.data.findIndex((obj) => obj.c == devicevalue.c);
emsesp_devicedata_3.data[objIndex] = devicevalue;
objIndex = emsesp_devicedata_3.data.findIndex((obj) => obj.c == command);
emsesp_devicedata_3.data[objIndex].v = value;
}
if (id === 4) {
objIndex = emsesp_devicedata_4.data.findIndex((obj) => obj.c == devicevalue.c);
emsesp_devicedata_4.data[objIndex] = devicevalue;
objIndex = emsesp_devicedata_4.data.findIndex((obj) => obj.c == command);
emsesp_devicedata_4.data[objIndex].v = value;
}
if (id === 5) {
objIndex = emsesp_devicedata_5.data.findIndex((obj) => obj.c == devicevalue.c);
emsesp_devicedata_5.data[objIndex] = devicevalue;
objIndex = emsesp_devicedata_5.data.findIndex((obj) => obj.c == command);
emsesp_devicedata_5.data[objIndex].v = value;
}
if (id === 6) {
objIndex = emsesp_devicedata_6.data.findIndex((obj) => obj.c == devicevalue.c);
emsesp_devicedata_6.data[objIndex] = devicevalue;
objIndex = emsesp_devicedata_6.data.findIndex((obj) => obj.c == command);
emsesp_devicedata_6.data[objIndex].v = value;
}
if (id === 7) {
objIndex = emsesp_devicedata_7.data.findIndex((obj) => obj.c == devicevalue.c);
emsesp_devicedata_7.data[objIndex] = devicevalue;
objIndex = emsesp_devicedata_7.data.findIndex((obj) => obj.c == command);
emsesp_devicedata_7.data[objIndex].v = value;
}
// custom entities
if (id === 99) {
objIndex = emsesp_devicedata_99.data.findIndex((obj) => obj.c == devicevalue.c);
emsesp_devicedata_99.data[objIndex] = devicevalue;
objIndex = emsesp_devicedata_99.data.findIndex((obj) => obj.c == command);
emsesp_devicedata_99.data[objIndex].v = value;
}
await delay(1000); // wait to show spinner

View File

@@ -841,7 +841,7 @@ std::string EMSdevice::get_value_uom(const std::string & shortname) const {
return std::string{}; // not found
}
bool EMSdevice::export_values(uint8_t device_type, JsonObject & output, const int8_t id, const uint8_t output_target) {
bool EMSdevice::export_values(uint8_t unique_id, JsonObject & output, const int8_t id, const uint8_t output_target) {
bool has_value = false;
uint8_t tag;
if (id >= 1 && id <= (1 + DeviceValueTAG::TAG_HS16 - DeviceValueTAG::TAG_HC1)) {
@@ -854,7 +854,7 @@ bool EMSdevice::export_values(uint8_t device_type, JsonObject & output, const in
if (id > 0 || output_target == EMSdevice::OUTPUT_TARGET::API_VERBOSE) {
for (const auto & emsdevice : EMSESP::emsdevices) {
if (emsdevice && (emsdevice->device_type() == device_type)) {
if (emsdevice->unique_id() == unique_id) {
has_value |= emsdevice->generate_values(output, tag, (id < 1), output_target); // use nested for id -1 and 0
}
}
@@ -866,7 +866,7 @@ bool EMSdevice::export_values(uint8_t device_type, JsonObject & output, const in
JsonObject output_hc = output;
bool nest_created = false;
for (const auto & emsdevice : EMSESP::emsdevices) {
if (emsdevice && (emsdevice->device_type() == device_type)) {
if (emsdevice->unique_id() == unique_id) {
if (!nest_created && emsdevice->has_tags(tag)) {
output_hc = output.createNestedObject(EMSdevice::tag_to_mqtt(tag));
nest_created = true;

View File

@@ -112,14 +112,10 @@ bool System::command_allvalues(const char * value, const int8_t id, JsonObject &
DynamicJsonDocument doc(EMSESP_JSON_SIZE_XXXLARGE);
JsonObject device_output;
for (const auto & device_class : EMSFactory::device_handlers()) {
for (const auto & emsdevice : EMSESP::emsdevices) {
if (emsdevice->device_type() == device_class.first) {
std::string title = emsdevice->device_type_2_device_name_translated() + std::string(" ") + emsdevice->to_string();
device_output = output.createNestedObject(title);
emsesp::EMSdevice::export_values(emsdevice->device_type(), device_output, id, EMSdevice::OUTPUT_TARGET::API_VERBOSE);
}
}
emsesp::EMSdevice::export_values(emsdevice->unique_id(), device_output, id, EMSdevice::OUTPUT_TARGET::API_VERBOSE);
}
// Custom entities

View File

@@ -37,9 +37,8 @@ bool Test::run_test(const char * command, int8_t id) {
// simulate HansRemmerswaal's setup - see https://github.com/emsesp/EMS-ESP32/issues/859
add_device(0x08, 172); // 176 entities - boiler: Enviline/Compress 6000AW/Hybrid 3000-7000iAW/SupraEco/Geo 5xx/WLW196i
// add_device(0x10, 158); // 62 entities - thermostat: RC300/RC310/Moduline 3000/1010H/CW400/Sense II/HPC410
// add_device(0x38, 200); // 4 entities - thermostat: RC100H
add_device(0x10, 158); // 62 entities - thermostat: RC300/RC310/Moduline 3000/1010H/CW400/Sense II/HPC410
add_device(0x38, 200); // 4 entities - thermostat: RC100H
return true;
}
@@ -47,9 +46,13 @@ bool Test::run_test(const char * command, int8_t id) {
if (strcmp(command, "general") == 0) {
EMSESP::logger().info("Testing general. Adding a Boiler and Thermostat");
// System::test_set_all_active(true); // uncomment if we want to show all entities and give them fake values
add_device(0x08, 123); // Nefit Trendline
add_device(0x18, 157); // Bosch CR100
// add_device(0x10, 158); // RC300 - there's no data here
// add some data
// Boiler -> Me, UBAMonitorFast(0x18), telegram: 08 00 18 00 00 02 5A 73 3D 0A 10 65 40 02 1A 80 00 01 E1 01 76 0E 3D 48 00 C9 44 02 00 (#data=25)
uart_telegram({0x08, 0x00, 0x18, 0x00, 0x00, 0x02, 0x5A, 0x73, 0x3D, 0x0A, 0x10, 0x65, 0x40, 0x02, 0x1A,

View File

@@ -230,15 +230,21 @@ void WebDataService::device_data(AsyncWebServerRequest * request) {
// assumes the service has been checked for admin authentication
void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVariant & json) {
if (json.is<JsonObject>()) {
JsonObject dv = json["devicevalue"];
uint8_t unique_id = json["id"];
uint8_t unique_id = json["id"]; // unique ID
const char * cmd = json["c"]; // the command
JsonVariant data = json["v"]; // the value in any format
// quit on bad values
if (strlen(cmd) == 0 || data.isNull()) {
AsyncWebServerResponse * response = request->beginResponse(400); // bad request
request->send(response);
return;
}
// using the unique ID from the web find the real device type
// id is the selected device
for (const auto & emsdevice : EMSESP::emsdevices) {
if (emsdevice->unique_id() == unique_id) {
// parse the command as it could have a hc or wwc prefixed, e.g. hc2/seltemp
const char * cmd = dv["c"]; // the command
int8_t id = -1; // default
cmd = Command::parse_command_string(cmd, id); // extract hc or wwc
@@ -248,7 +254,6 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
// the data could be in any format, but we need string
// authenticated is always true
JsonVariant data = dv["v"]; // the value in any format
uint8_t return_code = CommandRet::NOT_FOUND;
uint8_t device_type = emsdevice->device_type();
if (data.is<const char *>()) {
@@ -278,14 +283,14 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
return;
}
}
// special check for custom entities (which have a unique id of 99)
if (unique_id == 99) {
// parse the command as it could have a hc or wwc prefixed, e.g. hc2/seltemp
const char * cmd = dv["c"];
int8_t id = -1;
cmd = Command::parse_command_string(cmd, id);
auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_SMALL);
JsonObject output = response->getRoot();
JsonVariant data = dv["v"]; // the value in any format
uint8_t return_code = CommandRet::NOT_FOUND;
uint8_t device_type = EMSdevice::DeviceType::CUSTOM;
if (data.is<const char *>()) {
@@ -304,6 +309,7 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
EMSESP::logger().debug("Write command successful");
#endif
}
response->setCode((return_code == CommandRet::OK) ? 200 : 400); // bad request
response->setLength();
request->send(response);
@@ -311,6 +317,7 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
}
}
// if we reach here, fail
AsyncWebServerResponse * response = request->beginResponse(400); // bad request
request->send(response);
}