Skip to content

Commit

Permalink
update new-device.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
bmos committed Dec 15, 2023
1 parent d8f261a commit 6ea87bd
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions .github/workflows/new-device.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 6ea87bd

Please sign in to comment.