Skip to content

Commit

Permalink
Merge pull request emsesp#2014 from proddy/dev
Browse files Browse the repository at this point in the history
small changes
  • Loading branch information
proddy authored Sep 15, 2024
2 parents 2e4a295 + 5cb4f48 commit 865cd63
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 90 deletions.
10 changes: 5 additions & 5 deletions interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"async-validator": "^4.2.5",
"jwt-decode": "^4.0.0",
"mime-types": "^2.1.35",
"preact": "^10.23.2",
"preact": "^10.24.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-icons": "^5.3.0",
Expand All @@ -44,10 +44,10 @@
"@babel/core": "^7.25.2",
"@eslint/js": "^9.10.0",
"@preact/compat": "^18.3.1",
"@preact/preset-vite": "^2.9.0",
"@preact/preset-vite": "^2.9.1",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/formidable": "^3",
"@types/node": "^22.5.4",
"@types/node": "^22.5.5",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"@types/react-router-dom": "^5.3.3",
Expand All @@ -59,9 +59,9 @@
"rollup-plugin-visualizer": "^5.12.0",
"terser": "^5.32.0",
"typescript-eslint": "8.5.0",
"vite": "^5.4.4",
"vite": "^5.4.5",
"vite-plugin-imagemin": "^0.6.1",
"vite-tsconfig-paths": "^5.0.1"
},
"packageManager": "yarn@4.4.1"
"packageManager": "yarn@4.5.0"
}
48 changes: 28 additions & 20 deletions interface/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1054,9 +1054,9 @@ __metadata:
languageName: node
linkType: hard

"@preact/preset-vite@npm:^2.9.0":
version: 2.9.0
resolution: "@preact/preset-vite@npm:2.9.0"
"@preact/preset-vite@npm:^2.9.1":
version: 2.9.1
resolution: "@preact/preset-vite@npm:2.9.1"
dependencies:
"@babel/code-frame": "npm:^7.22.13"
"@babel/plugin-transform-react-jsx": "npm:^7.22.15"
Expand All @@ -1068,13 +1068,12 @@ __metadata:
kolorist: "npm:^1.8.0"
magic-string: "npm:0.30.5"
node-html-parser: "npm:^6.1.10"
resolve: "npm:^1.22.8"
source-map: "npm:^0.7.4"
stack-trace: "npm:^1.0.0-pre2"
peerDependencies:
"@babel/core": 7.x
vite: 2.x || 3.x || 4.x || 5.x
checksum: 10c0/658e3dc048d1f1d8ad7cb1fef4a3db0f933be4e00d3d6cdfbd29fe7ec02341b3a26747520a5b261992923b3d3f49800c23a4d77da849e708a5c1ad9a920343b2
checksum: 10c0/6c2f2a7f06b08b2bd817d493101c4654891d6b86f661d48e2fb0b1388289bc4cb40b11a9ab30f9a12f818a28a1b48d60d97b24b8d3376c317a9d8abe06a68b1e
languageName: node
linkType: hard

Expand Down Expand Up @@ -1417,7 +1416,7 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:*, @types/node@npm:^22.5.4":
"@types/node@npm:*":
version: 22.5.4
resolution: "@types/node@npm:22.5.4"
dependencies:
Expand All @@ -1426,6 +1425,15 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:^22.5.5":
version: 22.5.5
resolution: "@types/node@npm:22.5.5"
dependencies:
undici-types: "npm:~6.19.2"
checksum: 10c0/ead9495cfc6b1da5e7025856dcce2591e9bae635357410c0d2dd619fce797d2a1d402887580ca4b336cb78168b195224869967de370a23f61663cf1e4836121c
languageName: node
linkType: hard

"@types/parse-json@npm:^4.0.0":
version: 4.0.2
resolution: "@types/parse-json@npm:4.0.2"
Expand Down Expand Up @@ -1635,11 +1643,11 @@ __metadata:
"@mui/icons-material": "npm:^6.1.0"
"@mui/material": "npm:^6.1.0"
"@preact/compat": "npm:^18.3.1"
"@preact/preset-vite": "npm:^2.9.0"
"@preact/preset-vite": "npm:^2.9.1"
"@table-library/react-table-library": "npm:4.1.7"
"@trivago/prettier-plugin-sort-imports": "npm:^4.3.0"
"@types/formidable": "npm:^3"
"@types/node": "npm:^22.5.4"
"@types/node": "npm:^22.5.5"
"@types/react": "npm:^18.3.5"
"@types/react-dom": "npm:^18.3.0"
"@types/react-router-dom": "npm:^5.3.3"
Expand All @@ -1651,7 +1659,7 @@ __metadata:
formidable: "npm:^3.5.1"
jwt-decode: "npm:^4.0.0"
mime-types: "npm:^2.1.35"
preact: "npm:^10.23.2"
preact: "npm:^10.24.0"
prettier: "npm:^3.3.3"
react: "npm:^18.3.1"
react-dom: "npm:^18.3.1"
Expand All @@ -1663,7 +1671,7 @@ __metadata:
typesafe-i18n: "npm:^5.26.2"
typescript: "npm:^5.6.2"
typescript-eslint: "npm:8.5.0"
vite: "npm:^5.4.4"
vite: "npm:^5.4.5"
vite-plugin-imagemin: "npm:^0.6.1"
vite-tsconfig-paths: "npm:^5.0.1"
languageName: unknown
Expand Down Expand Up @@ -5568,10 +5576,10 @@ __metadata:
languageName: node
linkType: hard

"preact@npm:^10.23.2":
version: 10.23.2
resolution: "preact@npm:10.23.2"
checksum: 10c0/6e0dc1b38ead7554c99ddec9a32162b456e8f622229413b136042a777445a12d115633cd49d6df83c30b64d721a0ad4d3c71bb468edc759c15799896e96fd9f2
"preact@npm:^10.24.0":
version: 10.24.0
resolution: "preact@npm:10.24.0"
checksum: 10c0/09d490d2326c511e205a96f81db0adf05f1b42dbe2a39be6fc494662c7476575494e96140252f351a0e3b3d15aee5b079bf963865bb01287f69c45c6755ed22e
languageName: node
linkType: hard

Expand Down Expand Up @@ -5897,7 +5905,7 @@ __metadata:
languageName: node
linkType: hard

"resolve@npm:^1.10.0, resolve@npm:^1.19.0, resolve@npm:^1.22.8":
"resolve@npm:^1.10.0, resolve@npm:^1.19.0":
version: 1.22.8
resolution: "resolve@npm:1.22.8"
dependencies:
Expand All @@ -5910,7 +5918,7 @@ __metadata:
languageName: node
linkType: hard

"resolve@patch:resolve@npm%3A^1.10.0#optional!builtin<compat/resolve>, resolve@patch:resolve@npm%3A^1.19.0#optional!builtin<compat/resolve>, resolve@patch:resolve@npm%3A^1.22.8#optional!builtin<compat/resolve>":
"resolve@patch:resolve@npm%3A^1.10.0#optional!builtin<compat/resolve>, resolve@patch:resolve@npm%3A^1.19.0#optional!builtin<compat/resolve>":
version: 1.22.8
resolution: "resolve@patch:resolve@npm%3A1.22.8#optional!builtin<compat/resolve>::version=1.22.8&hash=c3c19d"
dependencies:
Expand Down Expand Up @@ -6960,9 +6968,9 @@ __metadata:
languageName: node
linkType: hard

"vite@npm:^5.4.4":
version: 5.4.4
resolution: "vite@npm:5.4.4"
"vite@npm:^5.4.5":
version: 5.4.5
resolution: "vite@npm:5.4.5"
dependencies:
esbuild: "npm:^0.21.3"
fsevents: "npm:~2.3.3"
Expand Down Expand Up @@ -6999,7 +7007,7 @@ __metadata:
optional: true
bin:
vite: bin/vite.js
checksum: 10c0/2752e7dd5584ea7cc057742e8f5cbf2f2bd3a2bceb8794fbd3d52f1e88d362b5ac7f1c70be7a3d01b3d768320c8a8ad0df287fd72f253bf040423c36c67a3e89
checksum: 10c0/89c6459452fc238cdf8e99681b30996af171c9c557af476f96408a18a639fb5a0a6ee2d2257e005b21dc284edceb604595c34920cd4a007ad18f7ebafb654c76
languageName: node
linkType: hard

Expand Down
15 changes: 11 additions & 4 deletions scripts/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,24 @@
from termcolor import cprint

def print_success(x): return cprint(x, 'green')
def print_fail(x): return cprint(x, 'red')
def print_fail(x): return cprint('Error: '+x, 'red')

def on_upload(source, target, env):

# make sure we have set the upload_protocol to custom
if env.get('UPLOAD_PROTOCOL') != 'custom':
print_fail("Please set upload_protocol = custom in your pio_local.ini file when using upload.py")
return

# first check authentication
try:
username = env.GetProjectOption('custom_username')
password = env.GetProjectOption('custom_password')
emsesp_ip = env.GetProjectOption('custom_emsesp_ip')
except:
print('No authentication settings specified. Please, add these to your pio_local.ini file: \n\ncustom_username=username\ncustom_password=password\n')
print_fail('Missing settings. Add these to your pio_local.ini file: \n\ncustom_username=username\ncustom_password=password\ncustom_emsesp_ip=ems-esp.local\n')
return


emsesp_url = "http://" + env.GetProjectOption('custom_emsesp_ip')
parsed_url = urlparse(emsesp_url)
Expand All @@ -71,10 +78,10 @@ def on_upload(source, target, env):
response = requests.post(signon_url, json=username_password, headers=signon_headers)

if response.status_code != 200:
print_fail("Authentication failed (code " + str(response.status_code) + ")")
print_fail("Authentication with EMS-ESP failed (code " + str(response.status_code) + ")")
return

print_success("Authentication successful")
print_success("Authentication with EMS-ESP successful")
access_token = response.json().get('access_token')

# start the upload
Expand Down
66 changes: 32 additions & 34 deletions src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
//
// Show commands
//
commands->add_command(ShellContext::MAIN, CommandFlags::USER, {F_(show)}, [=](Shell & shell, const std::vector<std::string> & arguments) {
to_app(shell).system_.show_system(shell);
});
commands->add_command(ShellContext::MAIN,
CommandFlags::USER,
string_vector{F_(show), F_(system)},
Expand Down Expand Up @@ -125,7 +128,7 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
// create commands test
commands->add_command(ShellContext::MAIN,
CommandFlags::USER,
string_vector{"test"},
{"test"},
string_vector{F_(name_optional), F_(data_optional), F_(id_optional)},
[=](Shell & shell, const std::vector<std::string> & arguments) {
if (arguments.empty()) {
Expand All @@ -138,12 +141,12 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
Test::run_test(shell, arguments[0].c_str(), arguments[1].c_str(), arguments[2].c_str());
}
});
commands->add_command(ShellContext::MAIN, CommandFlags::USER, string_vector{"t"}, [=](Shell & shell, const std::vector<std::string> & arguments) {
commands->add_command(ShellContext::MAIN, CommandFlags::USER, {"t"}, [=](Shell & shell, const std::vector<std::string> & arguments) {
Test::run_test(shell, "default");
});
#endif

commands->add_command(ShellContext::MAIN, CommandFlags::USER, string_vector{F_(su)}, [=](Shell & shell, const std::vector<std::string> & arguments) {
commands->add_command(ShellContext::MAIN, CommandFlags::USER, {F_(su)}, [=](Shell & shell, const std::vector<std::string> & arguments) {
auto become_admin = [](Shell & shell) {
shell.logger().log(LogLevel::NOTICE, LogFacility::AUTH, F("Admin session opened on console %s"), to_shell(shell).console_name().c_str());
shell.add_flags(CommandFlags::ADMIN);
Expand Down Expand Up @@ -176,7 +179,7 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
}
});

commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, string_vector{F_(passwd)}, [](Shell & shell, const std::vector<std::string> & arguments) {
commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, {F_(passwd)}, [](Shell & shell, const std::vector<std::string> & arguments) {
shell.enter_password(F_(new_password_prompt1), [](Shell & shell, bool completed, const std::string & password1) {
if (completed) {
shell.enter_password(F_(new_password_prompt2), [password1](Shell & shell, bool completed, const std::string & password2) {
Expand All @@ -198,8 +201,8 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {

commands->add_command(ShellContext::MAIN,
CommandFlags::ADMIN,
string_vector{F_(restart)},
string_vector{F_(partitionname_optional)},
{F_(restart)},
{F_(partitionname_optional)},
[](Shell & shell, const std::vector<std::string> & arguments) {
if (arguments.size()) {
to_app(shell).system_.system_restart(arguments.front().c_str());
Expand Down Expand Up @@ -244,7 +247,7 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
commands->add_command(ShellContext::MAIN,
CommandFlags::ADMIN,
string_vector{F_(set), F_(hostname)},
string_vector{F_(name_mandatory)},
{F_(name_mandatory)},
[](Shell & shell, const std::vector<std::string> & arguments) {
shell.println("The network connection will be reset...");
Shell::loop_all();
Expand All @@ -258,7 +261,7 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
commands->add_command(ShellContext::MAIN,
CommandFlags::ADMIN,
string_vector{F_(set), F_(wifi), F_(ssid)},
string_vector{F_(name_mandatory)},
{F_(name_mandatory)},
[](Shell & shell, const std::vector<std::string> & arguments) {
to_app(shell).esp8266React.getNetworkSettingsService()->updateWithoutPropagation([&](NetworkSettings & networkSettings) {
networkSettings.ssid = arguments.front().c_str();
Expand All @@ -273,7 +276,7 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
ShellContext::MAIN,
CommandFlags::ADMIN,
string_vector{F_(set), F_(board_profile)},
string_vector{F_(name_mandatory)},
{F_(name_mandatory)},
[](Shell & shell, const std::vector<std::string> & arguments) {
std::vector<int8_t> data; // led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode
std::string board_profile = Helpers::toUpper(arguments.front());
Expand Down Expand Up @@ -303,7 +306,7 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
ShellContext::MAIN,
CommandFlags::ADMIN,
string_vector{F_(set), F_(bus_id)},
string_vector{F_(deviceid_mandatory)},
{F_(deviceid_mandatory)},
[](Shell & shell, const std::vector<std::string> & arguments) {
uint8_t device_id = Helpers::hextoint(arguments.front().c_str());
if ((device_id == 0x0B) || (device_id == 0x0D) || (device_id == 0x0A) || (device_id == 0x0F) || (device_id == 0x12)) {
Expand All @@ -323,7 +326,7 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
commands->add_command(ShellContext::MAIN,
CommandFlags::ADMIN,
string_vector{F_(set), F_(tx_mode)},
string_vector{F_(n_mandatory)},
{F_(n_mandatory)},
[](Shell & shell, const std::vector<std::string> & arguments) {
uint8_t tx_mode = std::strtol(arguments[0].c_str(), nullptr, 10);
// save the tx_mode
Expand Down Expand Up @@ -371,30 +374,25 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
// EMS device commands
//

commands->add_command(ShellContext::MAIN,
CommandFlags::ADMIN,
string_vector{F_(scan)},
string_vector{F_(deep_optional)},
[](Shell & shell, const std::vector<std::string> & arguments) {
if (arguments.size() == 0) {
to_app(shell).scan_devices();
} else {
shell.printfln("Performing a deep scan...");
to_app(shell).clear_all_devices();
// device IDs taken from device_library.h
// send the read command with Version command
const std::vector<uint8_t> Device_Ids = {0x02, 0x08, 0x09, 0x10, 0x11, 0x12, 0x15, 0x17, 0x18, 0x19, 0x1A,
0x1B, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29,
0x2A, 0x30, 0x38, 0x40, 0x41, 0x48, 0x50, 0x51, 0x60};
for (const uint8_t device_id : Device_Ids) {
to_app(shell).send_read_request(EMSdevice::EMS_TYPE_VERSION, device_id);
}
}
});
commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, {F_(scan)}, {F_(deep_optional)}, [](Shell & shell, const std::vector<std::string> & arguments) {
if (arguments.size() == 0) {
to_app(shell).scan_devices();
} else {
shell.printfln("Performing a deep scan...");
to_app(shell).clear_all_devices();
// device IDs taken from device_library.h
// send the read command with Version command
const std::vector<uint8_t> Device_Ids = {0x02, 0x08, 0x09, 0x10, 0x11, 0x12, 0x15, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x20, 0x21, 0x22, 0x23,
0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x30, 0x38, 0x40, 0x41, 0x48, 0x50, 0x51, 0x60};
for (const uint8_t device_id : Device_Ids) {
to_app(shell).send_read_request(EMSdevice::EMS_TYPE_VERSION, device_id);
}
}
});

commands->add_command(ShellContext::MAIN,
CommandFlags::USER,
string_vector{F_(read)},
{F_(read)},
string_vector{F_(deviceid_mandatory), F_(typeid_mandatory), F_(offset_optional), F_(length_optional)},
[=](Shell & shell, const std::vector<std::string> & arguments) {
uint8_t device_id = Helpers::hextoint(arguments.front().c_str());
Expand All @@ -420,7 +418,7 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {

commands->add_command(ShellContext::MAIN,
CommandFlags::USER,
string_vector{F_(watch)},
{F_(watch)},
string_vector{F_(watch_format_optional), F_(watchid_optional)},
[](Shell & shell, const std::vector<std::string> & arguments) {
uint16_t watch_id = WATCH_ID_NONE;
Expand Down Expand Up @@ -490,7 +488,7 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
commands->add_command(
ShellContext::MAIN,
CommandFlags::ADMIN,
string_vector{F_(call)},
{F_(call)},
string_vector{F_(device_type_optional), F_(cmd_optional), F_(data_optional), F_(id_optional)},
[&](Shell & shell, const std::vector<std::string> & arguments) {
if (arguments.empty()) {
Expand Down
4 changes: 2 additions & 2 deletions src/emsdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ void EMSdevice::add_device_value(int8_t tag, // to b
snprintf(entity, sizeof(entity), "%s/%s", tag_to_mqtt(tag), short_name);
}

for (std::string entity_id : entityCustomization.entity_ids) {
for (const std::string & entity_id : entityCustomization.entity_ids) {
// if there is an appended custom name, strip it to get the true entity name
// and extract the new custom name
auto custom_name_pos = entity_id.find('|');
Expand Down Expand Up @@ -1112,7 +1112,7 @@ void EMSdevice::generate_values_web_customization(JsonArray output) {
EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
for (EntityCustomization entityCustomization : settings.entityCustomizations) {
if (entityCustomization.device_id == device_id()) {
for (std::string entity_id : entityCustomization.entity_ids) {
for (const std::string & entity_id : entityCustomization.entity_ids) {
uint8_t mask = Helpers::hextoint(entity_id.substr(0, 2).c_str());
if (mask & 0x80) {
JsonObject obj = output.add<JsonObject>();
Expand Down
Loading

0 comments on commit 865cd63

Please sign in to comment.