From a378e86d63d0015b7ec22e840639604c08700682 Mon Sep 17 00:00:00 2001 From: netmindz Date: Sun, 7 Jan 2024 13:48:09 +0000 Subject: [PATCH 1/5] Add rowLimit option --- README.md | 2 +- octopus-energy-rates-card.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 67015e3..5a7bcd4 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ Here's a breakdown of all the available configuration items: | cheapest | Y | false | If true show the cheapest rate in light green / light blue | | combinerate | Y | false | If true combine rows where the rate is the same price, useful if you have a daily tracker tarrif for instance | | multiplier | Y | 100 | multiple rate values for pence (100) or pounds (1) | - +| rowLimit | Y | N/A | Limit number of rates to display, useful if you only want to only show next 4 rates #### A note on colouring diff --git a/octopus-energy-rates-card.js b/octopus-energy-rates-card.js index 8072675..9bec18f 100644 --- a/octopus-energy-rates-card.js +++ b/octopus-energy-rates-card.js @@ -129,6 +129,7 @@ class OctopusEnergyRatesCard extends HTMLElement { const cheapest = config.cheapest; const combinerate = config.combinerate; const multiplier = config.multiplier + const rowLimit = config.rowLimit var colours = (config.exportrates ? colours_export : colours_import); var rates_totalnumber = 0; var combinedRates = []; @@ -229,6 +230,9 @@ class OctopusEnergyRatesCard extends HTMLElement { previous_rate = ratesToEvaluate; previous_rates_day = current_rates_day; } + if(rowLimit > 0 && rates_list_length == rowLimit) { + break; + } }); const rows_per_col = Math.ceil(rates_list_length / config.cols); @@ -351,7 +355,9 @@ class OctopusEnergyRatesCard extends HTMLElement { // Combine equal rates combinerate: false, // multiple rate values for pence (100) or pounds (1) - multiplier: 100 + multiplier: 100, + // Limit display to next X rows + rowLimit: 0 }; const cardConfig = { From 6520ee466a241de9fd24140afa44de660422ccf9 Mon Sep 17 00:00:00 2001 From: netmindz Date: Sun, 7 Jan 2024 13:54:33 +0000 Subject: [PATCH 2/5] Rename option to rateListLimit --- README.md | 2 +- octopus-energy-rates-card.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5a7bcd4..442abd2 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ Here's a breakdown of all the available configuration items: | cheapest | Y | false | If true show the cheapest rate in light green / light blue | | combinerate | Y | false | If true combine rows where the rate is the same price, useful if you have a daily tracker tarrif for instance | | multiplier | Y | 100 | multiple rate values for pence (100) or pounds (1) | -| rowLimit | Y | N/A | Limit number of rates to display, useful if you only want to only show next 4 rates +| rateListLimit | Y | N/A | Limit number of rates to display, useful if you only want to only show next 4 rates #### A note on colouring diff --git a/octopus-energy-rates-card.js b/octopus-energy-rates-card.js index 9bec18f..68ef13c 100644 --- a/octopus-energy-rates-card.js +++ b/octopus-energy-rates-card.js @@ -129,7 +129,7 @@ class OctopusEnergyRatesCard extends HTMLElement { const cheapest = config.cheapest; const combinerate = config.combinerate; const multiplier = config.multiplier - const rowLimit = config.rowLimit + const rateListLimit = config.rateListLimit var colours = (config.exportrates ? colours_export : colours_import); var rates_totalnumber = 0; var combinedRates = []; @@ -230,7 +230,7 @@ class OctopusEnergyRatesCard extends HTMLElement { previous_rate = ratesToEvaluate; previous_rates_day = current_rates_day; } - if(rowLimit > 0 && rates_list_length == rowLimit) { + if(rateListLimit > 0 && rates_list_length == rateListLimit) { break; } }); @@ -357,7 +357,7 @@ class OctopusEnergyRatesCard extends HTMLElement { // multiple rate values for pence (100) or pounds (1) multiplier: 100, // Limit display to next X rows - rowLimit: 0 + rateListLimit: 0 }; const cardConfig = { From f085b5326ebd0c7e37f13c1494d9dbf3830a0979 Mon Sep 17 00:00:00 2001 From: netmindz Date: Sun, 7 Jan 2024 14:10:44 +0000 Subject: [PATCH 3/5] correct way to break forEach --- octopus-energy-rates-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopus-energy-rates-card.js b/octopus-energy-rates-card.js index 68ef13c..1fc59dd 100644 --- a/octopus-energy-rates-card.js +++ b/octopus-energy-rates-card.js @@ -231,7 +231,7 @@ class OctopusEnergyRatesCard extends HTMLElement { previous_rates_day = current_rates_day; } if(rateListLimit > 0 && rates_list_length == rateListLimit) { - break; + return false; } }); From 3d177afe94ae2caefb743f097c4d67e33b727671 Mon Sep 17 00:00:00 2001 From: netmindz Date: Sun, 7 Jan 2024 14:20:49 +0000 Subject: [PATCH 4/5] Update octopus-energy-rates-card.js --- octopus-energy-rates-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopus-energy-rates-card.js b/octopus-energy-rates-card.js index 1fc59dd..bc5db6c 100644 --- a/octopus-energy-rates-card.js +++ b/octopus-energy-rates-card.js @@ -231,7 +231,7 @@ class OctopusEnergyRatesCard extends HTMLElement { previous_rates_day = current_rates_day; } if(rateListLimit > 0 && rates_list_length == rateListLimit) { - return false; + throw new Error(); // not ideal, but forEach doesn't check return nor support break } }); From ffd08806a5919cc540d49bc2c37591471f0b0042 Mon Sep 17 00:00:00 2001 From: netmindz Date: Sun, 7 Jan 2024 14:38:28 +0000 Subject: [PATCH 5/5] Update octopus-energy-rates-card.js --- octopus-energy-rates-card.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/octopus-energy-rates-card.js b/octopus-energy-rates-card.js index bc5db6c..2c24204 100644 --- a/octopus-energy-rates-card.js +++ b/octopus-energy-rates-card.js @@ -203,7 +203,7 @@ class OctopusEnergyRatesCard extends HTMLElement { rates_processingRow ++; var ratesToEvaluate = key.value_inc_vat * multiplier; - if(showpast || (date - Date.parse(new Date())>-1800000)) + if((showpast || (date - Date.parse(new Date())>-1800000)) && (rateListLimit == 0 || rates_list_length < rateListLimit)) { rates_currentNumber++; @@ -230,9 +230,6 @@ class OctopusEnergyRatesCard extends HTMLElement { previous_rate = ratesToEvaluate; previous_rates_day = current_rates_day; } - if(rateListLimit > 0 && rates_list_length == rateListLimit) { - throw new Error(); // not ideal, but forEach doesn't check return nor support break - } }); const rows_per_col = Math.ceil(rates_list_length / config.cols);