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

[REST] New REST APIs to generate DSL syntax for items and things #4569

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

lolodomo
Copy link
Contributor

@lolodomo lolodomo commented Jan 19, 2025

Related to #4509

Added REST APIs:

  • GET /inbox/{thingUID}/syntax/generate to generate syntax for the thing associated to the discovery result
  • GET /items/syntax/generate to generate syntax for all items
  • GET /items/{itemname}/syntax/generate to generate syntax for an item
  • GET /things/syntax/generate to generate syntax for all things
  • GET /things/{thingUID}/syntax/generate to generate syntax for a thing

All these APIs have a parameter named "format" to request a particular output format. Of course, a syntax generator should be available for this format. Only "DSL" format is provided by this PR as this is currently our unique supported format for items and things in config files. So this parameter is set to "DSL" by default. In the future, new formats could be added and they will be automatically supported by these APIs.

All these APIs have a boolean parameter named "hideDefaultParameters" to hide or show the configuration parameters having the default value. They are hidden by default.

The API GET /things/filesyntax has another parameter named "preferPresentationAsTree" allowing to choose between a flat display or a display as a tree. Its default value is true for a display of things as tree.

@lolodomo lolodomo requested a review from a team as a code owner January 19, 2025 22:55
@lolodomo lolodomo marked this pull request as draft January 19, 2025 22:55
@lolodomo lolodomo force-pushed the generate_dsl branch 12 times, most recently from 521b446 to 2ce9669 Compare January 25, 2025 10:14
@lolodomo
Copy link
Contributor Author

lolodomo commented Jan 25, 2025

Here is an example of result for things:

Thing astro:moon:e2015c6f37 "Données Astro de Lune" @ "Paris" [geolocation="49.023461463214126,-1.1425781250000002"] {
	Channels:
		Type end : rise#end "Heure Fin" [offset=-1, forceEvent=true]
}
Bridge freeboxos:api:api "Freebox API" [appToken="xxxxx", httpsAvailable=true] {
	Thing active-player player-test "Player Revolution" [remoteCode="123456"]
	Thing player player4k "Player Mini 4k" [id=15]
	Thing revolution serveur-test "Serveur Revolution"
}
Bridge netatmo:account:compte "Netatmo" [clientId="yyyyy", clientSecret="zzzzz"] {
	Bridge weather-station indoor "Indoor" [id="11:22:33:44:55:66"] {
		Thing outdoor exterieur "Sonde extérieure" [id="22:33:44:55:66:77"]
		Thing rain pluviometre "Pluviomètre" [id="33:44:55:66:77:88"]
		Channels:
			Type co2-measurement : max-co2-hour "Max CO2 Last Day" [limit="MAX", period="1day"]
			Type co2-measurement : max-co2-week "Max CO2 Last Week" [limit="MAX"]
			Type co2-measurement : min-co2-hour "Min CO2 Last Day" [period="1day"]
			Type co2-measurement : min-co2-week "Min CO2 Last Week"
			Type noise-measurement : max-noise-hour "Max Noise Last Hour" [limit="MAX", period="1hour"]
			Type noise-measurement : min-noise-hour "Min Noise Last Hour" [period="1hour"]
			Type noise-timestamp : time-max-noise-week "Time Max Noise Last Week" [limit="DATE_MAX"]
			State Number : test-number [param1="Value 1", param2=true, param3=15, 20.5, 25.5, 30]
			Trigger String : test-string [titi=100, toto=true, false, true]
	}
}
Thing ntp:ntp:local "Local Time" [hostname="0.fr.pool.ntp.org", timeZone="Europe/Paris"] {
	Channels:
		Type string-channel : string "Date Heure" [DateTimeFormat="dd-MM-yyyy HH:mm:ss"]
}

and the same in flat mode:

Thing astro:moon:e2015c6f37 "Données Astro de Lune" @ "Paris" [geolocation="49.023461463214126,-1.1425781250000002"] {
	Channels:
		Type end : rise#end "Heure Fin" [offset=-1, forceEvent=true]
}
Thing freeboxos:api:api "Freebox API" [appToken="xxxxx", httpsAvailable=true]
Thing freeboxos:active-player:api:player-test "Player Revolution" (freeboxos:api:api) [remoteCode="123456"]
Thing freeboxos:player:api:player4k "Player Mini 4k" (freeboxos:api:api) [id=15]
Thing freeboxos:revolution:api:serveur-test "Serveur Revolution" (freeboxos:api:api)
Thing netatmo:account:compte "Netatmo" [clientId="yyyyy", clientSecret="zzzzz"]
Thing netatmo:weather-station:compte:indoor "Indoor" (netatmo:account:compte) [id="11:22:33:44:55:66"] {
	Channels:
		Type co2-measurement : max-co2-hour "Max CO2 Last Day" [limit="MAX", period="1day"]
		Type co2-measurement : max-co2-week "Max CO2 Last Week" [limit="MAX"]
		Type co2-measurement : min-co2-hour "Min CO2 Last Day" [period="1day"]
		Type co2-measurement : min-co2-week "Min CO2 Last Week"
		Type noise-measurement : max-noise-hour "Max Noise Last Hour" [limit="MAX", period="1hour"]
		Type noise-measurement : min-noise-hour "Min Noise Last Hour" [period="1hour"]
		Type noise-timestamp : time-max-noise-week "Time Max Noise Last Week" [limit="DATE_MAX"]
		State Number : test-number [param1="Value 1", param2=true, param3=15, 20.5, 25.5, 30]
		Trigger String : test-string [titi=100, toto=true, false, true]
}
Thing netatmo:outdoor:compte:indoor:exterieur "Sonde extérieure" (netatmo:weather-station:compte:indoor) [id="22:33:44:55:66:77"]
Thing netatmo:rain:compte:indoor:pluviometre "Pluviomètre" (netatmo:weather-station:compte:indoor) [id="33:44:55:66:77:88"]
Thing ntp:ntp:local "Local Time" [hostname="0.fr.pool.ntp.org", timeZone="Europe/Paris"] {
	Channels:
		Type string-channel : string "Date Heure" [DateTimeFormat="dd-MM-yyyy HH:mm:ss"]
}

@lolodomo
Copy link
Contributor Author

lolodomo commented Jan 25, 2025

And the result for items:

Group:Switch:OR (ON, OFF) DemoSwitchGroup [home-group]
Group X "Group X"
Group C "Group C" (X, U)
Group U "Group U" (X)
Color DemoColor (DemoSwitchGroup)
Contact DemoContact
DateTime DemoDateTime
Dimmer DemoDimmer (DemoSwitchGroup) { autoupdate="false" }
Number:Dimensionless DemoHumidity "Humidity [%.0f %%]" <humidity> (U, C) [Humidity, Measurement] { listWidget="" [action="", iconUseState=true], unit="%" }
Number:Dimensionless DemoHumidity2 "Humidity 2" <humidity> (U, C) [Humidity, Measurement] { listWidget="" [action="", iconUseState=true], unit="%" }
Image DemoImage
Location DemoLocation "Demo Location"
Number DemoNumber (U)
Number DemoNumber2 (U) { stateDescription="" [min=-10, max=20, step=0.5, pattern="%.1f"] }
Number DemoNumber3 "Demo Number 3 [%.1f]" (U) { stateDescription="" [min=-10, max=20, step=0.5, pattern="%.1f"] }
Number DemoNumber4 "Demo Number 4" (U) { stateDescription="" [min=-5, max=5, pattern="%.0f", readOnly=true] }
Number DemoNumber5 "Demo Number 5" (U)
Rollershutter DemoRollershutter
String DemoString (X)
String DemoString2 "My String 2 [- %s -]" (X)
String DemoString3 "My String 3 [= %s =]" (X)
String DemoString4 "My String 4 [+++ %s +++]" (X)
String DemoString5 "My String 5" (X)
String DemoString6 "My String 6 []" (X)
String DemoString7 "My String 7" (X)
Switch DemoSwitch "Demo Switch [%s]" <switch> (DemoSwitchGroup) [Control, Light] { matter="OnOffLight" [label="Lampe sur l\'étagère"] }
Number:Temperature DemoTemperature "Setpoint [%.1f °C]" <temperature> (C) [Setpoint, Temperature]
String test { commandDescription="" [options="0=value 0,1,2=Value 2"], stateDescription="" [options="0=Valeur 0,1=Valeur 1,2", pattern="%s"] }
Number test2 "Aujourd\'hui" <none> [Energy, Measurement]
Number:Pressure test_0_1 "Label Test" <if:noto-v1:cityscape-at-dusk> (DemoSwitchGroup, C) [Sensor] { commandDescription=" " [options="0=Valeur 0,1=Valeur 1"], ga="Lock" [inverted=true], unit="bar" }
Number:Pressure test_0_2 "Label , Test = 1" <if:noto-v1:cityscape-at-dusk> (DemoSwitchGroup, C) [Sensor] { commandDescription=" " [options="0=Valeur 0,1=Valeur 1"], ga="Lock" [inverted=true], unit="bar" }
String Donnees_Astro_de_Lune_Evenement_Periode "Événement Période" [Point] { channel="astro:moon:e2015c6f37:rise#event" [profile="system:trigger-event-string"] }
DateTime Donnees_Astro_de_Lune_Heure_Fin "Heure Fin [%1$td/%1$tm/%1$tY %1$tR]" [Point] { channel="astro:moon:e2015c6f37:rise#end" [profile="system:timestamp-offset", offset=30.0], channel="astro:moon:e2015c6f37:rise#start", autoupdate="false" }
DateTime Lune_Heure_Debut "Heure Début [%1$td/%1$tm/%1$tY %1$tR]" [Point] { channel="astro:moon:e2015c6f37:rise#start" }
Color MagicColor { channel="magic:color-light:magicColor:color" }
Dimmer MagicDimmer { channel="magic:dimmable-light:magicDimmer:brightness" }
Switch MagicOnOff { channel="magic:onoff-light:magicOnOff:switch" }

@lolodomo lolodomo force-pushed the generate_dsl branch 2 times, most recently from cff0a29 to c3d70dc Compare January 25, 2025 13:38
@lolodomo lolodomo marked this pull request as ready for review January 25, 2025 13:41
@lolodomo
Copy link
Contributor Author

@kaikreuzer and @openhab/core-maintainers : for your information, the PR is now ready for review.

@lolodomo
Copy link
Contributor Author

Go back to draft as I discovered a bug.

@lolodomo lolodomo marked this pull request as draft January 25, 2025 23:03
@lolodomo lolodomo marked this pull request as ready for review January 26, 2025 10:27
@lolodomo
Copy link
Contributor Author

Problem with items sorting is solved. So ready again.

Related to openhab#4509

Added REST APIs:
- GET /inbox/{thingUID}/filesyntax to generate file syntax for the thing associated to the discovery result
- GET /items/filesyntax to generate file syntax for all items
- GET /items/{itemname}/filesyntax to generate file syntax for an item
- GET /things/filesyntax to generate file syntax for all things
- GET /things/{thingUID}/filesyntax to generate file syntax for a thing

All these APIs have a parameter named "format" to request a particular output format. Of course, a syntax generator should be available for this format.
Only "DSL" format is provided by this PR as this is currently our unique supported format for items and things in config files.
So this parameter is set to "DSL" by default.
In the future, new formats could be added and they will be automatically supported by these APIs.

The API GET /things/filesyntax has another parameter named "preferPresentationAsTree" allowing to choose between a flat display or a display as a tree.
Its default value is true for a display of things as tree.

Signed-off-by: Laurent Garnier <[email protected]>
Each API has a parameter named "hideDefaultParameters" to hide or show the configuration parameters having the default value. They are hidden by default.

Signed-off-by: Laurent Garnier <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant