Skip to content

Commit

Permalink
Add support of cluster 0xfc01 for Legrand with Netatmo devices.
Browse files Browse the repository at this point in the history
Handles invisible/special characters with \u<xxxx> Unicode escape
notation.

Signed-off-by: Pierre Gaufillet <[email protected]>
  • Loading branch information
pgaufillet committed Feb 3, 2022
1 parent f4f919d commit 0d2f33e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private synchronized void readDiscoveryProperties() throws IOException {
continue;
}

newProperties.add(new RequiredProperty(discoveryElement[0].trim(), discoveryElement[1].trim()));
newProperties.add(new RequiredProperty(discoveryElement[0].trim(), unescape(discoveryElement[1].trim())));
}

if (newProperties.isEmpty()) {
Expand Down Expand Up @@ -172,4 +172,30 @@ public RequiredProperty(String name, String value) {
this.value = value;
}
}

/**
* Transforms \x&lt;nnnn&gt; occurrences into corresponding utf16 char.
*
* @param s String that shall be unescaped.
* @return UTF16 string
*/
private static final String unescape(String s) {
StringBuilder sb = new StringBuilder();
String[] segments = s.split("\\\\u");

sb.append(segments[0]);
for (int i = 1; i < segments.length; i++) {
try {
sb.appendCodePoint(Integer.valueOf(segments[i].substring(0, 4), 16)).append(segments[i].substring(4));
} catch (NumberFormatException nfe) {
throw new IllegalArgumentException("Unicode " + segments[i].substring(0, 4) + " cannot be parsed.",
nfe);
} catch (IndexOutOfBoundsException ioobe) {
throw new IllegalArgumentException(
"Unicode " + segments[i].substring(0, segments[i].length()) + " is too short.");
}
}

return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<thing:thing-descriptions bindingId="zigbee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">

<thing-type id="legrand_dimmer_without_neutral" listed="false">
<label>Legrand with Netatmo Dimmer</label>
<description>Legrand with Netatmo Dimmer without neutral</description>
<channels>
<channel id="switch_onoff" typeId="switch_onoff">
<properties>
<property name="zigbee_endpoint">1</property>
</properties>
</channel>
<channel id="switch_level" typeId="switch_level">
<label>Level Control</label>
<description></description>
<properties>
<property name="zigbee_endpoint">1</property>
</properties>
</channel>
</channels>

<config-description>
<parameter name="zigbee_macaddress" type="text" readOnly="true" required="true">
<label>MAC Address</label>
</parameter>

<parameter name="attribute_01_in_fc01_0001_10" type="boolean">
<label>Led in Dark</label>
<options>
<option value="false">Disabled</option>
<option value="true">Enabled</option>
</options>
<default>false</default>
</parameter>

<parameter name="attribute_01_in_fc01_0002_10" type="boolean">
<label>Led if On</label>
<options>
<option value="false">Disabled</option>
<option value="true">Enabled</option>
</options>
<default>false</default>
</parameter>
</config-description>

</thing-type>
</thing:thing-descriptions>
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ xiaomi_lumisensorwaterleak,modelId=lumi.sensor_wleak.aq1
xiaomi_lumisensormagnet,modelId=lumi.sensor_magnet
innr-rc-110,vendor=innr,modelId=RC 110
osram-switch-4x-eu,vendor=OSRAM,modelId=Switch 4x EU-LIGHTIFY
legrand_dimmer_without_neutral,vendor=\u001f Legrand,modelId=\u001f Dimmer switch w/o neutral

0 comments on commit 0d2f33e

Please sign in to comment.