This commit is contained in:
MichaelDvP
2024-07-19 18:42:50 +02:00
9 changed files with 58 additions and 22 deletions

View File

@@ -314,16 +314,6 @@ const SystemStatus: FC = () => {
return (
<>
<List>
<ListItem>
<ListItemAvatar>
<Avatar sx={{ bgcolor: busStatusHighlight(), color: 'white' }}>
<DirectionsBusIcon />
</Avatar>
</ListItemAvatar>
<ListItemText primary={LL.EMS_BUS_STATUS()} secondary={busStatus()} />
</ListItem>
<Divider variant="inset" component="li" />
<ListItem>
<ListItemAvatar>
<Avatar sx={{ bgcolor: '#c5572c', color: 'white' }}>
@@ -347,7 +337,6 @@ const SystemStatus: FC = () => {
</ListItem>
<Divider variant="inset" component="li" />
<ListItem>
<ListItemAvatar>
<Avatar sx={{ bgcolor: '#5d89f7', color: 'white' }}>
@@ -375,8 +364,8 @@ const SystemStatus: FC = () => {
</Button>
)}
</ListItem>
<Divider variant="inset" component="li" />
<Divider variant="inset" component="li" />
<ListMenuItem
disabled={!me.admin}
icon={BuildIcon}
@@ -385,8 +374,18 @@ const SystemStatus: FC = () => {
text={data.emsesp_version}
to="/settings/upload"
/>
<Divider variant="inset" component="li" />
<Divider variant="inset" component="li" />
<ListMenuItem
disabled={!me.admin}
icon={DirectionsBusIcon}
bgcolor={busStatusHighlight()}
label={LL.EMS_BUS_STATUS()}
text={busStatus()}
to="/system/activity"
/>
<Divider variant="inset" component="li" />
<ListMenuItem
disabled={!me.admin}
icon={MemoryIcon}
@@ -395,8 +394,8 @@ const SystemStatus: FC = () => {
text={formatNumber(data.free_heap) + ' KB' + ' ' + LL.FREE_MEMORY()}
to="/system/espsystemstatus"
/>
<Divider variant="inset" component="li" />
<Divider variant="inset" component="li" />
<ListMenuItem
disabled={!me.admin}
icon={
@@ -409,8 +408,8 @@ const SystemStatus: FC = () => {
text={networkStatus()}
to="/settings/network/status"
/>
<Divider variant="inset" component="li" />
<Divider variant="inset" component="li" />
<ListMenuItem
disabled={!me.admin}
icon={DeviceHubIcon}
@@ -419,8 +418,8 @@ const SystemStatus: FC = () => {
text={data.mqtt_status ? LL.ACTIVE() : LL.INACTIVE(0)}
to="/settings/mqtt/status"
/>
<Divider variant="inset" component="li" />
<Divider variant="inset" component="li" />
<ListMenuItem
disabled={!me.admin}
icon={AccessTimeIcon}
@@ -429,8 +428,8 @@ const SystemStatus: FC = () => {
text={ntpStatus()}
to="/settings/ntp/status"
/>
<Divider variant="inset" component="li" />
<Divider variant="inset" component="li" />
<ListMenuItem
disabled={!me.admin}
icon={SettingsInputAntennaIcon}

View File

@@ -41,7 +41,7 @@ class ChunkPrint : public Print {
}
};
// added msgPack by Proddy
// added msgPack by proddy for EMS-ESP
class AsyncJsonResponse : public AsyncAbstractResponse {
protected:
JsonDocument _jsonBuffer;

View File

@@ -329,9 +329,7 @@ class AsyncWebServerRequest {
AsyncResponseStream * beginResponseStream(const String & contentType, size_t bufferSize = 1460);
AsyncWebServerResponse * beginResponse_P(int code, const String & contentType, const uint8_t * content, size_t len, AwsTemplateProcessor callback = nullptr);
AsyncWebServerResponse * beginResponse_P(int code, const String & contentType, PGM_P content, AwsTemplateProcessor callback = nullptr);
// added by proddy for EMS-ESP
AsyncWebServerResponse * beginResponse(const String & contentType, const uint8_t * content, size_t len);
AsyncWebServerResponse * beginResponse(const String & contentType, const uint8_t * content, size_t len); // added by proddy for EMS-ESP
size_t headers() const; // get header count
bool hasHeader(const String & name) const; // check if header exists

Binary file not shown.

Binary file not shown.

View File

@@ -580,6 +580,7 @@ void Mqtt::ha_status() {
#endif
// These come from the heartbeat MQTT topic
// we don't use camelCase as it would change the HA entity_id and impact historic data
publish_system_ha_sensor_config(DeviceValueType::STRING, "EMS Bus", "bus_status", DeviceValueUOM::NONE);
publish_system_ha_sensor_config(DeviceValueType::STRING, "Uptime", "uptime", DeviceValueUOM::NONE);
publish_system_ha_sensor_config(DeviceValueType::INT8, "Uptime (sec)", "uptime_sec", DeviceValueUOM::SECONDS);

View File

@@ -1359,6 +1359,7 @@ bool System::get_value_info(JsonObject root, const char * command) {
// export status information including the device information
// http://ems-esp/api/system/info
// TODO camelCase - #1860
bool System::command_info(const char * value, const int8_t id, JsonObject output) {
JsonObject node;
@@ -1413,7 +1414,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
#endif
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & settings) {
if (WiFi.status() == WL_CONNECTED && !settings.bssid.isEmpty()) {
node["BSSID"] = "set"; // TODO why is this not the actual value??
node["BSSID"] = "set"; // we don't disclose the name
}
node["TxPower setting"] = settings.tx_power;
node["static ip config"] = settings.staticIPConfig;
@@ -1591,6 +1592,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
obj["name"] = emsdevice->name(); // custom name
obj["device id"] = Helpers::hextoa(emsdevice->device_id());
obj["product id"] = emsdevice->product_id();
obj["brand"] = emsdevice->brand_to_char();
obj["version"] = emsdevice->version();
obj["entities"] = emsdevice->count_entities();
char result[500];

View File

@@ -146,3 +146,23 @@ Content-Type: application/json
< ./standalone_file_export/emsesp_settings.json
------WebKitFormBoundary7MA4YWxkTrZu0gW--
# test calling Home Assistant script
# https://developers.home-assistant.io/docs/api/rest/#post-apiservicesdomainservice
POST {{host_standalone}}/api
# HA
@ha = http://192.168.1.42:8123
@ha_token = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIwMzMyZjU1MjhlZmM0NGIyOTgyMjIxNThiODU1NDkyNSIsImlhdCI6MTcyMTMwNDg2NSwiZXhwIjoyMDM2NjY0ODY1fQ.Q-Y7E_i7clH3ff4Ma-OMmhZfbN7aMi_CahKwmoar
###
GET {{ha}}/api/services
Content-Type: application/json
Authorization: Bearer {{ha_token}}
###
POST {{ha}}/api/services/script/test_notify
Content-Type: application/json
Authorization: Bearer {{ha_token}}

16
test/api_test.sh Executable file
View File

@@ -0,0 +1,16 @@
#!/bin/sh
# API
curl -X GET http://ems-esp.local/api/system/info
echo "\n"
# HA
ha_url="http://192.168.1.42:8123"
ha_token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIwMzMyZjU1MjhlZmM0NGIyOTgyMjIxNThiODU1NDkyNSIsImlhdCI6MTcyMTMwNDg2NSwiZXhwIjoyMDM2NjY0ODY1fQ.Q-Y7E_i7clH3ff4Ma-OMmhZfbN7aMi_CahKwmoar"
curl -X POST \
${ha_url}/api/services/script/test_notify \
-H "Authorization: Bearer ${ha_token}" \
-H "Content-Type: application/json" \