mirror of
				https://github.com/Akkudoktor-EOS/EOS.git
				synced 2025-11-04 08:46:20 +00:00 
			
		
		
		
	
		
			Some checks failed
		
		
	
	docker-build / platform-excludes (push) Has been cancelled
				
			pre-commit / pre-commit (push) Has been cancelled
				
			Run Pytest on Pull Request / test (push) Has been cancelled
				
			docker-build / build (push) Has been cancelled
				
			docker-build / merge (push) Has been cancelled
				
			Close stale pull requests/issues / Find Stale issues and PRs (push) Has been cancelled
				
			* Fix logging configuration issues that made logging stop operation. Switch to Loguru logging (from Python logging). Enable console and file logging with different log levels. Add logging documentation. * Fix logging configuration and EOS configuration out of sync. Added tracking support for nested value updates of Pydantic models. This used to update the logging configuration when the EOS configurationm for logging is changed. Should keep logging config and EOS config in sync as long as all changes to the EOS logging configuration are done by set_nested_value(), which is the case for the REST API. * Fix energy management task looping endlessly after the second update when trying to update the last_update datetime. * Fix get_nested_value() to correctly take values from the dicts in a Pydantic model instance. * Fix usage of model classes instead of model instances in nested value access when evaluation the value type that is associated to each key. * Fix illegal json format in prediction documentation for PVForecastAkkudoktor provider. * Fix documentation qirks and add EOS Connect to integrations. * Support deprecated fields in configuration in documentation generation and EOSdash. * Enhance EOSdash demo to show BrightSky humidity data (that is often missing) * Update documentation reference to German EOS installation videos. Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
		
			
				
	
	
		
			79 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
#!.venv/bin/python
 | 
						|
"""This module generates the OpenAPI specification for the EOS application  defined in `akkudoktoreos.server.eos`.
 | 
						|
 | 
						|
The script can be executed directly to generate the OpenAPI specification
 | 
						|
either to the standard output or to a specified file.
 | 
						|
 | 
						|
Usage:
 | 
						|
    scripts/generate_openapi.py [--output-file OUTPUT_FILE]
 | 
						|
 | 
						|
Arguments:
 | 
						|
    --output-file : Optional. The file path to write the OpenAPI specification to.
 | 
						|
 | 
						|
Example:
 | 
						|
    scripts/generate_openapi.py --output-file openapi.json
 | 
						|
"""
 | 
						|
 | 
						|
import argparse
 | 
						|
import json
 | 
						|
import os
 | 
						|
import sys
 | 
						|
 | 
						|
from fastapi.openapi.utils import get_openapi
 | 
						|
 | 
						|
from akkudoktoreos.server.eos import app
 | 
						|
 | 
						|
 | 
						|
def generate_openapi() -> dict:
 | 
						|
    """Generate the OpenAPI specification.
 | 
						|
 | 
						|
    Returns:
 | 
						|
        openapi_spec (dict): OpenAPI specification.
 | 
						|
    """
 | 
						|
    openapi_spec = get_openapi(
 | 
						|
        title=app.title,
 | 
						|
        version=app.version,
 | 
						|
        openapi_version=app.openapi_version,
 | 
						|
        description=app.description,
 | 
						|
        routes=app.routes,
 | 
						|
    )
 | 
						|
 | 
						|
    # Fix file path for general settings to not show local/test file path
 | 
						|
    general = openapi_spec["components"]["schemas"]["ConfigEOS"]["properties"]["general"]["default"]
 | 
						|
    general["config_file_path"] = "/home/user/.config/net.akkudoktoreos.net/EOS.config.json"
 | 
						|
    general["config_folder_path"] = "/home/user/.config/net.akkudoktoreos.net"
 | 
						|
    # Fix file path for logging settings to not show local/test file path
 | 
						|
    logging = openapi_spec["components"]["schemas"]["ConfigEOS"]["properties"]["logging"]["default"]
 | 
						|
    logging["file_path"] = "/home/user/.local/share/net.akkudoktoreos.net/output/eos.log"
 | 
						|
 | 
						|
    return openapi_spec
 | 
						|
 | 
						|
 | 
						|
def main():
 | 
						|
    """Main function to run the generation of the OpenAPI specification."""
 | 
						|
    parser = argparse.ArgumentParser(description="Generate OpenAPI Specification")
 | 
						|
    parser.add_argument(
 | 
						|
        "--output-file", type=str, default=None, help="File to write the OpenAPI Specification to"
 | 
						|
    )
 | 
						|
 | 
						|
    args = parser.parse_args()
 | 
						|
 | 
						|
    try:
 | 
						|
        openapi_spec = generate_openapi()
 | 
						|
        openapi_spec_str = json.dumps(openapi_spec, indent=2)
 | 
						|
        if args.output_file:
 | 
						|
            # Write to file
 | 
						|
            with open(args.output_file, "w", encoding="utf-8", newline="\n") as f:
 | 
						|
                f.write(openapi_spec_str)
 | 
						|
        else:
 | 
						|
            # Write to std output
 | 
						|
            print(openapi_spec_str)
 | 
						|
 | 
						|
    except Exception as e:
 | 
						|
        print(f"Error during OpenAPI specification generation: {e}", file=sys.stderr)
 | 
						|
        sys.exit(1)
 | 
						|
 | 
						|
 | 
						|
if __name__ == "__main__":
 | 
						|
    main()
 |