Code Monkey home page Code Monkey logo

openhab-alignment-tool's Introduction



Build Status Visual Studio Marketplace Installs Visual Studio Marketplace Version Visual Studio Marketplace Version

This extension adds support for formatting and indenting openHAB files like *.items, *.sitemap, etc. At the moment only *.items and *.sitemap files are supported. They can be formatted in a column channel-column or multiline style. In the future the other file types and other format-types will be added. Feel free to add feature-requests on the github repository.

If you've found the extension helpful or useful, then please consider throwing a coffee my way to help support my work. As i am a student and would like to invest more time and effort in this project this would really help me.

Features

The tool is available as a standard Visual-Studio-Code formatter as it uses the original vsc formatter API. You can force to formatting with right-clicking the document and clicking Format Document... or Format Selection.... If you have enabled the function in the vsc settings it even can Format-On-Save.

Item-Formatting:

Column-Style:

formatting item gif

Column-Channel-Style:

formatting item gif

Multiline-Style:

formatting item gif

Sitemap-Formatting:

formatting sitemap gif

Special Comment Tags

With the new version (v2) of this extension there are introduced new Special Comment Tags you can use in your `.items file code, to change the way the extension is formatting your code.

New Group Tag

// #OHNG#

With this tag you can start a new formatting group for an item section. The tracking of the longest item parts is resetted and will be set to the longest item part in the new group. The following image shows an example of a formatting group:

new formatting group

New Formatting Style

// #OHFS#%FORMATTING_STYLE%#OHFS#

With this tag you can change the formatting of the following item definitions from the default formatting style selected in the VSC settings to a new style inserted in %FORMATTING_STYLE%. So just replace %FORMATTING_STYLE% with Column, ChannelColumn or Multiline. The following image shows an example of a Multiline formatted part in a ChannelColumn document:

new formatting style

Limitations

The formatting is available for the following openhab file types:

  • .items (Fully functional)
  • .sitemap (Under development)
  • .things (Under development)

Extension Settings

New Line After Item

With this option you can choose if you want to have a new line inserted after each item. If there is already a single empty line after an item this settings is ignored.

"oh-alignment-tool.newLineAfterItem": true

Preserve Whitespace

Whitespaces (tabs or spaces) in front of items get preserved and won't be deleted.

"oh-alignment-tool.preserveWhitespace": true

Multiline Indent Amount

With this option you can control the amount of indent when using the Multiline format.

"oh-alignment-tool.multilineIndentAmount": 28

Format Style

The format style option gives you two styles between you can choose.

  • Column
  • ChannelColumn
  • Multiline

The Column style formats the files in a column-way. Each item will be on one line and the item parts are separated in columns. With the ChannelColumn style only the channel part of an item gets formatted into multiple lines. The Multiline format prints every part of an item in a new line and indents the different parts.

Known Issues

See Github Issues file for the details.

Release Notes

See CHANGELOG.md file for the details.


For More Information

Enjoy!

openhab-alignment-tool's People

Contributors

cwempe avatar dependabot[bot] avatar maxbec avatar mhilbush avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

openhab-alignment-tool's Issues

Update README for new features in v2

Just a reminder to update the README.md to let new users know there are new features implemented (#OHNG#, #OHFS#) in v2. 😉
But maybe you want to wait untill they are tested properly.

I would also suggest small screenshots to show what the different format styles mean.

combination of space and comma should be irrelevant in bindingconfig

Example code:

Switch	A	"B"	<c>	(D)	{channel="e", alexa="Speaker.muted"}
Switch	A	"B"	<c>	(D)	{channel="e" ,alexa="Speaker.muted"}
Switch	A	"B"	<c>	(D)	{channel="e" , alexa="Speaker.muted"}

Result:

image

Only the first combination ,_ produces the expected result.
The other two _, and _,_ do not produce a new line.

Version: 2.0.7

Extension adds spaces to alexa-channel

I started to use the alexa skill recently and just noticed an odd thing while configuring a light:
When adding the alexa channels to the item there are no spaces allowed between the channels themselves. Let me show you:

This works:

Color Sprachassistent_Licht_Bett "Bett" {alexa="PowerController.powerState,BrightnessController.brightness,ColorController.color" [category="LIGHT"]}

This doesn't:

Color Sprachassistent_Licht_Bett "Bett" {alexa="PowerController.powerState, BrightnessController.brightness,ColorController.color" [category="LIGHT"]}

When using the second configuration alexa can't control the brightness of the item.

The problem appears when using the vscode extension and letting it format the items since the extension adds the one little space before BrightnessController. The extension always adds a space in the alexa="" string after the first channel no matter the order of the channels.

Expected Behavior

The extension should not correct any alexa="" string

Steps to Reproduce (for Bugs)

  1. My settings:
    image
  2. Try the item definitions as shown above

Context

Currently I can't save my items file with vscode since vscode auto formats the file before saving and adding the problematic space. So I have to save the file in vscode and edit it afterwards in another editor to remove the space

Your Environment

  • Extension Version: v2.1.4
  • VSCode Version: 1.55.1 (system setup)
  • Electron: 11.3.0
  • Chrome: 87.0.4280.141
  • Node.js: 12.18.3
  • V8: 8.7.220.31-electron.0
  • OS: Windows_NT x64 10.0.19042

Setting to use space for indentation/alignment

Is your feature request related to a problem? Please describe.
The indentation column alignment is done by inserting tabs.
For document portability across different editors, I prefer spaces instead.

Describe the solution you'd like
A settings option for choosing space or tabs.

User defined formatting-groups

I think the new feature reformat at save is not usable when you want to reformat parts of your file different that the rest. (like #7)

So I propose a feature where you can define "formatting groups" inside your files.

This is some example code:

Switch	Awtrix01AppstateTime	"Time"	<switch>			{mqtt=">[mosquitto:awtrix/basics:command:ON:{\"enable\"\\: \"Time\"}],
															       >[mosquitto:awtrix/basics:command:OFF:{\"disable\"\\: \"Time\"}]"}

Switch	HTPC_Online											{channel="network:pingdevice:htpc:online"}
Switch	PC_Online											{channel="network:pingdevice:pc:online"}
Switch	AVR_Online											{channel="network:pingdevice:avr:online"}
Switch	Beamer_Online										{channel="network:pingdevice:epson:online"}

Reformatting the whole document results in this:

image

It would look better if the lower group of items would be reformated seperately from the first line/group.
Maybe this could be implemented with some kind of special comment that gets recognized by the plugin and treats all following lines as a new group until the next special group-comment is detected.

image

Incorrect reformatting with escaped quotes in bindingconfig

I just found another special case where the reformatting dod not work correctly.

Example code:

String	Awtrix01timer		"Timer"			<clock>	{mqtt=">[mosquitto:awtrix/basics:command:*:{\"timer\"\\:\"${command}\",\"soundfile\"\\:1,\"count\"\\:10,\"text\"\\:\"Test123\"}]", autoupdate="false"}

Ouput when reformatting the document:

image

Expected:
The mqtt-bindingconfig hould be only one line.

image

I understand this is a very special use case and I wish I dod not have to excape all those characters. 😄

So I respect if this will not get fixed.

Another workaournd could be to implement a special comment like:

// ##openHAB-Alignment-Tool_skipNextLines: 2##

Lines should be stripped

Items without bindingconfig get tabs added at the end of the line.

image

I think these should be stripped at the end of the reformation process.

Version: 2.0.0-beta.2

[beta2] sitemap alignment not working at all

I am not sure if I should report an issue with the current beta2.

I suspect this worked in the stable version. But I never tried it.

When I try to format my sitemaps, the only thing that happens is that lines with Color or Switch are moved all the way to the left with no ident.
The rest of the document stays the same.

I guess the beta is still a work in progress and @maxbec focused on the items files for now. 😅

square brackets in bindingconfig ruin ChannelClumn

Example code:

Number:Temperature	Temp_Bad_Temp	"Bad [%.2f %unit%]"	<temperature>	{mqtt="<[mosquitto:misensor/Bad:state:JSONPATH($.temperature)]", alexa="TemperatureSensor.temperature" [scale="Celsius"], expire="2h,state=UNDEF"}
Number:Temperature	Temp_Bad_Temp	"Bad [%.2f %unit%]"	<temperature>	{mqtt="<[mosquitto:misensor/Bad:state:JSONPATH($.temperature)]", alexa="TemperatureSensor.temperature", expire="2h,state=UNDEF"}

Result:

image

The expire bindingconfig should be in a new line in bith cases.
It seems the plugin gets confused by the [scale="Celsius"] part.

Format Style: ChannelColumn
Version: 2.0.7

Parts of the line are duplicated during alignment

Expected Behavior

This line should be aligned inaccordance to the other lines:

Switch Abus_Mode "Alarmanlage [%s]" <siren> (G_jdbc,Group_HabPanel_Dashboard) {http=">[ON:GET:http://192.168.68.36:8060/setMode.cgi?Mode=Set{Authorization=Basic xxx}] >[OFF:GET:http://192.168.68.36:8060/setMode.cgi?Mode=Unset{Authorization=Basic xxx}]"}

Current Behavior

This is the result where parts of the code is duplicated starting with //192 ...

Switch Abus_Mode "Alarmanlage [%s]" <siren> (G_jdbc,Group_HabPanel_Dashboard) {http=">[ON:GET:http://192.168.68.36:8060/setMode.cgi?Mode=Set{Authorization=Basic xxx} //192.168.68.36:8060/setMode.cgi?Mode=Set{Authorization=Basic xxx}] >[OFF:GET:http://192.168.68.36:8060/setMode.cgi?Mode=Unset{Authorization=Basic xxx}]"}

Possible Solution

Is there an issue interpreting this part?

] >[OFF:GET:http:

Steps to Reproduce (for Bugs)

Context

Your Environment

openhabian v1.5
openhab 2.5.3-1 stable
Raspberry Pi 3B+

wrong commant in settings

I think the comments for the different format styles are wrong.

The comment for Column seems to be assigned to ChannelColumn whereas the commant for the later is missing at all.

image

image

do not format on save for sitemap, yet

I am not sure if the sitemap feature is even usable at the moment.

But as long as it is in development I would recommend sitemap files should not formatOnSave.
Even If the user has set this option (to use for items files)

Maybe even deactivate the sitemap feature and let it be enabled via a setting.

How about something like:

 "oh-alignment-tool.enableForFiletype": "items,"
 "oh-alignment-tool.enableForFiletype": "items,sitemap"
 "oh-alignment-tool.enableForFiletype": "items,sitemap, rules"

But I do not know if there are any consequences with a feature like this if you want to enable a new file type by default, but the users might already have an old setting set to items only.

Groups get unnecessary brackets

I think Groups are not handled correctly.

Example:

Group gTest

Result:

Group  gTest  {}

The brackets are inserted by the addon and I guess they will produce an error in openHAB. (did not test this)

v2.1.4

Comments at the end of line of item definition causes weird duplication of item

openHAB-Alignment-Tool 2.0.6

After the #OHNG# issue having been fixed so quickly I was going to clean up more of my long .items files and came accross this strange formatting bug for some lines where I have comments at the end of the lines of the itme definitions.

These comments are ancient, still from the OH1 MiLight binding and not really applicable and required any longer and I will remove them now in my clean up effort, but still wanted to report them as similar issues might affect others.

Format these lines with a Column format

Switch	Milight_Bedroom_Globe_1_Switch				"Bedroom Globe"			<bulb>			(G_Bedroom_Lights)              {channel="milight:rgbLed:XXXXXXXXXXXX:1:ledcolor"}					//Switch for all white bulbs on bridge2
Dimmer	Milight_Bedroom_Globe_1_Dimmer				"Dimmer [%d]"			<bulb_dimmer>                                    {channel="milight:rgbLed:XXXXXXXXXXXX:1:ledbrightness"}    			//Dimmer changing brightness for RGBW bulb1 on bridge2 with 27 dimming steps
Color	Milight_Bedroom_Globe_1_Colour_Bright       "Colour"									
Switch	Milight_Bedroom_Globe_1_WhiteMode			"White Mode"			<bulb>											{channel="milight:rgbLed:XXXXXXXXXXXX:1:ledwhitemode"}        		//Activate the WhiteMode
Switch	Milight_Bedroom_Globe_1_NightMode			"Night Mode"			<bulb>											{channel="milight:rgbLed:XXXXXXXXXXXX:1:lednightmode"}	       		//Activate the NightMode

The result I get is

Switch	Milight_Bedroom_Globe_1_Switch			"Bedroom Globe"	<bulb>				(G_Bedroom_Lights)			{channel="milight:rgbLed:XXXXXXXXXXXX:1:ledcolor"}					//Switch for all white bulbs on bridge2
Dimmer	Milight_Bedroom_Globe_1_Dimmer			"Dimmer [%d]"	<bulb_dimmer>									Dimmer	Milight_Bedroom_Globe_1_Dimmer				"Dimmer [%d]"			<bulb_dimmer>                                    {channel="milight:rgbLed:XXXXXXXXXXXX:1:ledbrightness"}
Color	Milight_Bedroom_Globe_1_Colour_Bright	"Colour"
Switch	Milight_Bedroom_Globe_1_WhiteMode		"White Mode"	<bulb>											{channel="milight:rgbLed:XXXXXXXXXXXX:1:ledwhitemode"}        		//Activate the WhiteMode
Switch	Milight_Bedroom_Globe_1_NightMode		"Night Mode"	<bulb>											Switch	Milight_Bedroom_Globe_1_NightMode			"Night Mode"			<bulb>											{channel="milight:rgbLed:XXXXXXXXXXXX:1:lednightmode"}

With the Dimmer and NightMode Switch items being strangely duplicated within the line itself and some comments being deleted, others not.

Once the comments at the end of the lines are removed everything works fine.

add multiline for bindingconfig only

Just discovered this nice extension.

But I am missing one feature.

Format item configurations like this:

image

Basically everything is in one line.
But the bindingconfig (in {}) should be broken into multiple lines to not exceed the screen.

ChannelColumn not working correctly anymore

There seems to be a regression with ChannelColumn in v2.1.6.

In v2.0.0 each Binding parameter (like mqtt's < and >) where moved to new lines.
See #31.

But it does not anymore for this simple example:

Number  aaa  "bbb"  {mqtt=">[mosquitto:ddd:command:*:default],<[mosquitto:ddd:state:default]"}

Channel Formatting Bug

I created a test-items with the following content. (Examples from above)

Number:Temperature Temp_Bad_Temp "Bad [%.2f %unit%]" {mqtt="<[mosquitto:misensor/Bad:state:JSONPATH($.temperature)]", alexa="TemperatureSensor.temperature" [scale="Celsius"], expire="2h,state=UNDEF"}
Number:Temperature Temp_Bad_Temp "Bad [%.2f %unit%]" {mqtt="<[mosquitto:misensor/Bad:state:JSONPATH($.temperature)]", alexa="TemperatureSensor.temperature", expire="2h,state=UNDEF"}

String A "B" (D) {autoupdate="false", alexa="ThermostatController.thermostatMode" [OFF="OFF", HEAT="ON", AUTO="AUTO"]}
After formatting it looks like this:

image

When I delete :Temperature it looks like nothing is destroyed. But the channels are not listed in new columns either.

image

I think it looks worse than before. 😢
Tested with oh-alignment-tool-2.0.9-beta.1.vsix.

Make ChannelColumn more readable

I finally found the time to test the new ChannelColumn feature I requested (#12 ).

I know my example screeshot did not show this in my previous request, but I think it would be better if the Channel commands would be lined relative to each other instead of to the Channel name.

Current behavior:

image

This would look nicer and be better to read:

image

Error with config option "Insert new line after item"

I tested on this *.items file. Also my last item got duplicated.

I did some manual formatting to look like this:

// Preset button
String	wifiled_presets					"LED Presets"							<light>				(gWifiledPresets)																												

String	wifiled_presets_livingroom		"LED Presets"							<light>				(gWifiledPresets)																												

// Kitchen LED Top
Switch	wifiled1_power					"Kitchen LED Top"						<light>				(gKitchen, gKitchenLights, gAllLightAutoTurnOff, gAllLight, gKitchenLedLight, gKitchenLedControl)								{channel="mqtt:topic:25e0dc66:1"}

Color	wifiled1_color					"LED Top Color"												(gKitchenLedControl, gKitchenLedColor)																							{channel="mqtt:topic:25e0dc66:3"}

Dimmer	wifiled1_white					"Kitchen Top LED"											(gKitchenLedControl, gKitchenLedWhite)																			[ "Lighting" ]	{channel="mqtt:topic:25e0dc66:4"}

Number	wifiled1_rssi					"Kitchen LED Top RSSI: [%d%%]"			<controls_round>	(gKitchenLedControl)																											{channel="mqtt:topic:25e0dc66:2"}

Dimmer	wifiled1_dimmer					"Kitchen LED Top Dimmer"																																									{channel="mqtt:topic:25e0dc66:5"}

// Kitchen LED Bottom
Switch	wifiled2_power					"Kitchen LED Bottom"					<light>				(gKitchen, gKitchenLights, gAllLightAutoTurnOff, gAllLight, gKitchenLedLight, gKitchenLedControl)								{channel="mqtt:topic:a0809db4:1"}

Color	wifiled2_color					"LED Bottom Color"											(gKitchenLedControl, gKitchenLedColor)																							{channel="mqtt:topic:a0809db4:3"}

Dimmer	wifiled2_white					"Kitchen Bottom LED"										(gKitchenLedControl, gKitchenLedWhite)																			[ "Lighting" ]	{channel="mqtt:topic:a0809db4:4"}

Dimmer	wifiled2_dimmer					"Kitchen Bottom LED Dimmer"																																									{channel="mqtt:topic:a0809db4:5"}

Number	wifiled2_rssi					"Kitchen LED Bottom RSSI: [%d%%]"		<controls_round>	(gKitchenLedControl)																											{channel="mqtt:topic:a0809db4:2"}

// Living Room Shelf LED
Switch	wifiled_livingroom				"Living Room Shelf LED"					<light>				(gLivingRoom, gLivingRoomLights, gAllLightAutoTurnOff, gAllLight, gLivingRoomLedLight, gLivingRoomLedControl)					{channel="mqtt:topic:livingroomShelfLed:1"}

Dimmer	wifiled_livingroom_white		"Living Room Shelf LED"					<light>				(gLivingRoomLedControl, gLivingRoomLedWhite)																	[ "Lighting" ]	{channel="mqtt:topic:livingroomShelfLed:3"}

Number	wifiled_livingroom_rssi			"Living Room Shelf LED RSSI: [%d%%]"	<controls_round>	(gLivingRoomLedControl)																											{channel="mqtt:topic:livingroomShelfLed:2"}

// Living Room Bottom LED
Switch	wifiled_livingroom_strip_power	"Living Room Bottom Strip LED"			<light>				(gLivingRoom, gLivingRoomLights, gAllLightAutoTurnOff, gAllLight, gLivingRoomLedLight, gLivingRoomLedControl)					{channel="mqtt:topic:a9b1ff48:1"}

Color	wifiled_livingroom_strip_color	"LED Bottom Color"											(gLivingRoomLedControl, gLivingRoomLedColor)																					{channel="mqtt:topic:a9b1ff48:3"}

Dimmer	wifiled_livingroom_strip_white	"Living Room Bottom LED"									(gLivingRoomLedControl, gLivingRoomLedWhite)																	[ "Lighting" ]	{channel="mqtt:topic:a9b1ff48:4"}

Dimmer	wifiled_livingroom_strip_dimmer	"Living Room Strip LED Dimmer"																																								{channel="mqtt:topic:a9b1ff48:5"}

Number	wifiled_livingroom_strip_rssi	"Living Room Strip RSSI: [%d%%]"		<controls_round>	(gLivingRoomLedControl)																											{channel="mqtt:topic:a9b1ff48:2"}

Switch	Morning_Led_Switch																																																			

If I rerun the formatting after changing some indentation, I get this. Look how every empty line became 2 empty line and the last item also got duplicated:

// Preset button
String	wifiled_presets					"LED Presets"							<light>				(gWifiledPresets)																												


String	wifiled_presets_livingroom		"LED Presets"							<light>				(gWifiledPresets)																												


// Kitchen LED Top
Switch	wifiled1_power					"Kitchen LED Top"						<light>				(gKitchen, gKitchenLights, gAllLightAutoTurnOff, gAllLight, gKitchenLedLight, gKitchenLedControl)								{channel="mqtt:topic:25e0dc66:1"}


Color	wifiled1_color					"LED Top Color"												(gKitchenLedControl, gKitchenLedColor)																							{channel="mqtt:topic:25e0dc66:3"}


Dimmer	wifiled1_white					"Kitchen Top LED"											(gKitchenLedControl, gKitchenLedWhite)																			[ "Lighting" ]	{channel="mqtt:topic:25e0dc66:4"}


Number	wifiled1_rssi					"Kitchen LED Top RSSI: [%d%%]"			<controls_round>	(gKitchenLedControl)																											{channel="mqtt:topic:25e0dc66:2"}


Dimmer	wifiled1_dimmer					"Kitchen LED Top Dimmer"																																									{channel="mqtt:topic:25e0dc66:5"}


// Kitchen LED Bottom
Switch	wifiled2_power					"Kitchen LED Bottom"					<light>				(gKitchen, gKitchenLights, gAllLightAutoTurnOff, gAllLight, gKitchenLedLight, gKitchenLedControl)								{channel="mqtt:topic:a0809db4:1"}


Color	wifiled2_color					"LED Bottom Color"											(gKitchenLedControl, gKitchenLedColor)																							{channel="mqtt:topic:a0809db4:3"}


Dimmer	wifiled2_white					"Kitchen Bottom LED"										(gKitchenLedControl, gKitchenLedWhite)																			[ "Lighting" ]	{channel="mqtt:topic:a0809db4:4"}


Dimmer	wifiled2_dimmer					"Kitchen Bottom LED Dimmer"																																									{channel="mqtt:topic:a0809db4:5"}


Number	wifiled2_rssi					"Kitchen LED Bottom RSSI: [%d%%]"		<controls_round>	(gKitchenLedControl)																											{channel="mqtt:topic:a0809db4:2"}


// Living Room Shelf LED
Switch	wifiled_livingroom				"Living Room Shelf LED"					<light>				(gLivingRoom, gLivingRoomLights, gAllLightAutoTurnOff, gAllLight, gLivingRoomLedLight, gLivingRoomLedControl)					{channel="mqtt:topic:livingroomShelfLed:1"}


Dimmer	wifiled_livingroom_white		"Living Room Shelf LED"					<light>				(gLivingRoomLedControl, gLivingRoomLedWhite)																	[ "Lighting" ]	{channel="mqtt:topic:livingroomShelfLed:3"}


Number	wifiled_livingroom_rssi			"Living Room Shelf LED RSSI: [%d%%]"	<controls_round>	(gLivingRoomLedControl)																											{channel="mqtt:topic:livingroomShelfLed:2"}


// Living Room Bottom LED
Switch	wifiled_livingroom_strip_power	"Living Room Bottom Strip LED"			<light>				(gLivingRoom, gLivingRoomLights, gAllLightAutoTurnOff, gAllLight, gLivingRoomLedLight, gLivingRoomLedControl)					{channel="mqtt:topic:a9b1ff48:1"}


Color	wifiled_livingroom_strip_color	"LED Bottom Color"											(gLivingRoomLedControl, gLivingRoomLedColor)																					{channel="mqtt:topic:a9b1ff48:3"}


Dimmer	wifiled_livingroom_strip_white	"Living Room Bottom LED"									(gLivingRoomLedControl, gLivingRoomLedWhite)																	[ "Lighting" ]	{channel="mqtt:topic:a9b1ff48:4"}


Dimmer	wifiled_livingroom_strip_dimmer	"Living Room Strip LED Dimmer"																																								{channel="mqtt:topic:a9b1ff48:5"}


Number	wifiled_livingroom_strip_rssi	"Living Room Strip RSSI: [%d%%]"		<controls_round>	(gLivingRoomLedControl)																											{channel="mqtt:topic:a9b1ff48:2"}
Switch	Morning_Led_Switch																																																			
Switch	Morning_Led_Switch

Extension name, and formatting multi-line files.

Just gave it a test. I actually was looking for a tool last night and came across the other one that formats as multi-line. So quite happy there is this column based one.

Unfortunately, I did run into some issues with your tool.

Firstly, it’s named exactly the same as the one from MarkHilbush. This caused the Command-Palette to not offer your one up for use. After disabling Mark’s one, it appeared in the Command-Palette, but the results weren’t what was expected.

Here is one of my item files before:

String                      JiPhone_BatteryStatus
                            "Battery Status [%s]"
                            <battery>
                            (iCloud_GroupJ)
                            {channel="icloud:device:myaccount:JiPhone7:batteryStatus"}

And here is what it looks like after using your tool:

StringJiPhone_BatteryStatus
                            "Battery Status [%s]"
                            <battery>
                            (iCloud_GroupJ)
                            {channel="icloud:device:myaccount:JiPhone7:batteryStatus"}

Ignore definition parts that are not present

I understand this plugin places at least one tab between each part of the item definition.

itemtype itemname "labeltext [stateformat]" <iconname> (group1, group2, ...) ["tag1", "tag2", ...] {bindingconfig}

But when you do not use some parts like (group) and [tag] you still get the extra tabs.

image

I think there should always be as few tabs as possible between the definition parts.

Here is the code to reproduce the behavior:

Switch	sLED_light		"LED 1"			<light>				{mqtt="<[mosquitto:homie/superledstrip/light/on:state:ON:true],
															       <[mosquitto:homie/superledstrip/light/on:state:OFF:false],
															       >[mosquitto:homie/superledstrip/light/on/set:command:ON:true],
															       >[mosquitto:homie/superledstrip/light/on/set:command:OFF:false]"}
Dimmer	sLED_brightness	"LED 1 [%d]"	<slider>			{mqtt="<[mosquitto:homie/superledstrip/light/brightness:state:default],
															       >[mosquitto:homie/superledstrip/light/brightness/set:command:*:default]"}

Version: 2.0.0-beta.2

Group state aggregation gets messed up by formatting

Dear developpers,
I experienced a somewhat severe bug as the use of group aggregation functions is a good practive within openhab.

Expected Behavior

The following group definition should be well aligned with others:
Group:Number:Temperature:AVG g_test_temp_tr "test label [%.1f °C]" <temperature> (testroom)

Current Behavior

However, the result is as follows:
Group:Number:Temperature Temperature
The aggregation main type "Number", the function name "AVG" and all following elements (group name, label, class, group association) are removed. Strangely, the sub type "Temperature" is duplicated and falsely used as group name.

Steps to Reproduce (for Bugs)

The provided example is enough to reproduce the bug (as only row in an .items file). If a group aggregation is used within a file with other item and group definitions, the same result can be observed. Other items' or groups' definitions in the same file are preserved and formatted correctly.

Context

General openHAB practice.

Your Environment

  • Version used:
    • vscode: V 1.52
    • openHAB (vscode extension) V 0.7.0
    • openHAB Alignment Tool V 2.0.8 (installed via vscode extension management)
  • No environment activated
  • Operating System and version: Windows 10 Pro V 2004

Bad formatting when an item starts with `_`

The following items:

Switch test1               "test 1"                                     (All)
Switch _test2              "_test 2"                                     (All)

align to:

Switch    test1    "test 1"    (All)SwitchSwitch _test2              "_test 2"                                     (All)

which is obviously wrong.

ChannelColumn not working correctly with additional bindingconfig

There seems to be an issue when I add an extra bindingconfig like autoupdate.

Example code

Switch	Awtrix01stopwatch	"Stopwatch"	<clock>			{mqtt=">[mosquitto:awtrix/basics:command:ON:{test123}], >[mosquitto:awtrix/basics:command:OFF:{test456}]", autoupdate="false"}
Switch	Awtrix01stopwatch	"Stopwatch"	<clock>			{mqtt=">[mosquitto:awtrix/basics:command:ON:{test123}], >[mosquitto:awtrix/basics:command:OFF:{test456}]"}

When reformatting the document I get this:

image

What I expect:

image

Version: 2.0.0-beta2

Format Document (Shift+Alt+F) does nothing

Expected Behavior

Clicking the right click menu item "Format Document" or alternatively pressing Shift+Alt+F should format the document.

Instead there is an additional Context menu entry "Reformat File" which seems redundant, because its functionality could be transferred to "Format Document", to enable other extensions to perform additional actions (e.g. on each save, my code is automatically formatted by executing "Format Document", which in this case does not work).

Current Behavior

Clicking the "Format Document" context menu entry does nothing.

Steps to Reproduce (for Bugs)

  1. Create a valid .stiemap file with working content
  2. Right-click -> Format Document or Format document with... openHAB

Your Environment

  • Version used: 1.3.12
  • Operating System: Windows 10

overwrite settings at document level

In addition to #29 it would be nice if you could overwrite the plugin settings for specific files.

Like:

image

image

The best solution would be if this feature could be used multiple times in a document.

image

Content of line gets partially duplicated in same line

Example code:

String OctoprintConnected "Connected [%s]" <network> (gOctoprint) { mqtt="<[mosquitto:octoPrint/mqtt:state:default]" } 
String OctoprintState	  "State [%s]"	   <office>  (gOctoprint) { mqtt="<[mosquitto:octoPrint/event/PrinterStateChanged:state:JSONPATH($.state_string)]" }

After reformatting document:

image

Version: 2.0.0-beta2

Reformat delets content when escaped characters are used

The extension seems to not do well when there are escaped characters.

Input:

Switch	Awtrix01AppstateTime            "Time"              <switch>	{ mqtt=">[mosquitto:awtrix/basics:command:ON:{\"enable\"\\: \"Time\"}],>[mosquitto:awtrix/basics:command:OFF:{\"disable\"\\: \"Time\"}], <[mosquitto:awtrix/appEnabled:state:ON:Time], <[mosquitto:awtrix/appDisabled:state:OFF:Time]"}

Output:

Switch	Awtrix01AppstateTime	"Time"	<switch>			{mqtt=">[mosquitto:awtrix/basics:command:ON:{\"enable\"\\: \"Time\"}

URL gets manipulated

I just found a bug where this plugin adds a space in a URL.

original line:

Number  A  "B [%d]"  {http="<[https://example.com/foobar/query?test,bla:600000:JSONPATH($.field)]"}

After formating there is a space before bla.

Number  A  "B [%d]"  {http="<[https://example.com/foobar/query?test, bla:600000:JSONPATH($.field)]"}

This breaks the URL of cause and results in errors.

Commented lines not formatting properly in sitemaps

Expected Behavior

When I use the new feature to reformat a sitemap, items that I have commented out should be formatted to match the indenting of the items adjacent to them.

Current Behavior

In 1.3.12, items that are commented out are split onto separate lines, leaving an empty comment and reactivating the items. It seems that the formatter is keying on the device type (e.g. "Switch") to determine when to create a new line.

Possible Solution

Perhaps it would be possible to have the reformatting completely ignore comments?

Steps to Reproduce (for Bugs)

This code:

// Switch item=Flag_Test label="Test Switch" icon="door"

Becomes this:

//
Switch item=Flag_Test label="Test
Switch" icon="door"

Context

I'm just testing this out of interest more than need.

Your Environment

I'm using the 1.3.12 version of the alignment tool. VSCode is up to date in Windows 10.

'Reformat Selection' reformats the whole file

When I select a fe lines in my .items and execute Reformat Selection the whole file is reformated.

Expected Behavior

I expect the command to only reformat the selected lines.

Current Behavior

All lines are refomated

Steps to Reproduce (for Bugs)

  1. open .items file
  2. select a few lines
  3. execute Reformat Selection
  4. see how all lines are reformated

Context

Eventually I will refomat the whole file, but the command should still do what it is named for. ;)

Your Environment

  • openhab 2.4.x
  • VScode 1.44.2
  • openHAB-Alignment-Tool 1.3.12
  • Windows 10

Semantic Model not supported?

I try to format my item file with the semantic model "extentions" coming with openhab .
It looks like they are currently not supported an will be filtered:

e.g.
before:

Group     lInnen             "01 Innenbereich"                   <ikInnen>                [Location]
Group     lKeller            "00 Keller"                        <ikKeller>         (lInnen)             [Location]
Group     lErdgeschoss       "01 Erdgeschoss"                        <ikErdgeschoss>         (lInnen)             [Location]
Group     lDachgeschoss      "02 Dachgeschoss"                        <iDachgeschoss>         (lInnen)             [Location]

after:

Group    lInnen           "01 Innenbereich"    <ikInnen>
Group    lKeller          "00 Keller"          <ikKeller>         (lInnen)
Group    lErdgeschoss     "01 Erdgeschoss"     <ikErdgeschoss>    (lInnen)
Group    lDachgeschoss    "02 Dachgeschoss"    <iDachgeschoss>    (lInnen)

Issue with escaped characters in item file

Found another bug.

This might be a tricky one, because it includes escaped characters.

Example:

String  AAA  "BBB"    {mqtt=">[mosquitto:ccc:command:open:{\"x\"\\: \"y\"}]"}

Result:

String  AAA  "BBB"  {mqtt=">[mosquitto:ccc:command:open:{\"}

And here is my real life example:

String  Therm_AZ_Preset  "AZ Preset"                 <thermostat>  (Thermostat)  {mqtt=">[mosquitto:zigbee2mqtt/Therm_AZ/set:command:schedule:{\"preset\"\\: \"schedule\"}],
                                                                                        >[mosquitto:zigbee2mqtt/Therm_AZ/set:command:manual:{\"preset\"\\: \"manual\"}],
                                                                                        >[mosquitto:zigbee2mqtt/Therm_AZ/set:command:boost:{\"preset\"\\: \"boost\"}],
                                                                                        >[mosquitto:zigbee2mqtt/Therm_AZ/set:command:complex:{\"preset\"\\: \"complex\"}],
                                                                                        >[mosquitto:zigbee2mqtt/Therm_AZ/set:command:comfort:{\"preset\"\\: \"comfort\"}],
                                                                                        >[mosquitto:zigbee2mqtt/Therm_AZ/set:command:eco:{\"preset\"\\: \"eco\"}],
                                                                                        <[mosquitto:zigbee2mqtt/Therm_AZ:state:JSONPATH($.preset)]"}

Addon version: 2.1.5

"Reformat File" inserts new lines on each run

Expected Behavior

Any additional click on "Reformat File" should produce the same result as the first click on it.

Current Behavior

Each click on context menu entry "Reformat File" inserts new empty lines between each existing line, stretching the whole code with empty lines.

Eyample: Starting point is the following code (.sitemap)

sitemap default label="My first sitemap"
 {
	// Syntax:
	// ElementType item=ItemName label="Description of the item shown on the webpage"
	Frame label="Testing"{
		Switch item=Presence_Brother_PT_P750W label="Description of the item shown on the webpage, here P750W"
		Default item=Chromecast_XE8005_Control icon=screen label="XE8005 Control"
	}
	Frame label="Working" {
		Slider item=Chromecast_XE8005_Volume icon=soundvolume label="XE8005 Volume"
	}
}

Second click on "Reformat File" produces the following output:

sitemap default label="My first sitemap"
 {

	// Syntax:

	// ElementType item=ItemName label="Description of the item shown on the webpage"

	Frame label="Testing"{

		Switch item=Presence_Brother_PT_P750W label="Description of the item shown on the webpage, here P750W"

		Default item=Chromecast_XE8005_Control icon=screen label="XE8005 Control"

	}

	Frame label="Working" {

		Slider item=Chromecast_XE8005_Volume icon=soundvolume label="XE8005 Volume"

	}

}

Third run produces:

sitemap default label="My first sitemap"
 {


	// Syntax:


	// ElementType item=ItemName label="Description of the item shown on the webpage"


	Frame label="Testing"{


		Switch item=Presence_Brother_PT_P750W label="Description of the item shown on the webpage, here P750W"


		Default item=Chromecast_XE8005_Control icon=screen label="XE8005 Control"


	}


	Frame label="Working" {


		Slider item=Chromecast_XE8005_Volume icon=soundvolume label="XE8005 Volume"


	}


}

And so on...

Possible Solution

Steps to Reproduce (for Bugs)

  1. Right Click -> Reformat File
  2. Right Click -> Reformat File (again)
    ...
    N. Right Click -> Reformat File (again)

Context

Your Environment

  • Version used: 1.3.12
  • Operating System: WIndows 10

Indent selection

Hi, it would be nice to be able to indent just the selection.

I have a bunch of groups with subgroups at the top of my items file and they don't indent nicely with the rest of the items.

I also don't like how it removes my line spacings between groupings of items. Lastly some item names are too long so I don't want the rest to be indented to accommodate the odd long ones.

In short, indenting just the selection will solve this.

Sitemap formatting not available

Problem

The extension doesn't show the option for formatting a sitemap
image

image

I enabled the beta features in the settings and restarted vs code. However this didn't help. Furthermore I tried reinstalling the extension, but no luck there either.
image

The tag for enabling the beta features is visible in the vscode settings file:

    "oh-alignment-tool.enableBetaFeatures": true,
    "[openhab]": {
        "editor.defaultFormatter": "max-beckenbauer.oh-alignment-tool"
    },

Am I missing something here?

Your Environment

  • Version used: OpenHAB v2.5-10, Extension v2.0.8, VSCode v152.1
  • Operating System: Win10

[beta3] "Format document" seems broken

Example code:

String A {e="f"}
String Z {u="t"}

"Format document" does nothing.
But selecting all and execute "Format selection" works.

I think "format document" is broken in beta.3.

custom define using tabs or spaces

Maybe this is already possible.

But I think I would like to have the option to use spaces between the items parts instead of tabs.

This is how it looks at the moment.

image

Right now there is at least one tab after each part wich can be as big as 1 (between "B" and <cc> ) or up to 4 spaces (between <cc> and (D)).

I think it would look better and more organized if the minimum distance between two parts could be defined by the user, if he wants to use spaces instead of tabs.

Like "minimum 2 spaces":
image

Or "minimum 1 space):

image

"minimum 3 spaces:

image

My vscod settings are set to use spaces.

image

But I understand if this would be difficult to implement.
And I do not NEED this.
It would be nice to have, though. 😉

btw: The openHAB documentation uses a single space between the elements in the examples.
But I would prefer two spaces.

Extension action declared as a formatter

Is your feature request related to a problem? Please describe.
Can't auto format or with default shortcut

Describe the solution you'd like
I'ld like my files to be formatted on save just like js, java, md...

Describe alternatives you've considered
If the extension action "extension.reformat-file" was declared as formatter, we won't need to call the action with Ctrl + Shift + P

Additional context
https://code.visualstudio.com/blogs/2016/11/15/formatters-best-practices

Include channel formatting

I would like to see that the channel part of an item ( the part between the {} at the end of the line) uses a standard formatting.

Currently I have item files that have some different formatting. Making this uniform by the allignment tool would be great!

Example:

String Item1 "Item 1" (group) { channel="channel1" }
String Item2 "Item 2" (group) {channel="channel2" }

Hope you see the difference: at Item2 the is a space missing after the bracket ({)
I would like that the formatting can fix that too so every line will be the same.

Misformatting on certain characters inside strings

Certain characters enclosed in "..." lead to misformatting and syntactical incorrect item-files.

Expected Behavior

The formatting should yield a working and syntactical correct item-file.

Current Behavior

On some "special characers" inside strings, the formatting fails to produce the correct syntax of an item file.

----before formatting-----
Contact Wetter_Aussentemperatur_Grenze2 "AT2 <20° [MAP(de.map):%s]" (Wetter) {knx="<3/1/15"}
----after formatting-----
Contact Wetter_Aussentemperatur_Grenze2 "AT2 <20° [MAP(de.map):%s]" <20° [MAP(de.map):%s]" <20° [MAP(de.map):%s]" {knx="<3/1/15"}

I suspect the less-than character "<" inside a string to fail the formatting.

Possible Solution

Improve special character handling.

Steps to Reproduce (for Bugs)

Format-Style "Column"

OHNG-Tag is interpreted to soon

Example code:

Switch	A	"B"	{channel="e"}
// #OHNG#
Switch	A	"B"	<c>	{channel="e"}

Result:
image

When I add a new line in front of the tag it works:

image

Version: 2.0.7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.