Skip to content

Conversation

@mime24
Copy link

@mime24 mime24 commented Dec 17, 2025

With this pull request, we are laying the foundation for enabling the data path /share/emhass in the add-on.
The path specified in the options is checked and any missing subfolders are created.

This is a prerequisite for the adjustment in the add-on. refer to davidusb-geek/emhass-add-on#122

Summary by Sourcery

Enhancements:

  • Relax the requirement for the configured data path to pre-exist by attempting to create the directory before using it and logging a warning if creation fails.

* create data path handed over via options.json

* new try

* work with try ald exept

* fix formating

* fix formatting

* fix formatting

* Exception Error message

---------

Co-authored-by: Michael Metz <[email protected]>
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 17, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR changes how the add-on resolves and prepares its data_path: instead of only using an existing path from options, it now attempts to create the directory, logs a warning on failure, and conditionally updates the configuration, laying groundwork for using paths like /share/emhass.

Sequence diagram for updated data_path handling in build_secrets

sequenceDiagram
    actor User
    participant AddonRuntime
    participant utils_build_secrets as utils_build_secrets
    participant Pathlib as pathlib_Path
    participant Logger as logger

    User ->> AddonRuntime: start_addon_with_options
    AddonRuntime ->> utils_build_secrets: build_secrets(options, emhass_conf, ...)

    utils_build_secrets ->> utils_build_secrets: read options data_path
    alt data_path is not None
        utils_build_secrets ->> Pathlib: Path(options_data_path)
        activate Pathlib
        Pathlib -->> utils_build_secrets: data_path_object
        deactivate Pathlib

        utils_build_secrets ->> Pathlib: data_path_object.mkdir(parents=False, exist_ok=True)
        alt mkdir succeeds
            utils_build_secrets ->> utils_build_secrets: emhass_conf data_path = data_path_object
        else mkdir raises Exception
            utils_build_secrets ->> Logger: warning(cannot create data_path directory...)
            Logger -->> utils_build_secrets: done
            utils_build_secrets ->> utils_build_secrets: keep default emhass_conf data_path
        end
    else data_path is None
        utils_build_secrets ->> utils_build_secrets: keep default emhass_conf data_path
    end

    utils_build_secrets -->> AddonRuntime: updated emhass_conf
    AddonRuntime -->> User: addon running with resolved data_path
Loading

Flow diagram for data_path directory creation logic

flowchart TD
    A[start_build_secrets] --> B{options_data_path_is_not_None}
    B -- Yes --> C["Create Path object from options data_path"]
    C --> D["Call mkdir on Path with parents=False and exist_ok=True"]
    D --> E{mkdir_raises_exception}
    E -- No --> F["Set emhass_conf data_path to created Path"]
    F --> G[end_build_secrets]
    E -- Yes --> H["Log warning via logger and keep default emhass_conf data_path"]
    H --> G
    B -- No --> I["Skip override and keep default emhass_conf data_path"]
    I --> G
Loading

File-Level Changes

Change Details Files
Update data_path handling to allow creation of the directory specified in options and log meaningful warnings on failure.
  • Remove the requirement that the options-provided data_path must already exist before being used.
  • Wrap data_path resolution and directory creation in a try/except block.
  • Attempt to create the configured data_path directory with mkdir and use it in emhass_conf when successful.
  • On any exception during directory creation, keep the default data_path and emit a warning including the error detail.
src/emhass/utils.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant