Transform MAP files for a binding

I’m currently developing the Sure Petcare binding and I’d like to ship a number of maps for the MAP transform bundle, so that user can use human readable text in sitemaps etc.

Is there a way to package the maps, so that they get installed with the bundle? If not, where is the correct place to put them, so that it is a easy as possible for the end user to install them?

Many thanks,
Rene

As far as I know there is no way to install those maps. However the pattern in general to implement such a feature is to add them channel state options and as localized text in the binding and make them part of the binding itself. For the other language you add the options text to the language file. If people still want to have another language they can create a map file that transforms the number or English word of the options into their own language. To give an example of how that works for a channel. Here is an example of your genderIdType it could look like this:

	<channel-type id="genderIdType">
		<item-type>String</item-type>   <--- Needs to be String
		<label>Gender Id</label>
		<description>The pet's gender id</description>
		<state readOnly="true">
			<options>
				<option value="0">Female</option>
				<option value="1">Male</option>
				<option value="unknown">Unknown</option>
			</options>
		</state>
	</channel-type>

or

				<option value="Female">Female</option>
				<option value="Male">Male</option>
				<option value="Unknown">Unknown</option>
1 Like

this is exactly i was playing with…

I found this in https://www.openhab.org/docs/developer/utils/i18n.html

and for now i have done it with:

things.xml

	<channel-type id="genderIdType">
		<item-type>String</item-type>
		<label>Gender Id</label>
		<description>The pet's gender id</description>
		<state readOnly="true" pattern="%s">
			<options>
				<option value="0">@text/genderFemale</option>
				<option value="1">@text/genderMale</option>
				<option value="">@text/genderUnknown</option>
			</options>
		</state>
	</channel-type>

surepetcare_en.properties

genderFemale = Female
genderMale = Male
genderUnknown = Unknown

i will push the related PR later this day. @scherer

Hi Hilbrand

Thanks for the response. That certainly works for read-only channels, but I’m not sure about writable channels. I assume the i18n translation only works one-way.

I can see 2 options:
Option 1. Expose 2 channels, a read-only string-type one called “Gender” which uses the options and i18n files to show a textual representation and a writable number channel called “Gender Id”, which shows the gender as a code and can be updated by sending a DecimalType command.

Option 2. Expose only one string-type channel called “Gender” which uses the options and i18n files to show a textual representation when displayed, but the handler expects a StringCommand with a code in the payload (i.e. “1”) to update the thing’s gender.

IMHO the first option looks cleaner, but requires 2 channels for basically the same information. What do you think? Is there a recommended design pattern?

Cheers,
Rene

It works both ways. In the sense that when it’s a writable channel it will be displayed in the UI as a selection box. The selection box will show the translated texts. The handler gets the StringCommand with the content from the option value attribute. Basically this is what you describe as option 2.

1 Like