2023-07-23 14:24:22 -07:00
|
|
|
"""Update strings.json and en.json from const.py."""
|
2024-02-05 14:13:13 -08:00
|
|
|
|
Add scripts to auto update en.json, strings.json and services.yaml (#520)
* Add scripts to auto update strings.json and services.yaml
* Run services
* simplify
* Run strings
* rerun
* revert
* allow unicode
* Add CODEOWNERS
* Update CODEOWNERS
* set CONF_USE_DEFAULTS docs
* add field_name
* Auto run scripts
* Update desc
* Update README.md, strings.json, and services.yaml
* double quotes
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README.md, strings.json, and services.yaml
* Add newline
* sync changes between en.json and strings.json
* Update README.md, strings.json, and services.yaml
* double quotes
* fix
* Update README.md, strings.json, and services.yaml
* Add comments
* Remove comments
* shorter
* Update README.md, strings.json, and services.yaml
* Rephrase
* Update README.md, strings.json, and services.yaml
* remove key from desc
---------
Co-authored-by: Benjamin Auquite <halomastar@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-04-03 14:59:14 -07:00
|
|
|
import json
|
|
|
|
|
import sys
|
2023-07-23 14:24:22 -07:00
|
|
|
from pathlib import Path
|
Add scripts to auto update en.json, strings.json and services.yaml (#520)
* Add scripts to auto update strings.json and services.yaml
* Run services
* simplify
* Run strings
* rerun
* revert
* allow unicode
* Add CODEOWNERS
* Update CODEOWNERS
* set CONF_USE_DEFAULTS docs
* add field_name
* Auto run scripts
* Update desc
* Update README.md, strings.json, and services.yaml
* double quotes
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README.md, strings.json, and services.yaml
* Add newline
* sync changes between en.json and strings.json
* Update README.md, strings.json, and services.yaml
* double quotes
* fix
* Update README.md, strings.json, and services.yaml
* Add comments
* Remove comments
* shorter
* Update README.md, strings.json, and services.yaml
* Rephrase
* Update README.md, strings.json, and services.yaml
* remove key from desc
---------
Co-authored-by: Benjamin Auquite <halomastar@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-04-03 14:59:14 -07:00
|
|
|
|
2023-08-09 17:17:25 -07:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
2023-07-26 12:52:03 -07:00
|
|
|
import yaml
|
|
|
|
|
|
Add scripts to auto update en.json, strings.json and services.yaml (#520)
* Add scripts to auto update strings.json and services.yaml
* Run services
* simplify
* Run strings
* rerun
* revert
* allow unicode
* Add CODEOWNERS
* Update CODEOWNERS
* set CONF_USE_DEFAULTS docs
* add field_name
* Auto run scripts
* Update desc
* Update README.md, strings.json, and services.yaml
* double quotes
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README.md, strings.json, and services.yaml
* Add newline
* sync changes between en.json and strings.json
* Update README.md, strings.json, and services.yaml
* double quotes
* fix
* Update README.md, strings.json, and services.yaml
* Add comments
* Remove comments
* shorter
* Update README.md, strings.json, and services.yaml
* Rephrase
* Update README.md, strings.json, and services.yaml
* remove key from desc
---------
Co-authored-by: Benjamin Auquite <halomastar@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-04-03 14:59:14 -07:00
|
|
|
sys.path.append(str(Path(__file__).parent.parent))
|
|
|
|
|
|
2024-02-05 14:13:13 -08:00
|
|
|
from custom_components.adaptive_lighting import const
|
Add scripts to auto update en.json, strings.json and services.yaml (#520)
* Add scripts to auto update strings.json and services.yaml
* Run services
* simplify
* Run strings
* rerun
* revert
* allow unicode
* Add CODEOWNERS
* Update CODEOWNERS
* set CONF_USE_DEFAULTS docs
* add field_name
* Auto run scripts
* Update desc
* Update README.md, strings.json, and services.yaml
* double quotes
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README.md, strings.json, and services.yaml
* Add newline
* sync changes between en.json and strings.json
* Update README.md, strings.json, and services.yaml
* double quotes
* fix
* Update README.md, strings.json, and services.yaml
* Add comments
* Remove comments
* shorter
* Update README.md, strings.json, and services.yaml
* Rephrase
* Update README.md, strings.json, and services.yaml
* remove key from desc
---------
Co-authored-by: Benjamin Auquite <halomastar@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-04-03 14:59:14 -07:00
|
|
|
|
2023-07-23 14:24:22 -07:00
|
|
|
folder = Path("custom_components") / "adaptive_lighting"
|
|
|
|
|
strings_fname = folder / "strings.json"
|
|
|
|
|
en_fname = folder / "translations" / "en.json"
|
|
|
|
|
with strings_fname.open() as f:
|
Add scripts to auto update en.json, strings.json and services.yaml (#520)
* Add scripts to auto update strings.json and services.yaml
* Run services
* simplify
* Run strings
* rerun
* revert
* allow unicode
* Add CODEOWNERS
* Update CODEOWNERS
* set CONF_USE_DEFAULTS docs
* add field_name
* Auto run scripts
* Update desc
* Update README.md, strings.json, and services.yaml
* double quotes
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README.md, strings.json, and services.yaml
* Add newline
* sync changes between en.json and strings.json
* Update README.md, strings.json, and services.yaml
* double quotes
* fix
* Update README.md, strings.json, and services.yaml
* Add comments
* Remove comments
* shorter
* Update README.md, strings.json, and services.yaml
* Rephrase
* Update README.md, strings.json, and services.yaml
* remove key from desc
---------
Co-authored-by: Benjamin Auquite <halomastar@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-04-03 14:59:14 -07:00
|
|
|
strings = json.load(f)
|
|
|
|
|
|
2023-07-26 12:52:03 -07:00
|
|
|
# Set "options"
|
2023-08-09 17:17:25 -07:00
|
|
|
data = {}
|
|
|
|
|
data_description = {}
|
|
|
|
|
for k, _, typ in const.VALIDATION_TUPLES:
|
|
|
|
|
desc = const.DOCS[k]
|
2025-01-01 23:28:15 -08:00
|
|
|
if len(desc) > 40 and typ not in (bool, cv.entity_ids):
|
2023-08-09 17:17:25 -07:00
|
|
|
data[k] = k
|
|
|
|
|
data_description[k] = desc
|
|
|
|
|
else:
|
|
|
|
|
data[k] = f"{k}: {desc}"
|
Add scripts to auto update en.json, strings.json and services.yaml (#520)
* Add scripts to auto update strings.json and services.yaml
* Run services
* simplify
* Run strings
* rerun
* revert
* allow unicode
* Add CODEOWNERS
* Update CODEOWNERS
* set CONF_USE_DEFAULTS docs
* add field_name
* Auto run scripts
* Update desc
* Update README.md, strings.json, and services.yaml
* double quotes
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README.md, strings.json, and services.yaml
* Add newline
* sync changes between en.json and strings.json
* Update README.md, strings.json, and services.yaml
* double quotes
* fix
* Update README.md, strings.json, and services.yaml
* Add comments
* Remove comments
* shorter
* Update README.md, strings.json, and services.yaml
* Rephrase
* Update README.md, strings.json, and services.yaml
* remove key from desc
---------
Co-authored-by: Benjamin Auquite <halomastar@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-04-03 14:59:14 -07:00
|
|
|
strings["options"]["step"]["init"]["data"] = data
|
2023-08-09 17:17:25 -07:00
|
|
|
strings["options"]["step"]["init"]["data_description"] = data_description
|
Add scripts to auto update en.json, strings.json and services.yaml (#520)
* Add scripts to auto update strings.json and services.yaml
* Run services
* simplify
* Run strings
* rerun
* revert
* allow unicode
* Add CODEOWNERS
* Update CODEOWNERS
* set CONF_USE_DEFAULTS docs
* add field_name
* Auto run scripts
* Update desc
* Update README.md, strings.json, and services.yaml
* double quotes
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README.md, strings.json, and services.yaml
* Add newline
* sync changes between en.json and strings.json
* Update README.md, strings.json, and services.yaml
* double quotes
* fix
* Update README.md, strings.json, and services.yaml
* Add comments
* Remove comments
* shorter
* Update README.md, strings.json, and services.yaml
* Rephrase
* Update README.md, strings.json, and services.yaml
* remove key from desc
---------
Co-authored-by: Benjamin Auquite <halomastar@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-04-03 14:59:14 -07:00
|
|
|
|
2023-07-26 12:52:03 -07:00
|
|
|
# Set "services"
|
|
|
|
|
services_filename = Path("custom_components") / "adaptive_lighting" / "services.yaml"
|
|
|
|
|
with open(services_filename) as f: # noqa: PTH123
|
|
|
|
|
services = yaml.safe_load(f)
|
|
|
|
|
services_json = {}
|
|
|
|
|
for service_name, dct in services.items():
|
|
|
|
|
services_json[service_name] = {
|
|
|
|
|
"name": service_name,
|
|
|
|
|
"description": dct["description"],
|
|
|
|
|
"fields": {},
|
|
|
|
|
}
|
|
|
|
|
for field_name, field in dct["fields"].items():
|
|
|
|
|
services_json[service_name]["fields"][field_name] = {
|
|
|
|
|
"description": field["description"],
|
|
|
|
|
"name": field_name,
|
|
|
|
|
}
|
|
|
|
|
strings["services"] = services_json
|
|
|
|
|
|
|
|
|
|
# Write changes to strings.json
|
2023-07-23 14:24:22 -07:00
|
|
|
with strings_fname.open("w") as f:
|
Add scripts to auto update en.json, strings.json and services.yaml (#520)
* Add scripts to auto update strings.json and services.yaml
* Run services
* simplify
* Run strings
* rerun
* revert
* allow unicode
* Add CODEOWNERS
* Update CODEOWNERS
* set CONF_USE_DEFAULTS docs
* add field_name
* Auto run scripts
* Update desc
* Update README.md, strings.json, and services.yaml
* double quotes
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README.md, strings.json, and services.yaml
* Add newline
* sync changes between en.json and strings.json
* Update README.md, strings.json, and services.yaml
* double quotes
* fix
* Update README.md, strings.json, and services.yaml
* Add comments
* Remove comments
* shorter
* Update README.md, strings.json, and services.yaml
* Rephrase
* Update README.md, strings.json, and services.yaml
* remove key from desc
---------
Co-authored-by: Benjamin Auquite <halomastar@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-04-03 14:59:14 -07:00
|
|
|
json.dump(strings, f, indent=2, ensure_ascii=False)
|
|
|
|
|
f.write("\n")
|
|
|
|
|
|
|
|
|
|
# Sync changes from strings.json to en.json
|
2023-07-23 14:24:22 -07:00
|
|
|
with en_fname.open() as f:
|
Add scripts to auto update en.json, strings.json and services.yaml (#520)
* Add scripts to auto update strings.json and services.yaml
* Run services
* simplify
* Run strings
* rerun
* revert
* allow unicode
* Add CODEOWNERS
* Update CODEOWNERS
* set CONF_USE_DEFAULTS docs
* add field_name
* Auto run scripts
* Update desc
* Update README.md, strings.json, and services.yaml
* double quotes
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README.md, strings.json, and services.yaml
* Add newline
* sync changes between en.json and strings.json
* Update README.md, strings.json, and services.yaml
* double quotes
* fix
* Update README.md, strings.json, and services.yaml
* Add comments
* Remove comments
* shorter
* Update README.md, strings.json, and services.yaml
* Rephrase
* Update README.md, strings.json, and services.yaml
* remove key from desc
---------
Co-authored-by: Benjamin Auquite <halomastar@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-04-03 14:59:14 -07:00
|
|
|
en = json.load(f)
|
|
|
|
|
|
|
|
|
|
en["config"]["step"]["user"] = strings["config"]["step"]["user"]
|
|
|
|
|
en["options"]["step"]["init"]["data"] = data
|
2023-08-09 17:17:25 -07:00
|
|
|
en["options"]["step"]["init"]["data_description"] = data_description
|
2023-07-26 12:52:03 -07:00
|
|
|
en["services"] = services_json
|
Add scripts to auto update en.json, strings.json and services.yaml (#520)
* Add scripts to auto update strings.json and services.yaml
* Run services
* simplify
* Run strings
* rerun
* revert
* allow unicode
* Add CODEOWNERS
* Update CODEOWNERS
* set CONF_USE_DEFAULTS docs
* add field_name
* Auto run scripts
* Update desc
* Update README.md, strings.json, and services.yaml
* double quotes
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README.md, strings.json, and services.yaml
* Add newline
* sync changes between en.json and strings.json
* Update README.md, strings.json, and services.yaml
* double quotes
* fix
* Update README.md, strings.json, and services.yaml
* Add comments
* Remove comments
* shorter
* Update README.md, strings.json, and services.yaml
* Rephrase
* Update README.md, strings.json, and services.yaml
* remove key from desc
---------
Co-authored-by: Benjamin Auquite <halomastar@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-04-03 14:59:14 -07:00
|
|
|
|
2023-07-23 14:24:22 -07:00
|
|
|
with en_fname.open("w") as f:
|
Add scripts to auto update en.json, strings.json and services.yaml (#520)
* Add scripts to auto update strings.json and services.yaml
* Run services
* simplify
* Run strings
* rerun
* revert
* allow unicode
* Add CODEOWNERS
* Update CODEOWNERS
* set CONF_USE_DEFAULTS docs
* add field_name
* Auto run scripts
* Update desc
* Update README.md, strings.json, and services.yaml
* double quotes
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README.md, strings.json, and services.yaml
* Add newline
* sync changes between en.json and strings.json
* Update README.md, strings.json, and services.yaml
* double quotes
* fix
* Update README.md, strings.json, and services.yaml
* Add comments
* Remove comments
* shorter
* Update README.md, strings.json, and services.yaml
* Rephrase
* Update README.md, strings.json, and services.yaml
* remove key from desc
---------
Co-authored-by: Benjamin Auquite <halomastar@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-04-03 14:59:14 -07:00
|
|
|
json.dump(en, f, indent=2, ensure_ascii=False)
|
|
|
|
|
f.write("\n")
|