2024-12-15 14:40:03 +01:00
|
|
|
import uvicorn
|
|
|
|
from fasthtml.common import H1, FastHTML, Table, Td, Th, Thead, Titled, Tr
|
|
|
|
|
|
|
|
from akkudoktoreos.config.config import get_config
|
2025-01-05 14:41:07 +01:00
|
|
|
from akkudoktoreos.core.logging import get_logger
|
2024-12-15 14:40:03 +01:00
|
|
|
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
|
|
config_eos = get_config()
|
|
|
|
|
|
|
|
|
|
|
|
configs = []
|
|
|
|
for field_name in config_eos.model_fields:
|
|
|
|
config = {}
|
|
|
|
config["name"] = field_name
|
|
|
|
config["value"] = getattr(config_eos, field_name)
|
|
|
|
config["default"] = config_eos.model_fields[field_name].default
|
|
|
|
config["description"] = config_eos.model_fields[field_name].description
|
|
|
|
configs.append(config)
|
|
|
|
|
|
|
|
|
|
|
|
app = FastHTML()
|
|
|
|
rt = app.route
|
|
|
|
|
|
|
|
|
|
|
|
def config_table() -> Table:
|
|
|
|
rows = [
|
|
|
|
Tr(
|
|
|
|
Td(config["name"]),
|
|
|
|
Td(config["value"]),
|
|
|
|
Td(config["default"]),
|
|
|
|
Td(config["description"]),
|
|
|
|
cls="even:bg-purple/5",
|
|
|
|
)
|
|
|
|
for config in configs
|
|
|
|
]
|
|
|
|
flds = "Name", "Value", "Default", "Description"
|
|
|
|
head = Thead(*map(Th, flds), cls="bg-purple/10")
|
|
|
|
return Table(head, *rows, cls="w-full")
|
|
|
|
|
|
|
|
|
|
|
|
@rt("/")
|
|
|
|
def get(): # type: ignore
|
2025-01-09 16:54:49 +01:00
|
|
|
return Titled("EOS Dashboard", H1("Configuration"), config_table())
|
2024-12-15 14:40:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
try:
|
2025-01-09 16:54:49 +01:00
|
|
|
logger.info(f"Starting {config_eos.server_eosdash_host}:{config_eos.server_eosdash_port}.")
|
2024-12-15 14:40:03 +01:00
|
|
|
uvicorn.run(
|
2025-01-09 16:54:49 +01:00
|
|
|
app, host=str(config_eos.server_eosdash_host), port=config_eos.server_eosdash_port
|
2024-12-15 14:40:03 +01:00
|
|
|
)
|
|
|
|
except Exception as e:
|
|
|
|
# Error handling for binding issues
|
|
|
|
logger.error(
|
2025-01-09 16:54:49 +01:00
|
|
|
f"Could not bind to host {config_eos.server_eosdash_host}:{config_eos.server_eosdash_port}. Error: {e}"
|
2024-12-15 14:40:03 +01:00
|
|
|
)
|
|
|
|
exit(1)
|