Skip to content

Commit be5bc38

Browse files
Add openhab (#5270)
* openhab-5.1 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add openhab to highSchemaVersion * forgot commit :S * fix test file * add missing type "object" * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Replace reference with copy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * non-strict mode * fix and more tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * more tests * renamed some fields --------- Co-authored-by: - <-> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 9fbaa99 commit be5bc38

11 files changed

+499
-0
lines changed

src/api/json/catalog.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9197,6 +9197,15 @@
91979197
"**/models/**/*.vespertide.yml"
91989198
],
91999199
"url": "https://www.schemastore.org/vespertide-model.json"
9200+
},
9201+
{
9202+
"name": "openHAB",
9203+
"description": "Configuration files for openHAB",
9204+
"fileMatch": ["**/conf/yaml/**/*.yml", "**/conf/yaml/**/*.yaml"],
9205+
"url": "https://www.schemastore.org/openhab-5.1.json",
9206+
"versions": {
9207+
"5.1": "https://www.schemastore.org/openhab-5.1.json"
9208+
}
92009209
}
92019210
]
92029211
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# yaml-language-server: $schema=../../schemas/json/openhab-5.1.json
2+
3+
items:
4+
MyItem:
5+
type: String
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# yaml-language-server: $schema=../../schemas/json/openhab-5.1.json
2+
3+
version: 1
4+
5+
items:
6+
# This item has a dimension set even though it's not a Number
7+
MyWrongNumberItem:
8+
type: Switch
9+
dimension: 'W'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# yaml-language-server: $schema=../../schemas/json/openhab-5.1.json
2+
3+
version: 1
4+
5+
items:
6+
# This group has a dimension set even though it's not a Number
7+
MyWrongGroupItem:
8+
type: Group
9+
group:
10+
type: Switch
11+
dimension: 'W'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# yaml-language-server: $schema=../../schemas/json/openhab-5.1.json
2+
3+
version: 1
4+
5+
things:
6+
# If type is set itemType can not be set
7+
my:thing:uuid:
8+
channels:
9+
channel_1:
10+
itemType: Switch
11+
itemDimension: W
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# yaml-language-server: $schema=../../schemas/json/openhab-5.1.json
2+
3+
version: 1
4+
5+
things:
6+
# If type is set kind can not be set
7+
my:thing:uuid:
8+
channels:
9+
channel_1:
10+
type: switch
11+
kind: state
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# yaml-language-server: $schema=../../schemas/json/openhab-5.1.json
2+
3+
version: 1
4+
5+
things:
6+
# If type is set itemType can not be set
7+
my:thing:uuid:
8+
channels:
9+
channel_1:
10+
type: switch
11+
itemType: String
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# yaml-language-server: $schema=../../schemas/json/openhab-5.1.json
2+
3+
version: 1
4+
5+
things:
6+
# If type is set itemType can not be set
7+
my:thing:uuid:
8+
channels:
9+
channel_1:
10+
type: switch
11+
itemDimension: String

src/schema-validation.jsonc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@
251251
"lsdlschema-4.1.json",
252252
"lsdlschema.json",
253253
"nodemon.json",
254+
"openhab-5.1.json",
254255
"partial-pyright.json",
255256
"pep-723.json",
256257
"pyproject.json",
@@ -298,6 +299,7 @@
298299
"license-report-config.json",
299300
"openweather.current.json",
300301
"openweather.roadrisk.json",
302+
"openhab-5.1.json",
301303
"specif-1.1.json",
302304
"ctfd.json",
303305
"zarf.json",

src/schemas/json/openhab-5.1.json

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://json.schemastore.org/openhab-5.1.json",
4+
"$defs": {
5+
"bool_value_type": { "enum": [true, false] },
6+
"thing_uid": {
7+
"type": "string",
8+
"pattern": "^[A-Za-z0-9]([\\w-]+:)+[\\w-]+$"
9+
},
10+
"item_type_enum": {
11+
"type": "string",
12+
"enum": [
13+
"Call",
14+
"Color",
15+
"Contact",
16+
"DateTime",
17+
"Dimmer",
18+
"Group",
19+
"Image",
20+
"Location",
21+
"Number",
22+
"Player",
23+
"Rollershutter",
24+
"String",
25+
"Switch"
26+
]
27+
},
28+
"item_dimension_type": { "type": "string" },
29+
"config_value_type": {
30+
"oneOf": [
31+
{ "$ref": "#/$defs/bool_value_type" },
32+
{ "type": "number" },
33+
{ "type": "string" }
34+
]
35+
},
36+
37+
"key_value_config_type": {
38+
"type": "object",
39+
"additionalProperties": false,
40+
"patternProperties": {
41+
"^[A-Za-z]\\w*$": { "$ref": "#/$defs/config_value_type" }
42+
}
43+
},
44+
"key_array_value_config_type": {
45+
"type": "object",
46+
"additionalProperties": false,
47+
"patternProperties": {
48+
"^[A-Za-z]\\w*$": {
49+
"oneOf": [
50+
{ "$ref": "#/$defs/config_value_type" },
51+
{
52+
"type": "array",
53+
"items": { "$ref": "#/$defs/config_value_type" }
54+
}
55+
]
56+
}
57+
}
58+
}
59+
},
60+
"title": "openHAB 5.1",
61+
"description": "Schema for openHAB configuration files. Implements version 5.1",
62+
"type": "object",
63+
"additionalProperties": false,
64+
"required": ["version"],
65+
"properties": {
66+
"version": { "type": "integer", "const": 1 },
67+
"things": {
68+
"type": "object",
69+
"additionalProperties": false,
70+
"patternProperties": {
71+
"^[A-Za-z0-9]([\\w-]+:)+[\\w-]+$": {
72+
"type": "object",
73+
"properties": {
74+
"isBridge": { "$ref": "#/$defs/bool_value_type" },
75+
"bridge": { "$ref": "#/$defs/thing_uid" },
76+
"location": { "type": "string" },
77+
"config": { "$ref": "#/$defs/key_value_config_type" },
78+
"channels": {
79+
"type": "object",
80+
"additionalProperties": false,
81+
"patternProperties": {
82+
"^.+$": {
83+
"type": "object",
84+
"properties": {
85+
"type": { "type": "string" },
86+
"kind": { "enum": ["state", "trigger"] },
87+
"itemType": { "$ref": "#/$defs/item_type_enum" },
88+
"itemDimension": { "$ref": "#/$defs/item_dimension_type" },
89+
"label": { "type": "string" },
90+
"description": { "type": "string" },
91+
"config": { "$ref": "#/$defs/key_array_value_config_type" }
92+
},
93+
"allOf": [
94+
{
95+
"if": { "required": ["type"] },
96+
"then": {
97+
"not": {
98+
"anyOf": [
99+
{ "required": ["kind"] },
100+
{ "required": ["itemType"] }
101+
]
102+
}
103+
}
104+
},
105+
{
106+
"if": { "type": "object", "required": ["itemDimension"] },
107+
"then": {
108+
"properties": { "itemType": { "const": "Number" } }
109+
}
110+
},
111+
{
112+
"if": {
113+
"type": "object",
114+
"properties": {
115+
"itemType": { "not": { "const": "Number" } }
116+
}
117+
},
118+
"then": { "not": { "required": ["itemDimension"] } }
119+
}
120+
]
121+
}
122+
}
123+
}
124+
}
125+
}
126+
}
127+
},
128+
"items": {
129+
"type": "object",
130+
"additionalProperties": false,
131+
"patternProperties": {
132+
"^[a-zA-Z_][a-zA-Z0-9_]*$": {
133+
"type": "object",
134+
"properties": {
135+
"type": { "$ref": "#/$defs/item_type_enum" },
136+
"dimension": { "type": "string" },
137+
"group": {
138+
"type": "object",
139+
"additionalProperties": false,
140+
"properties": {
141+
"type": { "$ref": "#/$defs/item_type_enum" },
142+
"dimension": { "type": "string" },
143+
"function": {
144+
"type": "string",
145+
"enum": [
146+
"EQUALITY",
147+
"AND",
148+
"OR",
149+
"NAND",
150+
"NOR",
151+
"XOR",
152+
"SUM",
153+
"AVG",
154+
"MEDIAN",
155+
"MIN",
156+
"MAX",
157+
"COUNT",
158+
"LATEST",
159+
"EARLIEST"
160+
]
161+
},
162+
"parameters": {
163+
"type": "array",
164+
"items": {
165+
"type": "string"
166+
}
167+
}
168+
},
169+
"allOf": [
170+
{
171+
"if": { "type": "object", "required": ["dimension"] },
172+
"then": { "properties": { "type": { "const": "Number" } } }
173+
},
174+
{
175+
"if": {
176+
"type": "object",
177+
"properties": { "type": { "not": { "const": "Number" } } }
178+
},
179+
"then": { "not": { "required": ["dimension"] } }
180+
}
181+
]
182+
},
183+
"label": { "type": "string" },
184+
"icon": { "type": "string" },
185+
"groups": {
186+
"type": "array",
187+
"items": {
188+
"type": "string",
189+
"pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$"
190+
}
191+
},
192+
"tags": {
193+
"type": "array",
194+
"items": {
195+
"type": "string",
196+
"pattern": "^[a-zA-Z_][a-zA-Z0-9_-]*$"
197+
}
198+
},
199+
"format": { "type": "string" },
200+
"unit": { "type": "string" },
201+
"autoupdate": { "$ref": "#/$defs/bool_value_type" },
202+
"channel": { "type": "string" },
203+
"channels": {
204+
"type": "object",
205+
"patternProperties": {
206+
"^.*$": { "$ref": "#/$defs/key_array_value_config_type" }
207+
}
208+
},
209+
"metadata": {
210+
"type": "object",
211+
"patternProperties": {
212+
"^.*$": {
213+
"type": "object",
214+
"properties": {
215+
"value": { "$ref": "#/$defs/config_value_type" },
216+
"config": { "$ref": "#/$defs/key_value_config_type" }
217+
}
218+
}
219+
}
220+
}
221+
},
222+
"allOf": [
223+
{
224+
"if": { "type": "object", "required": ["dimension"] },
225+
"then": { "properties": { "type": { "const": "Number" } } }
226+
},
227+
{
228+
"if": {
229+
"type": "object",
230+
"properties": { "type": { "not": { "const": "Number" } } }
231+
},
232+
"then": { "not": { "required": ["dimension"] } }
233+
},
234+
{
235+
"not": {
236+
"required": ["channel", "channels"]
237+
}
238+
}
239+
]
240+
}
241+
}
242+
},
243+
"tags": {
244+
"type": "object",
245+
"additionalProperties": false,
246+
"patternProperties": {
247+
"^(Location|Equipment|Point|Property)_([A-Z][A-Za-z0-9_]+)*[A-Z][A-Za-z0-9_]*$": {
248+
"type": "object",
249+
"properties": {
250+
"label": { "type": "string" },
251+
"description": { "type": "string" },
252+
"synonyms": {
253+
"type": "array",
254+
"items": { "type": "string" }
255+
}
256+
}
257+
}
258+
}
259+
}
260+
}
261+
}

0 commit comments

Comments
 (0)