Add internet volume dashboard view
This commit is contained in:
@@ -166,10 +166,10 @@ globals:
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: '0'
|
||||
- id: internet_graph_view
|
||||
type: bool
|
||||
- id: internet_view
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: 'false'
|
||||
initial_value: '0'
|
||||
# 361 ten-second samples span one hour; unfilled slots are never drawn.
|
||||
- id: internet_download_history
|
||||
type: std::array<float, 361>
|
||||
@@ -295,6 +295,23 @@ sensor:
|
||||
id: internet_upload
|
||||
entity_id: sensor.internet_speed_out
|
||||
internal: true
|
||||
# Utility meters inherit the SNMP counters' byte (B) unit.
|
||||
- platform: homeassistant
|
||||
id: internet_download_daily
|
||||
entity_id: sensor.daily_internet_traffic_in
|
||||
internal: true
|
||||
- platform: homeassistant
|
||||
id: internet_upload_daily
|
||||
entity_id: sensor.daily_internet_traffic_out
|
||||
internal: true
|
||||
- platform: homeassistant
|
||||
id: internet_download_monthly
|
||||
entity_id: sensor.monthly_internet_traffic_in
|
||||
internal: true
|
||||
- platform: homeassistant
|
||||
id: internet_upload_monthly
|
||||
entity_id: sensor.monthly_internet_traffic_out
|
||||
internal: true
|
||||
- platform: wireguard
|
||||
latest_handshake:
|
||||
name: 'WireGuard Latest Handshake'
|
||||
@@ -331,7 +348,7 @@ script:
|
||||
} else if (id(page_index) == 2) {
|
||||
id(clock_digital_view) = !id(clock_digital_view);
|
||||
} else if (id(page_index) == 3) {
|
||||
id(internet_graph_view) = !id(internet_graph_view);
|
||||
id(internet_view) = (id(internet_view) + 1) % 3;
|
||||
}
|
||||
- component.update: tft
|
||||
- id: show_next_page
|
||||
@@ -709,7 +726,7 @@ display:
|
||||
return std::string(text);
|
||||
};
|
||||
|
||||
if (!id(internet_graph_view)) {
|
||||
if (id(internet_view) == 0) {
|
||||
it.print(12, 10, id(font_small), Color::WHITE, "Internet");
|
||||
const int cx = 160, cy = 188;
|
||||
const float download_fraction = download_valid
|
||||
@@ -730,7 +747,7 @@ display:
|
||||
it.printf(cx, 204, id(font_device), Color::WHITE, TextAlign::TOP_CENTER,
|
||||
"Max: DL %.0f / UL %.0f Mbps",
|
||||
${internet_download_gauge_max_mbps}, ${internet_upload_gauge_max_mbps});
|
||||
} else {
|
||||
} else if (id(internet_view) == 1) {
|
||||
it.print(12, 10, id(font_device), Color::WHITE, "Internet · 1 h");
|
||||
const int left = 28, right = 308, top = 62, zero = 122, bottom = 182;
|
||||
const int count = id(internet_history_count);
|
||||
@@ -797,6 +814,36 @@ display:
|
||||
it.print(160, 90, id(font_small), Color::WHITE, TextAlign::TOP_CENTER,
|
||||
"Warte auf Messwerte");
|
||||
}
|
||||
} else {
|
||||
it.print(12, 10, id(font_device), Color::WHITE, "Internet · Volumen");
|
||||
auto format_volume = [&](sensor::Sensor *source) -> std::string {
|
||||
if (!connected || !source->has_state() || !std::isfinite(source->state)
|
||||
|| source->state < 0.0f) return "--";
|
||||
const char *units[] = {"B", "kB", "MB", "GB", "TB"};
|
||||
double volume = source->state;
|
||||
int unit = 0;
|
||||
while (volume >= 1000.0 && unit < 4) {
|
||||
volume /= 1000.0;
|
||||
unit++;
|
||||
}
|
||||
char text[32];
|
||||
snprintf(text, sizeof(text), "%.2f %s", volume, units[unit]);
|
||||
return std::string(text);
|
||||
};
|
||||
it.print(108, 40, id(font_small), download_color, TextAlign::TOP_CENTER, "Download");
|
||||
it.print(244, 40, id(font_small), upload_color, TextAlign::TOP_CENTER, "Upload");
|
||||
const char *periods[] = {"Heute", "Dieser Monat"};
|
||||
sensor::Sensor *downloads[] = {id(internet_download_daily), id(internet_download_monthly)};
|
||||
sensor::Sensor *uploads[] = {id(internet_upload_daily), id(internet_upload_monthly)};
|
||||
for (int period = 0; period < 2; period++) {
|
||||
const int y = 72 + period * 72;
|
||||
it.print(12, y, id(font_small), Color::WHITE, periods[period]);
|
||||
it.printf(108, y + 22, id(font_internet_value), download_color, TextAlign::TOP_CENTER,
|
||||
"%s", format_volume(downloads[period]).c_str());
|
||||
it.printf(244, y + 22, id(font_internet_value), upload_color, TextAlign::TOP_CENTER,
|
||||
"%s", format_volume(uploads[period]).c_str());
|
||||
}
|
||||
it.line(12, 132, 308, 132, muted);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -818,6 +865,7 @@ display:
|
||||
id(clock_digital_view) ? 2 : 1);
|
||||
} else if (id(page_index) == 3) {
|
||||
it.printf(160, 239, id(font_small), Color::WHITE, TextAlign::BOTTOM_CENTER,
|
||||
"%s · %d / 2", id(internet_graph_view) ? "Verlauf" : "Live",
|
||||
id(internet_graph_view) ? 2 : 1);
|
||||
"%s · %d / 3", id(internet_view) == 0 ? "Live"
|
||||
: id(internet_view) == 1 ? "Verlauf" : "Volumen",
|
||||
id(internet_view) + 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user