From 33498848bf80484a6f7f52d3a38cba766c2c2f01 Mon Sep 17 00:00:00 2001 From: Wil T Date: Thu, 14 Dec 2023 22:21:04 -0500 Subject: [PATCH 01/38] Create new-device.yml initial work to automatically create pull requests for device definitions based on user-submitted issues --- .github/workflows/new-device.yml | 138 +++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 .github/workflows/new-device.yml diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml new file mode 100644 index 000000000..08325ce57 --- /dev/null +++ b/.github/workflows/new-device.yml @@ -0,0 +1,138 @@ +name: New Device + +on: + issues: + types: [opened, edited] + +jobs: + collect-info: + runs-on: ubuntu-latest + if: ${{ contains(github.event.issue.title , '[Device]')}} + outputs: + manufacturer: ${{ steps.inputs.outputs.device_manufacturer }} + model: ${{ steps.inputs.outputs.device_model }} + battery_type: ${{ steps.inputs.outputs.device_battery_type }} + battery_quantity: ${{ steps.inputs.outputs.device_battery_quantity }} + steps: + - name: Get inputs + id: inputs + shell: bash + run: | + add_output(){ + local k=$1 + local v=$2 + echo "$k=$v" >> $GITHUB_OUTPUT + } + process_key(){ + local process_key=$1 + # Trim leading and trailing whitespace + process_key="$(echo -e "${process_key}" | sed -e "s/^[[:space:]]*//" -e s/[[:space:]]*$//)" + + # Substitute spaces with underscores + process_key="${process_key// /_}" + + # Convert to lowercase + process_key="${process_key,,}" + } + process_checkbox_line(){ + local checkbox_line=$1 + option="$(echo "$checkbox_line" | sed "s/- \[[^]]*\] //")" + + key="$(process_key "$option")" + value="$(echo "$checkbox_line" | grep -qE -- "- \[X\] && echo 'true' || echo 'false'")" + + add_output "$key" "$value" + + escaped_lookfor="$(echo "$checkbox_line" | sed "s/[][()\.^$?*+{}|]/\\&/g")" + nextcheckbox="$(echo "{{ github.event.issue.body }}" | awk "/$escaped_lookfor$/{getline; print}")" + + if [[ "$nextcheckbox" == "- ["* && -n "$nextcheckbox" && "$nextcheckbox" != "$checkbox_line" ]]; then + process_checkbox_line "$nextcheckbox" + fi + } + echo "${{ github.event.issue.body }}" | awk "/^###/ {print}" | while read line; do + echo "🔍 Processing line: $line" + value=$(echo "${{ github.event.issue.body }}" | awk "/^$line$/{getline; getline; print}") + + if [[ "$value" == "- ["* ]]; then + # Processing a checkbox + echo "☑️ Detected a checkbox!" + process_checkbox_line "$value" + else + # Remove "###" from the beginning of the string + key=${line##"###"} + + key="$(process_key "$key")" + add_output "$key" "$value" + fi + done + + update-json: + needs: collect-info + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install jq + run: sudo apt-get install jq + + - name: Update JSON file + env: + MANUFACTURER: ${{needs.collect-info.outputs.manufacturer}} + MODEL: ${{needs.collect-info.outputs.model}} + BATTERY_TYPE: ${{needs.collect-info.outputs.battery_type}} + BATTERY_QUANTITY: ${{needs.collect-info.outputs.battery_quantity}} + run: | + JSON_FILE="custom_components/battery_notes/data/library.json" + SCHEMA_URL="../../../schema.json" + VERSION=1 + + # Read current JSON content into a variable + JSON_CONTENT=$(jq '.' "$JSON_FILE") + + # Create a JSON object with collected information + NEW_ENTRY=$(jq -n \ + --arg manufacturer "$MANUFACTURER" \ + --arg model "$MODEL" \ + --arg battery_type "$BATTERY_TYPE" \ + --arg battery_quantity "$BATTERY_QUANTITY" \ + '{ + manufacturer: $manufacturer, + model: $model, + battery_type: $battery_type, + battery_quantity: $battery_quantity + }') + + # Remove null fields (e.g., if battery_quantity is not provided, it should not be in the new entry) + NEW_ENTRY_CLEAN=$(echo "$NEW_ENTRY" | jq 'del(.battery_quantity | select(. == 1))') + + # Add the new entry to the devices array in the JSON content + UPDATED_DEVICES=$(echo "$JSON_CONTENT" | jq --argjson newEntry "$NEW_ENTRY_CLEAN" '.devices += [$newEntry]') + + # Create updated JSON content with $schema and version + UPDATED_CONTENT=$(jq -n \ + --arg schema "$SCHEMA_URL" \ + --argjson version "$VERSION" \ + --argjson updatedDevices "$UPDATED_DEVICES" \ + '{ + "$schema": $schema, + "version": $version, + "devices": $updatedDevices.devices + }') + echo "$UPDATED_CONTENT" > "$JSON_FILE" + - name: Pick random branch name + uses: boonya/gh-action-name-generator@v1 + id: random-name-generator + with: + separator: '-' + length: '3' + style: lowerCase + - name: Create pull request + uses: peter-evans/create-pull-request@v5 + with: + title: "Add ${{ needs.collect-info.outputs.manufacturer }} ${{ needs.collect-info.outputs.model }}" + commit-message: "Automatically-generated from user-submitted device request" + branch: ${{ steps.random-name-generator.outputs.name }}" + delete-branch: true + From a360432e83cfb1d6aaf3176c9d805950d1ab1232 Mon Sep 17 00:00:00 2001 From: Wil T Date: Thu, 14 Dec 2023 22:35:17 -0500 Subject: [PATCH 02/38] Create new-device.yml --- .github/ISSUE_TEMPLATE/new-device.yml | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/new-device.yml diff --git a/.github/ISSUE_TEMPLATE/new-device.yml b/.github/ISSUE_TEMPLATE/new-device.yml new file mode 100644 index 000000000..1829ee473 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/new-device.yml @@ -0,0 +1,50 @@ +name: New Device +description: Submit a new device to the library so that others don't have to configure it themselves. +title: "[Device]: " +labels: ["new-device"] +body: + - type: markdown + attributes: + value: | + The battery library is a JSON document at [custom_components/battery_notes/data/library.json](custom_components/battery_notes/data/library.json) + To contribute, submit your device details via this form and the relevant code changes will be proposed on your behalf. + Note: The manufacturer and model should be exactly what is displayed on the Device screen within Home Assistant. + To see your devices, click here: + + [![Open your Home Assistant instance and show your devices.](https://my.home-assistant.io/badges/devices.svg)](https://my.home-assistant.io/redirect/devices/) + + - type: input + id: manufacturer + attributes: + label: Device Manufacturer + description: The manufacturer should be exactly what is displayed on the Devices screen within Home Assistant. + placeholder: ex. eWeLink + validations: + required: true + + - type: input + id: model + attributes: + label: Device Model + description: The model should be exactly what is displayed on the Devices screen within Home Assistant. + placeholder: ex. DS01 + validations: + required: true + + - type: input + id: battery-type + attributes: + label: Device Battery Type + description: When specifying battery types please use the Most Common naming for general batteries and the IEC naming for battery cells according to [Wikipedia](https://en.wikipedia.org/wiki/List_of_battery_sizes). + placeholder: ex. CR2032 + validations: + required: true + + - type: input + id: battery-quantity + attributes: + label: Device Battery Type + description: The battery_quantity attribute is numeric (no letters or special characters). + placeholder: ex. 1 + validations: + required: true From d54ddc761cbfb16dfa391a42380a4d479d8bedd3 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 10:43:56 -0500 Subject: [PATCH 03/38] update json_validate actions --- .github/workflows/json_validate.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/json_validate.yml b/.github/workflows/json_validate.yml index ee4ab17f9..58adfa13a 100644 --- a/.github/workflows/json_validate.yml +++ b/.github/workflows/json_validate.yml @@ -15,9 +15,9 @@ jobs: verify-json-validation: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Validate JSON - uses: docker://orrosenblatt/validate-json-action:latest + uses: ScratchAddons/validate-json-action@master env: INPUT_SCHEMA: ./schema.json INPUT_JSONS: custom_components/battery_notes/data/library.json From 9ae15310caecb4cbf1cf97b3988c880a076d3e95 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 10:45:35 -0500 Subject: [PATCH 04/38] update ruff and validate against 3.11 and 3.12 --- .github/workflows/lint.yml | 44 ++++++++++++++++++++++---------------- requirements.txt | 2 +- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f82d5d675..ba3acd2be 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,33 +1,41 @@ -name: "Lint" +name: Lint on: push: branches: - "main" - paths-ignore: - - 'custom_components/battery_notes/data/**' + paths: + - '**.py' # Run if pushed commits include a change to a Python (.py) file. + - '.github/workflows/*.yml' # Run if pushed commits include a change to a github actions workflow file. + - 'requirements.txt' # Run if pushed commits include a change to the Python requirements.txt file. pull_request: branches: - "main" - paths-ignore: - - 'custom_components/battery_notes/data/**' + paths: + - '**.py' # Run if pushed commits include a change to a Python (.py) file. + - '.github/workflows/*.yml' # Run if pushed commits include a change to a github actions workflow file. + - 'requirements.txt' # Run if pushed commits include a change to the Python requirements.txt file. + workflow_dispatch: jobs: - ruff: - name: "Ruff" + build: runs-on: "ubuntu-latest" + strategy: + matrix: + python-version: ["3.12", "3.11"] steps: - - name: "Checkout the repository" - uses: "actions/checkout@v4" + - name: Checkout repo + uses: actions/checkout@v4 - - name: "Set up Python" - uses: actions/setup-python@v5.0.0 - with: - python-version: "3.11" - cache: "pip" + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} - - name: "Install requirements" - run: python3 -m pip install -r requirements.txt + - name: Install dependencies from requirements.txt + run: | + if [ -f requirements.txt ]; then pip3 install -r requirements.txt; fi - - name: "Run" - run: python3 -m ruff check . + - name: Analyse the code with ruff + run: | + python3 -m ruff check . diff --git a/requirements.txt b/requirements.txt index f52ed9d17..9932f8875 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ colorlog==6.8.0 homeassistant==2023.7.0 pip>=21.0,<23.4 -ruff==0.1.7 +ruff==0.1.8 From 4d6e46f2da1074429f9c722eea988e2a6919ef77 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 14:01:50 -0500 Subject: [PATCH 05/38] convert update-json to use python --- .github/workflows/new-device.yml | 90 ++++++++++++++++---------------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 08325ce57..a24f6f0aa 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -77,50 +77,52 @@ jobs: - name: Install jq run: sudo apt-get install jq + - name: Set up python 3.12 + uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: Update JSON file - env: - MANUFACTURER: ${{needs.collect-info.outputs.manufacturer}} - MODEL: ${{needs.collect-info.outputs.model}} - BATTERY_TYPE: ${{needs.collect-info.outputs.battery_type}} - BATTERY_QUANTITY: ${{needs.collect-info.outputs.battery_quantity}} - run: | - JSON_FILE="custom_components/battery_notes/data/library.json" - SCHEMA_URL="../../../schema.json" - VERSION=1 - - # Read current JSON content into a variable - JSON_CONTENT=$(jq '.' "$JSON_FILE") - - # Create a JSON object with collected information - NEW_ENTRY=$(jq -n \ - --arg manufacturer "$MANUFACTURER" \ - --arg model "$MODEL" \ - --arg battery_type "$BATTERY_TYPE" \ - --arg battery_quantity "$BATTERY_QUANTITY" \ - '{ - manufacturer: $manufacturer, - model: $model, - battery_type: $battery_type, - battery_quantity: $battery_quantity - }') - - # Remove null fields (e.g., if battery_quantity is not provided, it should not be in the new entry) - NEW_ENTRY_CLEAN=$(echo "$NEW_ENTRY" | jq 'del(.battery_quantity | select(. == 1))') - - # Add the new entry to the devices array in the JSON content - UPDATED_DEVICES=$(echo "$JSON_CONTENT" | jq --argjson newEntry "$NEW_ENTRY_CLEAN" '.devices += [$newEntry]') - - # Create updated JSON content with $schema and version - UPDATED_CONTENT=$(jq -n \ - --arg schema "$SCHEMA_URL" \ - --argjson version "$VERSION" \ - --argjson updatedDevices "$UPDATED_DEVICES" \ - '{ - "$schema": $schema, - "version": $version, - "devices": $updatedDevices.devices - }') - echo "$UPDATED_CONTENT" > "$JSON_FILE" + uses: jannekem/run-python-script-action@v1 + with: + script: | + import json + + # Set the file paths and version + JSON_FILE = "custom_components/battery_notes/data/library.json" + SCHEMA_URL = "../../../schema.json" + VERSION = 1 + + # Read the current JSON content + with open(JSON_FILE) as file: + json_content = json.load(file) + + print(${{needs.collect-info.outputs.manufacturer}}) + # Create a dictionary with collected information + new_entry = { + "manufacturer": ${{needs.collect-info.outputs.manufacturer}}, + "model": ${{needs.collect-info.outputs.model}}, + "battery_type": ${{needs.collect-info.outputs.battery_type}}, + "battery_quantity": ${{needs.collect-info.outputs.battery_quantity}} + } + + # Remove null fields + new_entry_clean = {k: v for k, v in new_entry.items() if v is not None} + + # Add the new entry to the devices array + json_content["devices"].append(new_entry_clean) + + # Create updated JSON content with $schema and version + updated_content = { + "$schema": SCHEMA_URL, + "version": VERSION, + "devices": json_content["devices"] + } + + # Write the updated content back to the JSON file + with open(JSON_FILE, "w") as file: + json.dump(updated_content, file) + - name: Pick random branch name uses: boonya/gh-action-name-generator@v1 id: random-name-generator @@ -128,6 +130,7 @@ jobs: separator: '-' length: '3' style: lowerCase + - name: Create pull request uses: peter-evans/create-pull-request@v5 with: @@ -135,4 +138,3 @@ jobs: commit-message: "Automatically-generated from user-submitted device request" branch: ${{ steps.random-name-generator.outputs.name }}" delete-branch: true - From 05b142c1e3d06e48934be4bc977c844965434381 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 14:18:05 -0500 Subject: [PATCH 06/38] update new-device.yml --- .github/workflows/new-device.yml | 134 +++++-------------------------- 1 file changed, 18 insertions(+), 116 deletions(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index a24f6f0aa..954eb0cd4 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -5,77 +5,21 @@ on: types: [opened, edited] jobs: - collect-info: - runs-on: ubuntu-latest + create-device-pull-request: if: ${{ contains(github.event.issue.title , '[Device]')}} - outputs: - manufacturer: ${{ steps.inputs.outputs.device_manufacturer }} - model: ${{ steps.inputs.outputs.device_model }} - battery_type: ${{ steps.inputs.outputs.device_battery_type }} - battery_quantity: ${{ steps.inputs.outputs.device_battery_quantity }} - steps: - - name: Get inputs - id: inputs - shell: bash - run: | - add_output(){ - local k=$1 - local v=$2 - echo "$k=$v" >> $GITHUB_OUTPUT - } - process_key(){ - local process_key=$1 - # Trim leading and trailing whitespace - process_key="$(echo -e "${process_key}" | sed -e "s/^[[:space:]]*//" -e s/[[:space:]]*$//)" - - # Substitute spaces with underscores - process_key="${process_key// /_}" - - # Convert to lowercase - process_key="${process_key,,}" - } - process_checkbox_line(){ - local checkbox_line=$1 - option="$(echo "$checkbox_line" | sed "s/- \[[^]]*\] //")" - - key="$(process_key "$option")" - value="$(echo "$checkbox_line" | grep -qE -- "- \[X\] && echo 'true' || echo 'false'")" - - add_output "$key" "$value" - - escaped_lookfor="$(echo "$checkbox_line" | sed "s/[][()\.^$?*+{}|]/\\&/g")" - nextcheckbox="$(echo "{{ github.event.issue.body }}" | awk "/$escaped_lookfor$/{getline; print}")" - - if [[ "$nextcheckbox" == "- ["* && -n "$nextcheckbox" && "$nextcheckbox" != "$checkbox_line" ]]; then - process_checkbox_line "$nextcheckbox" - fi - } - echo "${{ github.event.issue.body }}" | awk "/^###/ {print}" | while read line; do - echo "🔍 Processing line: $line" - value=$(echo "${{ github.event.issue.body }}" | awk "/^$line$/{getline; getline; print}") - - if [[ "$value" == "- ["* ]]; then - # Processing a checkbox - echo "☑️ Detected a checkbox!" - process_checkbox_line "$value" - else - # Remove "###" from the beginning of the string - key=${line##"###"} - - key="$(process_key "$key")" - add_output "$key" "$value" - fi - done - - update-json: - needs: collect-info runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 + - name: Parse device info from issue body + id: device-info + uses: onmax/issue-form-parser@v1.4 + with: + issue_number: ${{ github.event.issue.number }} + - name: Install jq - run: sudo apt-get install jq + run: sudo apt install jq - name: Set up python 3.12 uses: actions/setup-python@v5 @@ -83,58 +27,16 @@ jobs: python-version: '3.12' - name: Update JSON file + id: update-json uses: jannekem/run-python-script-action@v1 with: script: | - import json - - # Set the file paths and version - JSON_FILE = "custom_components/battery_notes/data/library.json" - SCHEMA_URL = "../../../schema.json" - VERSION = 1 - - # Read the current JSON content - with open(JSON_FILE) as file: - json_content = json.load(file) - - print(${{needs.collect-info.outputs.manufacturer}}) - # Create a dictionary with collected information - new_entry = { - "manufacturer": ${{needs.collect-info.outputs.manufacturer}}, - "model": ${{needs.collect-info.outputs.model}}, - "battery_type": ${{needs.collect-info.outputs.battery_type}}, - "battery_quantity": ${{needs.collect-info.outputs.battery_quantity}} - } - - # Remove null fields - new_entry_clean = {k: v for k, v in new_entry.items() if v is not None} - - # Add the new entry to the devices array - json_content["devices"].append(new_entry_clean) - - # Create updated JSON content with $schema and version - updated_content = { - "$schema": SCHEMA_URL, - "version": VERSION, - "devices": json_content["devices"] - } - - # Write the updated content back to the JSON file - with open(JSON_FILE, "w") as file: - json.dump(updated_content, file) - - - name: Pick random branch name - uses: boonya/gh-action-name-generator@v1 - id: random-name-generator - with: - separator: '-' - length: '3' - style: lowerCase - - - name: Create pull request - uses: peter-evans/create-pull-request@v5 - with: - title: "Add ${{ needs.collect-info.outputs.manufacturer }} ${{ needs.collect-info.outputs.model }}" - commit-message: "Automatically-generated from user-submitted device request" - branch: ${{ steps.random-name-generator.outputs.name }}" - delete-branch: true + print(${{ steps.parse.outputs.payload }}) +# +# - name: Create pull request +# uses: peter-evans/create-pull-request@v5 +# with: +# title: "Add ${{ needs.collect-info.outputs.manufacturer }} ${{ needs.collect-info.outputs.model }}" +# commit-message: "Automatically-generated from user-submitted device request" +# branch: ${{ steps.random-name-generator.outputs.name }}" +# delete-branch: true From 6e7a4f31667d40a5cefb19b60a04dc6b0b472cea Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 14:28:23 -0500 Subject: [PATCH 07/38] update new-device --- .github/ISSUE_TEMPLATE/new-device.yml | 8 ++++---- .github/workflows/new-device.yml | 11 +++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/new-device.yml b/.github/ISSUE_TEMPLATE/new-device.yml index 1829ee473..821234c22 100644 --- a/.github/ISSUE_TEMPLATE/new-device.yml +++ b/.github/ISSUE_TEMPLATE/new-device.yml @@ -16,7 +16,7 @@ body: - type: input id: manufacturer attributes: - label: Device Manufacturer + label: ">>Device Manufacturer<<" description: The manufacturer should be exactly what is displayed on the Devices screen within Home Assistant. placeholder: ex. eWeLink validations: @@ -25,7 +25,7 @@ body: - type: input id: model attributes: - label: Device Model + label: ">>Device Model<<" description: The model should be exactly what is displayed on the Devices screen within Home Assistant. placeholder: ex. DS01 validations: @@ -34,7 +34,7 @@ body: - type: input id: battery-type attributes: - label: Device Battery Type + label: ">>Device Battery Type<<" description: When specifying battery types please use the Most Common naming for general batteries and the IEC naming for battery cells according to [Wikipedia](https://en.wikipedia.org/wiki/List_of_battery_sizes). placeholder: ex. CR2032 validations: @@ -43,7 +43,7 @@ body: - type: input id: battery-quantity attributes: - label: Device Battery Type + label: ">>Device Battery Quantity<<" description: The battery_quantity attribute is numeric (no letters or special characters). placeholder: ex. 1 validations: diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 954eb0cd4..1bc054aa0 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -14,10 +14,13 @@ jobs: - name: Parse device info from issue body id: device-info - uses: onmax/issue-form-parser@v1.4 + uses: peter-murray/issue-forms-body-parser@v4 with: - issue_number: ${{ github.event.issue.number }} - + issue_id: ${{ github.event.issue.number }} + separator: '###' + label_marker_start: '>>' + label_marker_end: '<<' + - name: Install jq run: sudo apt install jq @@ -31,7 +34,7 @@ jobs: uses: jannekem/run-python-script-action@v1 with: script: | - print(${{ steps.parse.outputs.payload }}) + print(${{ steps.device-data.outputs.payload }}) # # - name: Create pull request # uses: peter-evans/create-pull-request@v5 From a0b875c9436acde1cb0c2f36a33f0b75b9b9cc4a Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 14:35:42 -0500 Subject: [PATCH 08/38] new device updates --- .github/workflows/new-device.yml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 1bc054aa0..4fe75aab9 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -12,14 +12,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Parse device info from issue body - id: device-info - uses: peter-murray/issue-forms-body-parser@v4 + - name: Parse device data + id: device-data + uses: issue-ops/parser@v0 with: - issue_id: ${{ github.event.issue.number }} - separator: '###' - label_marker_start: '>>' - label_marker_end: '<<' + body: ${{ github.event.issue.body }} - name: Install jq run: sudo apt install jq @@ -34,7 +31,7 @@ jobs: uses: jannekem/run-python-script-action@v1 with: script: | - print(${{ steps.device-data.outputs.payload }}) + print(${{ steps.device-data.outputs.json }}) # # - name: Create pull request # uses: peter-evans/create-pull-request@v5 From 54d8b7b8b502db8d7e2fc751e0fab9d73a57b60e Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 14:38:13 -0500 Subject: [PATCH 09/38] update new-device.yml --- .github/workflows/new-device.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 4fe75aab9..8ccf93cf7 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -17,6 +17,7 @@ jobs: uses: issue-ops/parser@v0 with: body: ${{ github.event.issue.body }} + issue-form-template: new-device.yml - name: Install jq run: sudo apt install jq @@ -27,12 +28,11 @@ jobs: python-version: '3.12' - name: Update JSON file - id: update-json uses: jannekem/run-python-script-action@v1 with: script: | print(${{ steps.device-data.outputs.json }}) -# + # - name: Create pull request # uses: peter-evans/create-pull-request@v5 # with: From 1988174815c762dd4a8ce10a17194752629d2121 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 14:43:07 -0500 Subject: [PATCH 10/38] new-device.yml --- .github/workflows/new-device.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 8ccf93cf7..203c6fc22 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -31,7 +31,12 @@ jobs: uses: jannekem/run-python-script-action@v1 with: script: | - print(${{ steps.device-data.outputs.json }}) + import json + new_device = ${{ steps.device-data.outputs.json }} + print(new_device["battery_quantity"]) + if int(new_device["battery_quantity"]) == 1: + del new_device["battery_quantity"] + print(new_device) # - name: Create pull request # uses: peter-evans/create-pull-request@v5 From d8f261a99aa6ad40210e940f0d1f59ee47af2178 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 14:44:58 -0500 Subject: [PATCH 11/38] update new-device.yml --- .github/ISSUE_TEMPLATE/new-device.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/new-device.yml b/.github/ISSUE_TEMPLATE/new-device.yml index 821234c22..921b3a196 100644 --- a/.github/ISSUE_TEMPLATE/new-device.yml +++ b/.github/ISSUE_TEMPLATE/new-device.yml @@ -16,7 +16,7 @@ body: - type: input id: manufacturer attributes: - label: ">>Device Manufacturer<<" + label: Manufacturer description: The manufacturer should be exactly what is displayed on the Devices screen within Home Assistant. placeholder: ex. eWeLink validations: @@ -25,7 +25,7 @@ body: - type: input id: model attributes: - label: ">>Device Model<<" + label: Model description: The model should be exactly what is displayed on the Devices screen within Home Assistant. placeholder: ex. DS01 validations: @@ -34,7 +34,7 @@ body: - type: input id: battery-type attributes: - label: ">>Device Battery Type<<" + label: Battery Type description: When specifying battery types please use the Most Common naming for general batteries and the IEC naming for battery cells according to [Wikipedia](https://en.wikipedia.org/wiki/List_of_battery_sizes). placeholder: ex. CR2032 validations: @@ -43,7 +43,7 @@ body: - type: input id: battery-quantity attributes: - label: ">>Device Battery Quantity<<" + label: Battery Quantity description: The battery_quantity attribute is numeric (no letters or special characters). placeholder: ex. 1 validations: From 6ea87bdc32110b36a6dd52efc37d0acec6a198b4 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 14:57:05 -0500 Subject: [PATCH 12/38] update new-device.yml --- .github/workflows/new-device.yml | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 203c6fc22..56a589e7f 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -32,16 +32,28 @@ jobs: with: script: | import json + + # Load the existing JSON library file + with open("custom_components/battery_notes/data/library.json",'r') as f: + devices_json = json.loads(f.read()) + devices = devices_json.get('devices') + + # Remove the "battery_quantity" key from the device dictionary if it's 1 new_device = ${{ steps.device-data.outputs.json }} - print(new_device["battery_quantity"]) if int(new_device["battery_quantity"]) == 1: del new_device["battery_quantity"] - print(new_device) - -# - name: Create pull request -# uses: peter-evans/create-pull-request@v5 -# with: -# title: "Add ${{ needs.collect-info.outputs.manufacturer }} ${{ needs.collect-info.outputs.model }}" -# commit-message: "Automatically-generated from user-submitted device request" -# branch: ${{ steps.random-name-generator.outputs.name }}" -# delete-branch: true + + # Check for duplicates and replace old entry with new one + duplicate_found = False + for i, device in enumerate(devices): + if device["manufacturer"] == new_device["manufacturer"] and device["model"] == new_device["model"]: + devices[i] = new_device + duplicate_found = True + break + + # If no duplicate found, add the new device to the JSON library file + if not duplicate_found: + devices.append(new_device) + + with open("custom_components/battery_notes/data/library.json", "w") as f: + f.write(json.dumps(devices_json, indent=2)) From bca248d7b68997ca192a2f1e63ef0ec706d41489 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 15:00:18 -0500 Subject: [PATCH 13/38] update new-device --- .github/workflows/new-device.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 56a589e7f..8af920208 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -57,3 +57,10 @@ jobs: with open("custom_components/battery_notes/data/library.json", "w") as f: f.write(json.dumps(devices_json, indent=2)) + - name: Create pull request + uses: peter-evans/create-pull-request@v5 + with: + commit-message: "Update device: ${{ steps.device-data.outputs.json.manufacturer }} - ${{ steps.device-data.outputs.json.model }}" + title: "DEVICE: ${{ steps.device-data.outputs.json.manufacturer }} - ${{ steps.device-data.outputs.json.model }}" + body: "This pull request adds or updates the device information for ${{ steps.device-data.outputs.json.manufacturer }} - ${{ steps.device-data.outputs.json.model }}" + branch: update-device-${{ steps.device-data.outputs.json.manufacturer }}-${{ steps.device-data.outputs.json.model }}" From 82d8fdab397a6b1b2c84d1efb943deca46185f65 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 15:15:33 -0500 Subject: [PATCH 14/38] update new-device.yml --- .github/workflows/new-device.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 8af920208..696b9fbef 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -28,6 +28,7 @@ jobs: python-version: '3.12' - name: Update JSON file + id: update-json uses: jannekem/run-python-script-action@v1 with: script: | @@ -54,13 +55,17 @@ jobs: # If no duplicate found, add the new device to the JSON library file if not duplicate_found: devices.append(new_device) + + print(f"manufacturer={device["manufacturer"]}" >> $GITHUB_OUTPUT) + print(f"model={device["model"]}" >> $GITHUB_OUTPUT) with open("custom_components/battery_notes/data/library.json", "w") as f: f.write(json.dumps(devices_json, indent=2)) + - name: Create pull request uses: peter-evans/create-pull-request@v5 with: - commit-message: "Update device: ${{ steps.device-data.outputs.json.manufacturer }} - ${{ steps.device-data.outputs.json.model }}" - title: "DEVICE: ${{ steps.device-data.outputs.json.manufacturer }} - ${{ steps.device-data.outputs.json.model }}" - body: "This pull request adds or updates the device information for ${{ steps.device-data.outputs.json.manufacturer }} - ${{ steps.device-data.outputs.json.model }}" - branch: update-device-${{ steps.device-data.outputs.json.manufacturer }}-${{ steps.device-data.outputs.json.model }}" + commit-message: "Update device: ${{ steps.update-json.outputs.manufacturer }} - ${{ steps.update-json.outputs.json.model }}" + title: "DEVICE: ${{ steps.update-json.outputs.json.manufacturer }} - ${{ steps.update-json.outputs.json.model }}" + body: "This pull request adds or updates the device information for ${{ steps.update-json.outputs.json.manufacturer }} - ${{ steps.update-json.outputs.json.model }}" + branch: update-device-${{ steps.update-json.outputs.json.manufacturer }}-${{ steps.update-json.outputs.json.model }}" From 96a1d823a05c6fb0caa8a7f84712ec8a8fc66dc5 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 15:17:08 -0500 Subject: [PATCH 15/38] update new-device.yml --- .github/workflows/new-device.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 696b9fbef..d18b4d307 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -56,8 +56,8 @@ jobs: if not duplicate_found: devices.append(new_device) - print(f"manufacturer={device["manufacturer"]}" >> $GITHUB_OUTPUT) - print(f"model={device["model"]}" >> $GITHUB_OUTPUT) + print(f"manufacturer={device["manufacturer"]}" >> $GITHUB_OUTPUT") + print(f"model={device["model"]}" >> $GITHUB_OUTPUT") with open("custom_components/battery_notes/data/library.json", "w") as f: f.write(json.dumps(devices_json, indent=2)) @@ -67,5 +67,5 @@ jobs: with: commit-message: "Update device: ${{ steps.update-json.outputs.manufacturer }} - ${{ steps.update-json.outputs.json.model }}" title: "DEVICE: ${{ steps.update-json.outputs.json.manufacturer }} - ${{ steps.update-json.outputs.json.model }}" - body: "This pull request adds or updates the device information for ${{ steps.update-json.outputs.json.manufacturer }} - ${{ steps.update-json.outputs.json.model }}" + body: "This pull request adds or updates the device information for ${{ steps.update-json.outputs.json.manufacturer }} - ${{ steps.update-json.outputs.json.model }}\nIt closes issue #${{ github.event.issue.number }}" branch: update-device-${{ steps.update-json.outputs.json.manufacturer }}-${{ steps.update-json.outputs.json.model }}" From d451e5f37ca438aea2f3d29e852f3b750309cfcc Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 15:18:50 -0500 Subject: [PATCH 16/38] update new-device.yml --- .github/workflows/new-device.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index d18b4d307..81ee1f1c0 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -56,8 +56,8 @@ jobs: if not duplicate_found: devices.append(new_device) - print(f"manufacturer={device["manufacturer"]}" >> $GITHUB_OUTPUT") - print(f"model={device["model"]}" >> $GITHUB_OUTPUT") + print(f"manufacturer={device["manufacturer"]} >> $GITHUB_OUTPUT") + print(f"model={device["model"]} >> $GITHUB_OUTPUT") with open("custom_components/battery_notes/data/library.json", "w") as f: f.write(json.dumps(devices_json, indent=2)) From 81cc448b0d4dbd566ffd2a5942a2b24f8b42919e Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 15:22:10 -0500 Subject: [PATCH 17/38] update new-device.yml --- .github/workflows/new-device.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 81ee1f1c0..9f766e39d 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -56,8 +56,9 @@ jobs: if not duplicate_found: devices.append(new_device) - print(f"manufacturer={device["manufacturer"]} >> $GITHUB_OUTPUT") - print(f"model={device["model"]} >> $GITHUB_OUTPUT") + # Save manufacturer and model info as outputs + print(f"::set-output name=manufacturer::{new_device['manufacturer']}") + print(f"::set-output name=model::{new_device['model']}") with open("custom_components/battery_notes/data/library.json", "w") as f: f.write(json.dumps(devices_json, indent=2)) From 14be1504f2278f716e5c03bbc2d43ce64e3de0ef Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 15:24:10 -0500 Subject: [PATCH 18/38] update new-device.yml --- .github/workflows/new-device.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 9f766e39d..798075548 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -56,9 +56,8 @@ jobs: if not duplicate_found: devices.append(new_device) - # Save manufacturer and model info as outputs - print(f"::set-output name=manufacturer::{new_device['manufacturer']}") - print(f"::set-output name=model::{new_device['model']}") + print(f"'manufacturer={device["manufacturer"]}'' >> $GITHUB_OUTPUT") + print(f"'model={device["model"]}'' >> $GITHUB_OUTPUT") with open("custom_components/battery_notes/data/library.json", "w") as f: f.write(json.dumps(devices_json, indent=2)) From 7637e42aefdfc91e63e849bb7e3392fb815d8083 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 15:34:57 -0500 Subject: [PATCH 19/38] update new-device.yml --- .github/workflows/new-device.yml | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 798075548..14ac48805 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -56,16 +56,28 @@ jobs: if not duplicate_found: devices.append(new_device) - print(f"'manufacturer={device["manufacturer"]}'' >> $GITHUB_OUTPUT") - print(f"'model={device["model"]}'' >> $GITHUB_OUTPUT") + # Save manufacturer and model string for use in naming the pull request + print(f"'mm={device["manufacturer"]} - {device["model"]}'' >> $GITHUB_OUTPUT") + # print(f"'manufacturer={device["manufacturer"]}'' >> $GITHUB_OUTPUT") + # print(f"'model={device["model"]}'' >> $GITHUB_OUTPUT") with open("custom_components/battery_notes/data/library.json", "w") as f: f.write(json.dumps(devices_json, indent=2)) + - name: Rename Issue + run: | + curl --request PATCH \ + --url https://api.github.com/repos/${{github.event.repository.name}}/issues/${{github.event.issue.number}} \ + --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ + --header 'Content-Type: application/json' \ + --data '{ + "title": "Device: ${{ steps.update-json.outputs.mm }}" + }' + - name: Create pull request uses: peter-evans/create-pull-request@v5 with: - commit-message: "Update device: ${{ steps.update-json.outputs.manufacturer }} - ${{ steps.update-json.outputs.json.model }}" - title: "DEVICE: ${{ steps.update-json.outputs.json.manufacturer }} - ${{ steps.update-json.outputs.json.model }}" - body: "This pull request adds or updates the device information for ${{ steps.update-json.outputs.json.manufacturer }} - ${{ steps.update-json.outputs.json.model }}\nIt closes issue #${{ github.event.issue.number }}" - branch: update-device-${{ steps.update-json.outputs.json.manufacturer }}-${{ steps.update-json.outputs.json.model }}" + commit-message: "Update device: ${{ steps.update-json.outputs.mm }}" + title: "DEVICE: ${{ steps.update-json.outputs.mm }}" + body: "This pull request adds or updates the device information for ${{ steps.update-json.outputs.mm }}\nIt closes issue #${{ github.event.issue.number }}" + branch: update-device-${{ steps.update-json.outputs.mm }}" From 9f4ad5f95bf4fafef156811812fc7a91a1dc4319 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 15:38:24 -0500 Subject: [PATCH 20/38] update new-deivce --- .github/workflows/new-device.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 14ac48805..abee5610e 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -67,7 +67,7 @@ jobs: - name: Rename Issue run: | curl --request PATCH \ - --url https://api.github.com/repos/${{github.event.repository.name}}/issues/${{github.event.issue.number}} \ + --url https://api.github.com/repos/${{github.repository}}/issues/${{github.event.issue.number}} \ --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ --header 'Content-Type: application/json' \ --data '{ From 7c2d99043960cc07008c46d58360dd1331e8a923 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 15:40:59 -0500 Subject: [PATCH 21/38] update new-device.yml --- .github/workflows/new-device.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index abee5610e..2c337935e 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -57,9 +57,9 @@ jobs: devices.append(new_device) # Save manufacturer and model string for use in naming the pull request - print(f"'mm={device["manufacturer"]} - {device["model"]}'' >> $GITHUB_OUTPUT") - # print(f"'manufacturer={device["manufacturer"]}'' >> $GITHUB_OUTPUT") - # print(f"'model={device["model"]}'' >> $GITHUB_OUTPUT") + print(f"'mm={device["manufacturer"]} - {device["model"]}' >> $GITHUB_OUTPUT") + # print(f"'manufacturer={device["manufacturer"]}' >> $GITHUB_OUTPUT") + # print(f"'model={device["model"]}' >> $GITHUB_OUTPUT") with open("custom_components/battery_notes/data/library.json", "w") as f: f.write(json.dumps(devices_json, indent=2)) From a9fc0aa8dbbaa6b2fe44fd04f31023b272a0e101 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 15:50:07 -0500 Subject: [PATCH 22/38] update new-device --- .github/workflows/new-device.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 2c337935e..cc1f30a32 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -32,6 +32,7 @@ jobs: uses: jannekem/run-python-script-action@v1 with: script: | + import os import json # Load the existing JSON library file @@ -57,9 +58,12 @@ jobs: devices.append(new_device) # Save manufacturer and model string for use in naming the pull request - print(f"'mm={device["manufacturer"]} - {device["model"]}' >> $GITHUB_OUTPUT") - # print(f"'manufacturer={device["manufacturer"]}' >> $GITHUB_OUTPUT") - # print(f"'model={device["model"]}' >> $GITHUB_OUTPUT") + def set_action_outputs(output_pairs) : + if "GITHUB_OUTPUT" in os.environ : + with open(os.environ["GITHUB_OUTPUT"], "a") as f: + for key, value in output_pairs.items(): + print(f"{key}={value}", file=f) + set_action_outputs(new_device) with open("custom_components/battery_notes/data/library.json", "w") as f: f.write(json.dumps(devices_json, indent=2)) From 67dea6941ef840fcb5d8000d9e48cefd76150cea Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 15:52:43 -0500 Subject: [PATCH 23/38] update new-device.yml --- .github/workflows/new-device.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index cc1f30a32..016dd7b84 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -32,7 +32,6 @@ jobs: uses: jannekem/run-python-script-action@v1 with: script: | - import os import json # Load the existing JSON library file @@ -58,12 +57,9 @@ jobs: devices.append(new_device) # Save manufacturer and model string for use in naming the pull request - def set_action_outputs(output_pairs) : - if "GITHUB_OUTPUT" in os.environ : - with open(os.environ["GITHUB_OUTPUT"], "a") as f: - for key, value in output_pairs.items(): - print(f"{key}={value}", file=f) - set_action_outputs(new_device) + print(f"'mm={device["manufacturer"]} - {device["model"]}' >> '$GITHUB_OUTPUT'") + # print(f"'manufacturer={device["manufacturer"]}' >> '$GITHUB_OUTPUT'") + # print(f"'model={device["model"]}' >> '$GITHUB_OUTPUT'") with open("custom_components/battery_notes/data/library.json", "w") as f: f.write(json.dumps(devices_json, indent=2)) From 4b27938ace8d5a392fb1e48f7ae10af029ba8ff4 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 15:57:11 -0500 Subject: [PATCH 24/38] update new-device --- .github/workflows/new-device.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 016dd7b84..37b7872c2 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -2,7 +2,7 @@ name: New Device on: issues: - types: [opened, edited] + types: [opened] jobs: create-device-pull-request: @@ -57,9 +57,7 @@ jobs: devices.append(new_device) # Save manufacturer and model string for use in naming the pull request - print(f"'mm={device["manufacturer"]} - {device["model"]}' >> '$GITHUB_OUTPUT'") - # print(f"'manufacturer={device["manufacturer"]}' >> '$GITHUB_OUTPUT'") - # print(f"'model={device["model"]}' >> '$GITHUB_OUTPUT'") + set_output("mm", "device['manufacturer']} - {device['model']") with open("custom_components/battery_notes/data/library.json", "w") as f: f.write(json.dumps(devices_json, indent=2)) From 41da5a54e214720d40f174f907183de4f61aee5e Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 15:59:38 -0500 Subject: [PATCH 25/38] update new-device --- .github/workflows/new-device.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 37b7872c2..70687d1d3 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -57,7 +57,7 @@ jobs: devices.append(new_device) # Save manufacturer and model string for use in naming the pull request - set_output("mm", "device['manufacturer']} - {device['model']") + set_output("mm", f"{device['manufacturer']} - {device['model']}") with open("custom_components/battery_notes/data/library.json", "w") as f: f.write(json.dumps(devices_json, indent=2)) From 7043b9e5a03a4ee6e42bd7317cee3f3b93d0f55e Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 18:10:00 -0500 Subject: [PATCH 26/38] update new-dev9ice.yml --- .github/workflows/new-device.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 70687d1d3..e8be54d50 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -78,4 +78,4 @@ jobs: commit-message: "Update device: ${{ steps.update-json.outputs.mm }}" title: "DEVICE: ${{ steps.update-json.outputs.mm }}" body: "This pull request adds or updates the device information for ${{ steps.update-json.outputs.mm }}\nIt closes issue #${{ github.event.issue.number }}" - branch: update-device-${{ steps.update-json.outputs.mm }}" + branch: "update-device-${{ steps.update-json.outputs.mm }}" From 834763fb5184c5f958f6e82204b20cfdbb504942 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 18:13:09 -0500 Subject: [PATCH 27/38] sort by man/mod --- .github/workflows/new-device.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index e8be54d50..1ce81e66e 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -56,6 +56,9 @@ jobs: if not duplicate_found: devices.append(new_device) + # Sort the devices by manufacturer and model + devices.sort(key=lambda x: (x["manufacturer"], x["model"])) + # Save manufacturer and model string for use in naming the pull request set_output("mm", f"{device['manufacturer']} - {device['model']}") From a2a27e050736db03ba5f87c806c4645ddc7dae0c Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 18:14:28 -0500 Subject: [PATCH 28/38] stop defining branch name --- .github/workflows/new-device.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 1ce81e66e..cc7438d60 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -81,4 +81,4 @@ jobs: commit-message: "Update device: ${{ steps.update-json.outputs.mm }}" title: "DEVICE: ${{ steps.update-json.outputs.mm }}" body: "This pull request adds or updates the device information for ${{ steps.update-json.outputs.mm }}\nIt closes issue #${{ github.event.issue.number }}" - branch: "update-device-${{ steps.update-json.outputs.mm }}" + # branch: "update-device-${{ steps.update-json.outputs.mm }}" From 795fe31cd5a49366b182a87e018670e49975c6bd Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 18:14:54 -0500 Subject: [PATCH 29/38] work on issue edit also --- .github/workflows/new-device.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index cc7438d60..52e66fcd8 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -2,7 +2,7 @@ name: New Device on: issues: - types: [opened] + types: [opened, edited] jobs: create-device-pull-request: From 2ed98b0bf4919faa755b2780543393c3a28dc59e Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 18:21:02 -0500 Subject: [PATCH 30/38] clean up branch name --- .github/workflows/new-device.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 52e66fcd8..bfee864a7 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -43,7 +43,7 @@ jobs: new_device = ${{ steps.device-data.outputs.json }} if int(new_device["battery_quantity"]) == 1: del new_device["battery_quantity"] - + # Check for duplicates and replace old entry with new one duplicate_found = False for i, device in enumerate(devices): @@ -51,7 +51,7 @@ jobs: devices[i] = new_device duplicate_found = True break - + # If no duplicate found, add the new device to the JSON library file if not duplicate_found: devices.append(new_device) @@ -60,8 +60,8 @@ jobs: devices.sort(key=lambda x: (x["manufacturer"], x["model"])) # Save manufacturer and model string for use in naming the pull request - set_output("mm", f"{device['manufacturer']} - {device['model']}") - + set_output("mm", '_'.join(re.findall(r'\w+',f"{device['manufacturer']}{device['model']})).lower()") + with open("custom_components/battery_notes/data/library.json", "w") as f: f.write(json.dumps(devices_json, indent=2)) @@ -81,4 +81,4 @@ jobs: commit-message: "Update device: ${{ steps.update-json.outputs.mm }}" title: "DEVICE: ${{ steps.update-json.outputs.mm }}" body: "This pull request adds or updates the device information for ${{ steps.update-json.outputs.mm }}\nIt closes issue #${{ github.event.issue.number }}" - # branch: "update-device-${{ steps.update-json.outputs.mm }}" + branch: "device-${{ steps.update-json.outputs.mm }}" From 7f31828736e5b11109220337676e181a2e5eb940 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 18:21:38 -0500 Subject: [PATCH 31/38] typo (not device) --- .github/workflows/new-device.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index bfee864a7..33e3b3051 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -60,7 +60,7 @@ jobs: devices.sort(key=lambda x: (x["manufacturer"], x["model"])) # Save manufacturer and model string for use in naming the pull request - set_output("mm", '_'.join(re.findall(r'\w+',f"{device['manufacturer']}{device['model']})).lower()") + set_output("mm", '_'.join(re.findall(r'\w+',f"{new_device['manufacturer']}{new_device['model']})).lower()") with open("custom_components/battery_notes/data/library.json", "w") as f: f.write(json.dumps(devices_json, indent=2)) From c7c3ecb77916222453d1eef7ddb0bfd23d6698a6 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 18:24:39 -0500 Subject: [PATCH 32/38] missing ) --- .github/workflows/new-device.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 33e3b3051..89ca8570e 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -60,7 +60,7 @@ jobs: devices.sort(key=lambda x: (x["manufacturer"], x["model"])) # Save manufacturer and model string for use in naming the pull request - set_output("mm", '_'.join(re.findall(r'\w+',f"{new_device['manufacturer']}{new_device['model']})).lower()") + set_output("mm", '_'.join(re.findall(r'\w+',f"{new_device['manufacturer']}{new_device['model']}).lower()"))) with open("custom_components/battery_notes/data/library.json", "w") as f: f.write(json.dumps(devices_json, indent=2)) From 760e53fcaf7c764744f59b0afa559d3c07215db9 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 18:25:32 -0500 Subject: [PATCH 33/38] import re --- .github/workflows/new-device.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 89ca8570e..617642439 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -32,6 +32,7 @@ jobs: uses: jannekem/run-python-script-action@v1 with: script: | + import re import json # Load the existing JSON library file From 5d110dc88b8fbc7fa341ca7fba4e55cce1075801 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 18:33:42 -0500 Subject: [PATCH 34/38] improved naming --- .github/workflows/new-device.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 617642439..4fae859a3 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -60,8 +60,10 @@ jobs: # Sort the devices by manufacturer and model devices.sort(key=lambda x: (x["manufacturer"], x["model"])) - # Save manufacturer and model string for use in naming the pull request - set_output("mm", '_'.join(re.findall(r'\w+',f"{new_device['manufacturer']}{new_device['model']}).lower()"))) + # Save manufacturer and model for later use + set_output("mm", "_".join(re.findall(r"\w+",f"{new_device['manufacturer']}{new_device['model']})".lower()))) + set_output("manufacturer", "_".join(re.findall(r"\w+",f"{new_device['manufacturer']})"))) + set_output("model", "_".join(re.findall(r"\w+",f"{new_device['model']})"))) with open("custom_components/battery_notes/data/library.json", "w") as f: f.write(json.dumps(devices_json, indent=2)) @@ -79,7 +81,7 @@ jobs: - name: Create pull request uses: peter-evans/create-pull-request@v5 with: - commit-message: "Update device: ${{ steps.update-json.outputs.mm }}" - title: "DEVICE: ${{ steps.update-json.outputs.mm }}" - body: "This pull request adds or updates the device information for ${{ steps.update-json.outputs.mm }}\nIt closes issue #${{ github.event.issue.number }}" + commit-message: "Update device: ${{ steps.update-json.outputs.model }} by ${{ steps.update-json.outputs.manufacturer }}" + title: "DEVICE: ${{ steps.update-json.outputs.manufacturer }} - ${{ steps.update-json.outputs.model }}" + body: "This pull request adds or updates the device information for ${{ steps.update-json.outputs.model }} by ${{ steps.update-json.outputs.manufacturer }}\nIt closes issue #${{ github.event.issue.number }}" branch: "device-${{ steps.update-json.outputs.mm }}" From d2676b4e89b3af95a20ca1069f556217c9361175 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 18:40:06 -0500 Subject: [PATCH 35/38] update new-dev --- .github/workflows/new-device.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 4fae859a3..3fc49b8ba 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -58,7 +58,7 @@ jobs: devices.append(new_device) # Sort the devices by manufacturer and model - devices.sort(key=lambda x: (x["manufacturer"], x["model"])) + devices = sorted(devices , key=lambda device: "%02d %s" % (device['manufacturer'], device['model'])) # Save manufacturer and model for later use set_output("mm", "_".join(re.findall(r"\w+",f"{new_device['manufacturer']}{new_device['model']})".lower()))) From fa895291d6a83c3e76fa27b17e1bf03593414cda Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 18:43:36 -0500 Subject: [PATCH 36/38] alt attemp --- .github/workflows/new-device.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index 3fc49b8ba..db212e965 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -58,7 +58,7 @@ jobs: devices.append(new_device) # Sort the devices by manufacturer and model - devices = sorted(devices , key=lambda device: "%02d %s" % (device['manufacturer'], device['model'])) + devices = sorted(devices, key=lambda k: cmp(k['manufacturer'], k['model'])) # Save manufacturer and model for later use set_output("mm", "_".join(re.findall(r"\w+",f"{new_device['manufacturer']}{new_device['model']})".lower()))) From e9a8f4ea157960b9d0d3fe67ebe990adc7384ddd Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 18:44:30 -0500 Subject: [PATCH 37/38] remokve cmp --- .github/workflows/new-device.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index db212e965..acee89825 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -58,7 +58,7 @@ jobs: devices.append(new_device) # Sort the devices by manufacturer and model - devices = sorted(devices, key=lambda k: cmp(k['manufacturer'], k['model'])) + devices = sorted(devices, key=lambda k: (k['manufacturer'], k['model'])) # Save manufacturer and model for later use set_output("mm", "_".join(re.findall(r"\w+",f"{new_device['manufacturer']}{new_device['model']})".lower()))) From 497099f05b374daf3e46ba80315c92c0bbd320ab Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Fri, 15 Dec 2023 18:47:06 -0500 Subject: [PATCH 38/38] sort in place --- .github/workflows/new-device.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/new-device.yml b/.github/workflows/new-device.yml index acee89825..16344f1ed 100644 --- a/.github/workflows/new-device.yml +++ b/.github/workflows/new-device.yml @@ -58,7 +58,7 @@ jobs: devices.append(new_device) # Sort the devices by manufacturer and model - devices = sorted(devices, key=lambda k: (k['manufacturer'], k['model'])) + devices.sort(key=lambda k: (k['manufacturer'], k['model'])) # Save manufacturer and model for later use set_output("mm", "_".join(re.findall(r"\w+",f"{new_device['manufacturer']}{new_device['model']})".lower())))