Skip to content

Comments

[shelly] Inline I18N texts#20084

Merged
lsiepel merged 7 commits intoopenhab:mainfrom
jlaur:shelly-inline-i18n-texts
Jan 17, 2026
Merged

[shelly] Inline I18N texts#20084
lsiepel merged 7 commits intoopenhab:mainfrom
jlaur:shelly-inline-i18n-texts

Conversation

@jlaur
Copy link
Contributor

@jlaur jlaur commented Jan 16, 2026

Follow-up to #19586 (comment)

Please see individual commits for the steps taken. I don't know if there's already a tool for it, but I quite quickly got decent results from an AI-generated script for the "inlining" commit (and detecting the wrong keys for the first commit) - see below.

Also fixes:

  • Some @text/ references were invalid (pointing to non-existing I18N keys).
  • Some texts were wrongly escaped: &T should not appear in shelly.properties, only in XML.
  • The text for channel-type.shelly.motionActive.description was lost in Fix documentation, grammar, and spelling in bindings Q-S #19586.
  • Typos: "Threshold" was misspelled as "Treshold".
from pathlib import Path
from lxml import etree

def load_properties(path):
    props = {}
    with open(path, encoding="utf-8") as f:
        for line in f:
            line = line.strip()
            if not line or line.startswith("#"):
                continue
            key, _, value = line.partition("=")
            props[key.strip()] = value.strip()
    return props

BASE_DIR = Path("bundles/org.openhab.binding.shelly")

XML_DIR = BASE_DIR / "src/main/resources/OH-INF"
PROPERTIES_FILE = BASE_DIR / "src/main/resources/OH-INF/i18n/shelly.properties"

props = load_properties(PROPERTIES_FILE)

parser = etree.XMLParser(
    remove_blank_text=False,
    resolve_entities=False,
    strip_cdata=False
)

def extract_key(text):
    return text.removeprefix("@text/")

for xml_file in XML_DIR.rglob("*.xml"):
    tree = etree.parse(str(xml_file), parser)
    root = tree.getroot()
    modified = False

    for elem in root.iter():
        if elem.text:
            text = elem.text.strip()
            if text.startswith("@text/"):
                key = extract_key(text)
                if key in props:
                    elem.text = props[key]
                    modified = True
                else:
                    print(f"[WARN] Missing key '{key}' in {xml_file}")

    if modified:
        tree.write(
            str(xml_file),
            encoding="UTF-8",
            xml_declaration=True,
            pretty_print=False
        )
        print(f"[UPDATED] {xml_file}")

jlaur added 4 commits January 16, 2026 22:08
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request inlines I18N text references from the properties file directly into XML configuration files for the Shelly binding. The changes replace @text/ reference patterns with the actual text values from shelly.properties, making the XML files self-contained and eliminating the need for external text lookups.

Changes:

  • Inlined all I18N text references in thing definition XML files (device descriptions, labels, channel types)
  • Inlined I18N references in configuration XML files (parameter labels and descriptions)
  • Reorganized and expanded the shelly.properties file to include all previously referenced keys
  • Applied automated script to perform text replacements consistently across multiple files

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
unknown.xml Inlined device and configuration descriptions for unknown/protected devices
shellyGen2_sensor.xml Inlined descriptions for Gen2 sensor devices
shellyGen2_relay.xml Inlined descriptions and labels for Gen2 relay devices with extensive channel groups
shellyGen2_lights.xml Inlined descriptions for Gen2 LED controllers
shellyGen1_sensor.xml Inlined extensive channel type definitions and state options for Gen1 sensors
shellyGen1_relay.xml Inlined channel types and state options for Gen1 relay devices
shellyGen1_lights.xml Inlined light control descriptions and color effect options
shellyBlu.xml Inlined descriptions for Bluetooth device types
device.xml Inlined device status channel types and alarm options
configblu.xml Inlined configuration parameter labels/descriptions for BLU devices
config2.xml Inlined configuration parameters for Gen2 devices
config.xml Inlined configuration parameters for Gen1 devices
addon.xml Inlined addon configuration descriptions
shelly.properties Reorganized with new sections and added all previously referenced keys

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the commits reflecting the steps taken is very review friendly, thanks for doing it thisway.

As this was mainly script drivven, I did not review and investigate every single line, but did like 20 tests and no errors are found. I'm confident this is another step forward in getting this binding to a stable situation.

Copilot did some suggestions that should be fixed, otherwise LGTM

jlaur added 3 commits January 17, 2026 15:00
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
@jlaur jlaur force-pushed the shelly-inline-i18n-texts branch from 92a4f93 to ca6e2df Compare January 17, 2026 14:11
@jlaur
Copy link
Contributor Author

jlaur commented Jan 17, 2026

Regarding the "treshold" typo found by Copilot: It also appears in DTO's:

@SerializedName("dark_treshold")
public Integer darkTreshold; // Illumination definition for "dark" in lux
@SerializedName("twilight_treshold")
public Integer twiLightTreshold; // Illumination definition for "twilight" in lux

@SerializedName("report_thr")
public Double reportTreshold; // only for type analog

The last one doesn't matter, but for the first two, the question is: Does the Shelly API have the same typo, or are these thresholds broken in the binding?

FYI @markus7017

@jlaur
Copy link
Contributor Author

jlaur commented Jan 17, 2026

Does the Shelly API have the same typo, or are these thresholds broken in the binding?

It doesn't appear so from documentation, but I don't have any Gen 1 devices to verify if implementation is according to the documentation: https://shelly-api-docs.shelly.cloud/gen1/#shelly-motion-settings

Attribute Type Description
dark_threshold number Illumination level threshold for dark condition.
twilight_threshold number Illumination level threshold for twilight condition.

EDIT: Fixed in #20087

@lsiepel lsiepel merged commit 04d54f7 into openhab:main Jan 17, 2026
2 checks passed
@lsiepel lsiepel added this to the 5.2 milestone Jan 17, 2026
@jlaur jlaur deleted the shelly-inline-i18n-texts branch January 17, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants