From 44be86140f069118146bd7823c1263288dc6ad98 Mon Sep 17 00:00:00 2001 From: Andrew Jackson Date: Mon, 11 Dec 2023 09:37:58 +0000 Subject: [PATCH 1/8] Init commit of schema validator --- .github/workflows/json_validate.yml | 14 ++++++++++ schema.json | 41 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 .github/workflows/json_validate.yml create mode 100644 schema.json diff --git a/.github/workflows/json_validate.yml b/.github/workflows/json_validate.yml new file mode 100644 index 000000000..92b0401ef --- /dev/null +++ b/.github/workflows/json_validate.yml @@ -0,0 +1,14 @@ +name: Validate JSONs + +on: [push, pull_request] + +jobs: + verify-json-validation: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Validate JSON + uses: docker://orrosenblatt/validate-json-action:latest + env: + INPUT_SCHEMA: ./schema.json + INPUT_JSONS: custom_components/battery_notes/data/library.json diff --git a/schema.json b/schema.json new file mode 100644 index 000000000..5c5d99b0c --- /dev/null +++ b/schema.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/andrew-codechimp/HA-Battery-Notes.schema.json", + "title": "Battery Notes Library", + "description": "Library of battery types for devices", + "type": "object", + "properties": { + "version": { + "description": "Version of the library schema", + "type": "integer" + }, + "devices": { + "type": "array", + "properties": { + "manufacturer": { + "type": "string" + }, + "model": { + "type": "string" + }, + "battery_type": { + "type": "string" + }, + "battery_quantity": { + "type": "integer" + } + }, + "additionalProperties": false, + "required": [ + "manufacturer", + "model", + "battery_type" + ] + } + }, + "additionalProperties": false, + "required": [ + "version", + "devices" + ] +} \ No newline at end of file From 1283fa23020f6042056327334892500144465141 Mon Sep 17 00:00:00 2001 From: Andrew Jackson Date: Mon, 11 Dec 2023 09:40:38 +0000 Subject: [PATCH 2/8] WIP --- schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schema.json b/schema.json index 5c5d99b0c..64c085d6a 100644 --- a/schema.json +++ b/schema.json @@ -1,5 +1,5 @@ { - "$schema": "https://json-schema.org/draft/2020-12/schema", + "$schema": "http://json-schema.org/draft-07/schema", "$id": "https://github.com/andrew-codechimp/HA-Battery-Notes.schema.json", "title": "Battery Notes Library", "description": "Library of battery types for devices", From 66d2d40a6598f3bc4936212d0fec04b19e081d49 Mon Sep 17 00:00:00 2001 From: Andrew Jackson Date: Mon, 11 Dec 2023 09:41:43 +0000 Subject: [PATCH 3/8] Test a bad schema --- .../battery_notes/data/library.json | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/custom_components/battery_notes/data/library.json b/custom_components/battery_notes/data/library.json index 8d3f79c28..e45dd919c 100644 --- a/custom_components/battery_notes/data/library.json +++ b/custom_components/battery_notes/data/library.json @@ -4,31 +4,30 @@ { "manufacturer": "Develco", "model": "Smoke detector with siren (SMSZB-120)", - "battery_type": "CR123" }, { "manufacturer": "DIYRuZ", "model": "[Flower sensor](http://modkam.ru/?p=1700) (DIYRuZ_Flower)", "battery_type": "AAA", "battery_quantity": 2 - }, + }, { "manufacturer": "Fantem", "model": "4 in 1 multi sensor (ZB003-X)", "battery_type": "CR123A", "battery_quantity": 2 - }, + }, { "manufacturer": "GiEX", "model": "Water irrigation valve (QT06_2)", "battery_type": "AA", "battery_quantity": 4 - }, + }, { "manufacturer": "HEIMAN", "model": "Smart carbon monoxide sensor (HS1CA-E)", "battery_type": "CR123A" - }, + }, { "manufacturer": "OSRAM", "model": "Smart+ switch mini (AC0251100NJ/AC0251600NJ/AC0251700NJ)", @@ -70,24 +69,24 @@ "manufacturer": "SONOFF", "model": "Motion sensor (SNZB-03)", "battery_type": "CR2450" - }, + }, { "manufacturer": "Sonoff", "model": "Temperature and humidity sensor (SNZB-02)", "battery_type": "CR2430" - }, + }, { "manufacturer": "Sure Petcare", "model": "Pet flap", "battery_type": "C", "battery_quantity": 4 - }, + }, { "manufacturer": "SwitchBot", "model": "W340001X", "battery_type": "AAA", "battery_quantity": 2 - }, + }, { "manufacturer": "Tado", "model": "RU01", @@ -99,13 +98,13 @@ "model": "VA02", "battery_type": "AA", "battery_quantity": 2 - }, + }, { "manufacturer": "TT Lock", "model": "SN511-180MS_PV53", "battery_type": "AA", "battery_quantity": 4 - }, + }, { "manufacturer": "TuYa", "model": "Soil sensor (TS0601_soil)", @@ -153,12 +152,12 @@ "manufacturer": "Xiaomi", "model": "Aqara D1 double key wireless wall switch (WXKG07LM)", "battery_type": "CR2032" - }, + }, { "manufacturer": "Xiaomi", "model": "Aqara D1 single key wireless wall switch (WXKG06LM)", "battery_type": "CR2032" - }, + }, { "manufacturer": "Xiaomi", "model": "Aqara wireless switch (WXKG11LM)", @@ -169,7 +168,7 @@ "model": "Aqara TVOC air quality monitor (VOCKQJK11LM)", "battery_type": "CR2450", "battery_quantity": 2 - }, + }, { "manufacturer": "Xiaomi", "model": "Aqara water leak sensor (SJCGQ11LM)", @@ -184,16 +183,16 @@ "manufacturer": "Xiaomi", "model": "HHCCJCY01", "battery_type": "CR2032" - }, + }, { "manufacturer": "Xiaomi", "model": "LYWSD03MMC", "battery_type": "CR2032" - }, + }, { "manufacturer": "Xiaomi", "model": "MiJia wireless switch (WXKG01LM)", "battery_type": "CR2032" } ] -} +} \ No newline at end of file From f2bf26370b7e054676fcf1e435dd844af1ec729a Mon Sep 17 00:00:00 2001 From: Andrew Jackson Date: Mon, 11 Dec 2023 09:43:06 +0000 Subject: [PATCH 4/8] Another bad schema test --- custom_components/battery_notes/data/library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/battery_notes/data/library.json b/custom_components/battery_notes/data/library.json index e45dd919c..882f11afe 100644 --- a/custom_components/battery_notes/data/library.json +++ b/custom_components/battery_notes/data/library.json @@ -3,7 +3,7 @@ "devices": [ { "manufacturer": "Develco", - "model": "Smoke detector with siren (SMSZB-120)", + "model": "Smoke detector with siren (SMSZB-120)" }, { "manufacturer": "DIYRuZ", From e63c503fde3d6bdbf84b52a8954cba9dd2ed3ab6 Mon Sep 17 00:00:00 2001 From: Andrew Jackson Date: Mon, 11 Dec 2023 10:01:37 +0000 Subject: [PATCH 5/8] Update schema --- schema.json | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/schema.json b/schema.json index 64c085d6a..076de0064 100644 --- a/schema.json +++ b/schema.json @@ -11,26 +11,29 @@ }, "devices": { "type": "array", - "properties": { - "manufacturer": { - "type": "string" - }, - "model": { - "type": "string" - }, - "battery_type": { - "type": "string" - }, - "battery_quantity": { - "type": "integer" + "items": { + "type": "object", + "additionalProperties": false, + "required": [ + "manufacturer", + "model", + "battery_type" + ], + "properties": { + "manufacturer": { + "type": "string" + }, + "model": { + "type": "string" + }, + "battery_type": { + "type": "string" + }, + "battery_quantity": { + "type": "integer" + } } - }, - "additionalProperties": false, - "required": [ - "manufacturer", - "model", - "battery_type" - ] + } } }, "additionalProperties": false, From 8b3c05edd7c3b17addf8b1649d4a114fd339d164 Mon Sep 17 00:00:00 2001 From: Andrew Jackson Date: Mon, 11 Dec 2023 10:02:43 +0000 Subject: [PATCH 6/8] Repair library --- custom_components/battery_notes/data/library.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/custom_components/battery_notes/data/library.json b/custom_components/battery_notes/data/library.json index 882f11afe..c83173d2f 100644 --- a/custom_components/battery_notes/data/library.json +++ b/custom_components/battery_notes/data/library.json @@ -3,7 +3,8 @@ "devices": [ { "manufacturer": "Develco", - "model": "Smoke detector with siren (SMSZB-120)" + "model": "Smoke detector with siren (SMSZB-120)", + "battery_type": "CR123" }, { "manufacturer": "DIYRuZ", From dcc42dadf23d75cc2fc30514c6729946a8da1c27 Mon Sep 17 00:00:00 2001 From: Andrew Jackson Date: Mon, 11 Dec 2023 10:13:16 +0000 Subject: [PATCH 7/8] Change validate package --- .github/workflows/json_validate.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/json_validate.yml b/.github/workflows/json_validate.yml index 92b0401ef..25fde61c1 100644 --- a/.github/workflows/json_validate.yml +++ b/.github/workflows/json_validate.yml @@ -8,7 +8,7 @@ jobs: steps: - uses: actions/checkout@v1 - name: Validate JSON - uses: docker://orrosenblatt/validate-json-action:latest - env: - INPUT_SCHEMA: ./schema.json - INPUT_JSONS: custom_components/battery_notes/data/library.json + uses: nhalstead/validate-json-action@0.1.3 + with: + schema: ./schema.json + jsons: custom_components/battery_notes/data/library.json From d63375aa6e80c1c6a95c6aa97d0c7648ecd97db5 Mon Sep 17 00:00:00 2001 From: Andrew Jackson Date: Mon, 11 Dec 2023 10:15:25 +0000 Subject: [PATCH 8/8] Change back to more popular validator --- .github/workflows/json_validate.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/json_validate.yml b/.github/workflows/json_validate.yml index 25fde61c1..92b0401ef 100644 --- a/.github/workflows/json_validate.yml +++ b/.github/workflows/json_validate.yml @@ -8,7 +8,7 @@ jobs: steps: - uses: actions/checkout@v1 - name: Validate JSON - uses: nhalstead/validate-json-action@0.1.3 - with: - schema: ./schema.json - jsons: custom_components/battery_notes/data/library.json + uses: docker://orrosenblatt/validate-json-action:latest + env: + INPUT_SCHEMA: ./schema.json + INPUT_JSONS: custom_components/battery_notes/data/library.json