Skip to content

Commit

Permalink
feat: move library out of component
Browse files Browse the repository at this point in the history
  • Loading branch information
bramstroker committed Apr 12, 2024
1 parent 532432b commit 4c930b1
Show file tree
Hide file tree
Showing 940 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/lut_validator/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const validColorModeCombinations = [
]

const main = async () => {
const dataDirectory = path.join(__dirname, '../../../custom_components/powercalc/data')
const dataDirectory = path.join(__dirname, '../../../profile_library')
let errors = []
for await (const model_dir of readdirp(dataDirectory, {depth: 2, type: 'directories'})) {
if (!model_dir.path.includes('/')) {
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/supported_models/generate_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
]

PROJECT_ROOT = os.path.realpath(os.path.join(os.path.abspath(__file__), "../../../../"))
DATA_DIR = f"{PROJECT_ROOT}/custom_components/powercalc/data"
DATA_DIR = f"{PROJECT_ROOT}/profile_library"


def generate_supported_model_list(model_listing: list[dict]):
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/generate-model-list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,4 @@ jobs:
if: github.ref == 'refs/heads/master'
with:
add: 'docs/supported_models.md'
message: 'Update support model list'
- uses: EndBug/add-and-commit@v9
if: github.ref == 'refs/heads/master'
with:
add: 'custom_components/powercalc/data/manufacturer_device_types.json'
message: 'Update manufacturer_device_types.json'
message: 'Update support model list'
4 changes: 2 additions & 2 deletions .github/workflows/validate-model-json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request_target:
paths:
- '**/model.json'
- 'custom_components/powercalc/data/model_schema.json'
- 'profile_library/model_schema.json'

permissions:
issues: write
Expand All @@ -23,7 +23,7 @@ jobs:
uses: bramstroker/json-schema-validator@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
json_schema: ./custom_components/powercalc/data/model_schema.json
json_schema: ./profile_library/model_schema.json
json_path_pattern: .*/data/([^/]+/)?([^/]+/)?model.json$
send_comment: true
clear_comments: true
2 changes: 1 addition & 1 deletion custom_components/powercalc/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def evaluate_power(power: Template | Decimal | float) -> Decimal | None:

def get_library_path(sub_path: str = "") -> str:
"""Get the path to the library file."""
base_path = os.path.join(os.path.dirname(__file__), "data")
base_path = os.path.join(os.path.dirname(__file__), "../../profile_library")
return f"{base_path}/{sub_path}"


Expand Down
4 changes: 3 additions & 1 deletion custom_components/powercalc/power_profile/power_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from awesomeversion.awesomeversion import AwesomeVersion
from homeassistant.const import __version__ as HA_VERSION # noqa

from custom_components.powercalc.helpers import get_library_path

if AwesomeVersion(HA_VERSION) >= AwesomeVersion("2023.8.0"):
from enum import StrEnum
else:
Expand Down Expand Up @@ -77,7 +79,7 @@ def __init__(
def get_model_directory(self, root_only: bool = False) -> str:
"""Get the model directory containing the data files."""
if self.linked_lut:
return os.path.join(os.path.dirname(__file__), "../data", self.linked_lut)
return get_library_path(self.linked_lut)

if root_only:
return self._directory
Expand Down
2 changes: 1 addition & 1 deletion docs/source/contributing/measure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Submitting your work with a Pull Request
To create a Pull Request (PR) on the Powercalc GitHub repository, follow these steps:

1. Fork the repository by clicking on the "Fork" button on the top right of the repository page. This will create a copy of the repository under your own account.
2. Next, upload the directory containing your changes to the custom_components/powercalc/data directory of your forked repository. Make sure to keep the manufacturer/model folders intact.
2. Next, upload the directory containing your changes to the profile_library directory of your forked repository. Make sure to keep the manufacturer/model folders intact.
3. If you're familiar with Git, you can also use a Git client to make the changes to your local copy of the repository, commit the changes, and push them to your forked repository on GitHub.
4. Once your changes have been uploaded to your forked repository, go to the original repository and click on the "New Pull Request" button. This will open a new page where you can review the changes and submit the PR for review.
5. Once the PR is submitted, the repository maintainers will review your changes and may request additional changes or merge the PR into the main repository.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/library/structure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ model.json
----------

Every model MUST contain a ``model.json`` file which defines the supported calculation modes and other configuration.
See the `json schema <https://github.com/bramstroker/homeassistant-powercalc/blob/master/custom_components/powercalc/data/model_schema.json>`_ how the file must be structured or the examples below.
See the `json schema <https://github.com/bramstroker/homeassistant-powercalc/blob/master/profile_library/model_schema.json>`_ how the file must be structured or the examples below.

When the calculation strategy is ``lut`` also [CSV lookup files](#lut-data-files) must be provided, which can be created by running the measure tool.

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 4c930b1

Please sign in to comment.