Skip to content

Commit

Permalink
Generate valid tags in thing-description-1.0.0.xsd
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
  • Loading branch information
jimtng committed Mar 1, 2025
1 parent 7bdfc2b commit a20460d
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 1 deletion.
41 changes: 41 additions & 0 deletions bundles/org.openhab.core.semantics/model/generateTagClasses.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
@Grab('com.xlson.groovycsv:groovycsv:1.1')
import static com.xlson.groovycsv.CsvParser.parseCsv
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING
import java.nio.file.Files
import java.nio.file.Paths
import java.time.Year
Expand Down Expand Up @@ -53,6 +54,7 @@ labelsFile.close()

createDefaultSemanticTags(tagSets)
createDefaultProviderFile(tagSets)
updateThingDescriptionXsd()

println "\n\nTagSets:"
for (String tagSet : tagSets) {
Expand Down Expand Up @@ -177,6 +179,45 @@ public class DefaultSemanticTagProvider implements SemanticTagProvider {
file.close()
}

def updateThingDescriptionXsd() {
def xsdPath = baseDir.resolveSibling("org.openhab.core.thing/schema/thing/thing-description-1.0.0.xsd")
def tempPath = xsdPath.resolveSibling("thing-description.xsd.tmp")
def xsdFile = new File(xsdPath.toString()).text
def tempFile = new FileWriter(tempPath.toString())
def tagSection = ""
def beginEquipment = "<!-- Begin Allowed Semantic Equipment Tag Values -->"
def beginProperty = "<!-- Begin Allowed Semantic Property Tag Values -->"
def beginPoint = "<!-- Begin Allowed Semantic Point Tag Values -->"
def endTag = "<!-- End Allowed "
def doNotEdit = "\t\t\t<!-- DO NOT EDIT THIS LIST - Generated by generateTagClasses.groovy -->"
xsdFile.eachLine { sourceLine, lineNumber ->
if (tagSection && !sourceLine.contains(endTag)) {
return
} else {
tempFile.write(sourceLine + "\n")

if (sourceLine.contains(endTag)) {
tagSection = ""
} else if (sourceLine.contains(beginEquipment)) {
tagSection = "Equipment"
} else if (sourceLine.contains(beginPoint)) {
tagSection = "Point"
} else if (sourceLine.contains(beginProperty)) {
tagSection = "Property"
}

if (tagSection) {
tempFile.write(doNotEdit + "\n")
for (tag in tagsByType[tagSection]) {
tempFile.write("""\t\t\t<xs:enumeration value="${tag.Tag}"/>\n""")
}
}
}
}
tempFile.close()
Files.move(tempPath, xsdPath, REPLACE_EXISTING)
}

def header() {
def headerPath = baseDir.resolve("../../licenses/epl-2.0/header.txt")
def year = String.valueOf(Year.now().getValue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<xs:element name="label" type="xs:string"/>
<xs:element name="description" type="xs:string" minOccurs="0"/>
<xs:element name="category" type="xs:string" minOccurs="0"/>
<xs:element name="semantic-equipment-tag" type="thing-description:semanticEquipmentTag" minOccurs="0"/>
<xs:choice minOccurs="0">
<xs:element name="channels" type="thing-description:channels"/>
<xs:element name="channel-groups" type="thing-description:channelGroups"/>
Expand Down Expand Up @@ -215,7 +216,7 @@

<xs:complexType name="tags">
<xs:sequence>
<xs:element name="tag" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
<xs:element name="tag" type="thing-description:semanticPropertyOrPointTag" minOccurs="1" maxOccurs="2"/>
</xs:sequence>
</xs:complexType>

Expand Down Expand Up @@ -269,4 +270,116 @@
</xs:extension>
</xs:simpleContent>
</xs:complexType>


<xs:simpleType name="semanticEquipmentTag">
<xs:restriction base="xs:string">
<!-- Begin Allowed Semantic Equipment Tag Values -->
<!-- DO NOT EDIT THIS LIST - Generated by generateTagClasses.groovy -->
<xs:enumeration value="AlarmSystem"/>
<xs:enumeration value="Battery"/>
<xs:enumeration value="Blinds"/>
<xs:enumeration value="Boiler"/>
<xs:enumeration value="Camera"/>
<xs:enumeration value="Car"/>
<xs:enumeration value="CleaningRobot"/>
<xs:enumeration value="Door"/>
<xs:enumeration value="BackDoor"/>
<xs:enumeration value="CellarDoor"/>
<xs:enumeration value="FrontDoor"/>
<xs:enumeration value="GarageDoor"/>
<xs:enumeration value="Gate"/>
<xs:enumeration value="InnerDoor"/>
<xs:enumeration value="SideDoor"/>
<xs:enumeration value="Doorbell"/>
<xs:enumeration value="Fan"/>
<xs:enumeration value="CeilingFan"/>
<xs:enumeration value="KitchenHood"/>
<xs:enumeration value="HVAC"/>
<xs:enumeration value="Inverter"/>
<xs:enumeration value="LawnMower"/>
<xs:enumeration value="Lightbulb"/>
<xs:enumeration value="LightStripe"/>
<xs:enumeration value="Lock"/>
<xs:enumeration value="NetworkAppliance"/>
<xs:enumeration value="PowerOutlet"/>
<xs:enumeration value="Projector"/>
<xs:enumeration value="Pump"/>
<xs:enumeration value="RadiatorControl"/>
<xs:enumeration value="Receiver"/>
<xs:enumeration value="RemoteControl"/>
<xs:enumeration value="Screen"/>
<xs:enumeration value="Television"/>
<xs:enumeration value="Sensor"/>
<xs:enumeration value="MotionDetector"/>
<xs:enumeration value="SmokeDetector"/>
<xs:enumeration value="Siren"/>
<xs:enumeration value="Smartphone"/>
<xs:enumeration value="Speaker"/>
<xs:enumeration value="Valve"/>
<xs:enumeration value="VoiceAssistant"/>
<xs:enumeration value="WallSwitch"/>
<xs:enumeration value="WebService"/>
<xs:enumeration value="WeatherService"/>
<xs:enumeration value="WhiteGood"/>
<xs:enumeration value="Dishwasher"/>
<xs:enumeration value="Dryer"/>
<xs:enumeration value="Freezer"/>
<xs:enumeration value="Oven"/>
<xs:enumeration value="Refrigerator"/>
<xs:enumeration value="WashingMachine"/>
<xs:enumeration value="Window"/>
<!-- End Allowed Semantic Equipment Tag Values -->
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="semanticPropertyOrPointTag">
<xs:restriction base="xs:string">
<!-- Begin Allowed Semantic Property Tag Values -->
<!-- DO NOT EDIT THIS LIST - Generated by generateTagClasses.groovy -->
<xs:enumeration value="Temperature"/>
<xs:enumeration value="Light"/>
<xs:enumeration value="ColorTemperature"/>
<xs:enumeration value="Humidity"/>
<xs:enumeration value="Presence"/>
<xs:enumeration value="Pressure"/>
<xs:enumeration value="Smoke"/>
<xs:enumeration value="Noise"/>
<xs:enumeration value="Rain"/>
<xs:enumeration value="Wind"/>
<xs:enumeration value="Water"/>
<xs:enumeration value="CO2"/>
<xs:enumeration value="CO"/>
<xs:enumeration value="Energy"/>
<xs:enumeration value="Power"/>
<xs:enumeration value="Voltage"/>
<xs:enumeration value="Current"/>
<xs:enumeration value="Frequency"/>
<xs:enumeration value="Gas"/>
<xs:enumeration value="SoundVolume"/>
<xs:enumeration value="Oil"/>
<xs:enumeration value="Duration"/>
<xs:enumeration value="Level"/>
<xs:enumeration value="Opening"/>
<xs:enumeration value="Timestamp"/>
<xs:enumeration value="Ultraviolet"/>
<xs:enumeration value="Vibration"/>
<!-- End Allowed Property Tag Values -->

<!-- Begin Allowed Semantic Point Tag Values -->
<!-- DO NOT EDIT THIS LIST - Generated by generateTagClasses.groovy -->
<xs:enumeration value="Alarm"/>
<xs:enumeration value="Control"/>
<xs:enumeration value="Switch"/>
<xs:enumeration value="Measurement"/>
<xs:enumeration value="Setpoint"/>
<xs:enumeration value="Status"/>
<xs:enumeration value="LowBattery"/>
<xs:enumeration value="OpenLevel"/>
<xs:enumeration value="OpenState"/>
<xs:enumeration value="Tampered"/>
<xs:enumeration value="Tilt"/>
<!-- End Allowed Point Tag Values -->
</xs:restriction>
</xs:simpleType>
</xs:schema>

0 comments on commit a20460d

Please sign in to comment.