Skip to content

Commit

Permalink
Add a name to a Sunalyzer instance (#84)
Browse files Browse the repository at this point in the history
* fixes

* fix Readme.md, reference correct repo
* fix reference of css files to give custom.css highest prio
* fix typos in localization.js

* fix numberic

* add name feature to name Sunalyzer instances
  • Loading branch information
smezger authored Sep 27, 2024
1 parent 2e63063 commit a0ea44b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
11 changes: 11 additions & 0 deletions backend/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,17 @@ def handle_request():
data = {"state": "error"}
return json.dumps(data)

@app.route("/name", methods=['GET'])
def handle_name():

try:
return json.dumps(config.config_data['sunalyzer']['name'])
logging.debug(f"Server: REST request of type 'name' received")
except Exception:
logging.exception("Error while handling HTTP request")
data = {"state": "error"}
return json.dumps(data)


# Main loop
def main():
Expand Down
2 changes: 1 addition & 1 deletion site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<!-- Logo -->
<a class="navbar-brand ps-3"><img src="favicon.ico" width="26" height="26">
Sunalyzer</a>
<span id="instance-name">Sunalyzer</span></a>

<!-- More settings -->
<ul class="navbar-nav ms-auto pe-4">
Expand Down
14 changes: 14 additions & 0 deletions site/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,22 @@ window.addEventListener('DOMContentLoaded', event => {
initSelectionBoxes();
updateCsvDateSelector();
setVersion();
setName();
});

function setName() {
fetchNameJSON().then(name =>{
document.getElementById("instance-name").innerHTML = "Sunalyzer "+name;
document.title ="Sunalyzer "+ name;
})
}

async function fetchNameJSON() {
const response = await fetch(gBaseUrl + 'name');
const name = await response.json();
return name;
}

function restoreSettings() {
var ts = localStorage.getItem("dash_time_span");
if (ts != null)
Expand Down
5 changes: 4 additions & 1 deletion templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ prices:
price_per_grid_kwh: 0.325 # Price for 1 kWh from the grid in Euro
revenue_per_fed_in_kwh: 0.085 # Revenue for one fed in kWh in Euro


# General Sunalyzer Config
sunalyzer:
name: "My Site" # Name of the Sunalyzer instance

## Internal Settings. Do not modify!

# Web server configuration. Do not modify!
Expand Down

0 comments on commit a0ea44b

Please sign in to comment.