diff --git a/api/src/bin/convert_autos_from_index.py b/api/src/bin/convert_autos_from_index.py new file mode 100644 index 0000000..dcd6afb --- /dev/null +++ b/api/src/bin/convert_autos_from_index.py @@ -0,0 +1,28 @@ +import argparse +from pathlib import Path +from typing import Dict, List + +import yaml + + +def convert_tags(automations: List[dict], tags: Dict[int, dict]) -> Dict[str, dict]: + converted = {} + for tagsIdx, tagValues in tags.items(): + if tagsIdx < len(automations): + auto = automations[tagsIdx] + converted[auto["id"]] = tagValues + else: + print(f"WARN: tags index = {tagsIdx} is out of bounds") + return converted + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("-i", dest="input", required=True, type=Path) + args = parser.parse_args() + auto_path: Path = args.input / "automations.yaml" + tags_path: Path = args.input / ".shortumations" / "tags.yaml" + automations = yaml.safe_load(auto_path.read_text()) + tags = yaml.safe_load(tags_path.read_text()) + converted = convert_tags(automations, tags) + tags_path.write_text(yaml.dump(converted)) diff --git a/api/tests/samples/config/.shortumations/tags.yaml b/api/tests/samples/config/.shortumations/tags.yaml index e3b090c..ef2075c 100644 --- a/api/tests/samples/config/.shortumations/tags.yaml +++ b/api/tests/samples/config/.shortumations/tags.yaml @@ -1,77 +1,77 @@ -0: +'1616887975473': Type: HA -1: +'1616888026264': Type: HA -2: - Type: Button +'1619371298367': Room: Living -3: Type: Button +'1620239986670': Room: Kitchen -4: Type: Button +'1620324780561': Room: Kitchen -5: Type: Button +'1621352850204': Room: Kitchen -6: Type: Button +'1622210698281': Room: Kitchen -7: Type: Button +'1622769811245': Room: Living -8: Type: Button +'1623430479201': Room: Baby -9: Type: Button +'1623642118976': Room: Baby -10: Type: Button +'1624640900951': + Room: Baby + Type: Button +'1628024070687': Room: Baby -11: Type: Routine +'1628024123214': Room: Baby -12: Type: Routine - Room: Baby -13: +'1628444671951': + Room: Office Type: Window - Room: Office -14: - Type: Door +'1629309267204': Room: Balcony -15: - Type: Routine -16: - Type: Button - Room: Baby -17: - Type: Routine -18: - Type: Routine -19: Type: Door - Room: Bedroom -20: - Type: Ensure Power -21: - Type: Ensure Power -22: - Type: Motion - Room: Office -23: +'1629422438707': Type: Routine +'1634497376234': Room: Baby -24: - Type: Climate - Climate: Heat -25: - Type: Climate - Climate: Time -26: - Type: Routine -27: Type: Button +'1635539262562': + Type: Routine +'1636428429596': + Type: Routine +'1639500650865': Room: Bedroom - BadOne: yes + Type: Door +'1641617168123': + Type: Ensure Power +'1648071019802': + Type: Ensure Power +'1649426399020': + Room: Office + Type: Motion +'1649432254675': + Room: Baby + Type: Routine +'1649726828269': + Climate: Heat + Type: Climate +'1649727810678': + Climate: Time + Type: Climate +'1649820885714': + Type: Routine +'1649947692702': + BadOne: true + Room: Bedroom + Type: Button