Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No-Code Device Submission #49

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3349884
Create new-device.yml
bmos Dec 15, 2023
a360432
Create new-device.yml
bmos Dec 15, 2023
a6d0692
Merge branch 'andrew-codechimp:main' into automatic-device-definitions
bmos Dec 15, 2023
d54ddc7
update json_validate actions
bmos Dec 15, 2023
9ae1531
update ruff and validate against 3.11 and 3.12
bmos Dec 15, 2023
4d6e46f
convert update-json to use python
bmos Dec 15, 2023
05b142c
update new-device.yml
bmos Dec 15, 2023
6e7a4f3
update new-device
bmos Dec 15, 2023
a0b875c
new device updates
bmos Dec 15, 2023
54d8b7b
update new-device.yml
bmos Dec 15, 2023
1988174
new-device.yml
bmos Dec 15, 2023
d8f261a
update new-device.yml
bmos Dec 15, 2023
6ea87bd
update new-device.yml
bmos Dec 15, 2023
bca248d
update new-device
bmos Dec 15, 2023
82d8fda
update new-device.yml
bmos Dec 15, 2023
96a1d82
update new-device.yml
bmos Dec 15, 2023
d451e5f
update new-device.yml
bmos Dec 15, 2023
81cc448
update new-device.yml
bmos Dec 15, 2023
14be150
update new-device.yml
bmos Dec 15, 2023
7637e42
update new-device.yml
bmos Dec 15, 2023
9f4ad5f
update new-deivce
bmos Dec 15, 2023
7c2d990
update new-device.yml
bmos Dec 15, 2023
a9fc0aa
update new-device
bmos Dec 15, 2023
67dea69
update new-device.yml
bmos Dec 15, 2023
4b27938
update new-device
bmos Dec 15, 2023
41da5a5
update new-device
bmos Dec 15, 2023
7043b9e
update new-dev9ice.yml
bmos Dec 15, 2023
834763f
sort by man/mod
bmos Dec 15, 2023
a2a27e0
stop defining branch name
bmos Dec 15, 2023
795fe31
work on issue edit also
bmos Dec 15, 2023
2ed98b0
clean up branch name
bmos Dec 15, 2023
7f31828
typo (not device)
bmos Dec 15, 2023
c7c3ecb
missing )
bmos Dec 15, 2023
760e53f
import re
bmos Dec 15, 2023
5d110dc
improved naming
bmos Dec 15, 2023
d2676b4
update new-dev
bmos Dec 15, 2023
fa89529
alt attemp
bmos Dec 15, 2023
e9a8f4e
remokve cmp
bmos Dec 15, 2023
497099f
sort in place
bmos Dec 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/ISSUE_TEMPLATE/new-device.yml
Original file line number Diff line number Diff line change
@@ -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: 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: 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: 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: Battery Quantity
description: The battery_quantity attribute is numeric (no letters or special characters).
placeholder: ex. 1
validations:
required: true
4 changes: 2 additions & 2 deletions .github/workflows/json_validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
44 changes: 26 additions & 18 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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 .
87 changes: 87 additions & 0 deletions .github/workflows/new-device.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: New Device

on:
issues:
types: [opened, edited]

jobs:
create-device-pull-request:
if: ${{ contains(github.event.issue.title , '[Device]')}}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Parse device data
id: device-data
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

- name: Set up python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Update JSON file
id: update-json
uses: jannekem/run-python-script-action@v1
with:
script: |
import re
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 }}
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):
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)

# Sort the devices by manufacturer and 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())))
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))

- name: Rename Issue
run: |
curl --request PATCH \
--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 '{
"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.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 }}"
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Loading