Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add semantic equipment tag on things #4617

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

andrewfg
Copy link
Contributor

@andrewfg andrewfg commented Feb 23, 2025

The purpose of this PR is to add a semantic (equipment) tag to things so that the UI can use that tag for putting items that are bound to channels on such things in the semantic model.

Adds two things:

  1. Extends the XSD schema definition to add a semantic (equipment) tag on thing types. See also Add restrictions for semantic point/property tags on channels #4615
  2. Adds code to permeate this tag throughout OH core wherever it may be needed. Specifically in the classes, DTOs and (de)serializers for thing types and things.

See also #4616 #4619 #4622

Resolves #4614

Signed-off-by: Andrew Fiddian-Green [email protected]

Signed-off-by: Andrew Fiddian-Green <[email protected]>
@andrewfg andrewfg requested a review from a team as a code owner February 23, 2025 11:39
@andrewfg andrewfg marked this pull request as draft February 23, 2025 11:39
@andrewfg andrewfg changed the title XSD Add new definition for semantic tags on things XSD Add new definition for semantic tags on thing type definitions Feb 23, 2025
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-5-semantic-model-proposal/162526/96

@andrewfg andrewfg changed the title XSD Add new definition for semantic tags on thing type definitions XSD Add semantic tag on things Feb 23, 2025
Signed-off-by: Andrew Fiddian-Green <[email protected]>
@andrewfg andrewfg marked this pull request as ready for review February 23, 2025 16:24
@andrewfg andrewfg marked this pull request as draft February 24, 2025 07:56
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
@andrewfg
Copy link
Contributor Author

@mherwege can I kindly ask you to be a sparring partner for this PR? My goal is to allow developers to set a (proposed) semantic (equipment) tag in their thing type xml, and have this permeated through the thing type instances to the actual thing instances so that the UI can use that semantic (equipment) tag (as a hint) in creating a semantic model.

@mherwege
Copy link
Contributor

@mherwege can I kindly ask you to be a sparring partner for this PR? My goal is to allow developers to set a (proposed) semantic (equipment) tag in their thing type xml, and have this permeated through the thing type instances to the actual thing instances so that the UI can use that semantic (equipment) tag (as a hint) in creating a semantic model.

@andrewfg Sure. I like the idea as long as it does not then enforce anything on the item semantics. So I would think that it should be carried to the point of a having a tag on the thing, but then it should be up to the UI to pick this up as a suggested equipment semantic when creating the group item with its points (create model from thing).
As it should not be used on the thing directly, except when creating items, I am wondering what it should be called. Some day someone may think it carries meaning beyond a suggestion for an equipment group item, and may want to also show that in the UI...

@andrewfg
Copy link
Contributor Author

andrewfg commented Feb 24, 2025

Indeed. The tags in the ChannelType xml are hints for semantic “point” and semantic “property” tags which are intended for functional Item creation. And the single tag in the ThingType xml would be a hint for the semantic “equipment” tag intended for semantic GroupItem creation. The remaining “location” semantic tag is entirely user dependent and would not come from the xml.

PS we could even explicitly name it equipmentTag ..

Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
* @param semanticEquipmentTag semantic (equipment) tag
* @return the updated builder
*/
public DiscoveryResultBuilder withSemanticEquipmentTag(@Nullable String semanticEquipmentTag) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if it would be better to stay consistent and generic like e.g. here:

/**
* Adds a tag to the ChannelType
*
* @param tag Tag to be added to the ChannelType
* @return this Builder
*/
T withTag(String tag);
/**
* Sets the StateDescription for the ChannelType
*
* @param tags Collection of tags to be added to the ChannelType
* @return this Builder
*/
T withTags(Collection<String> tags);

so simply withTag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #4617 (comment) above.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am fine either way.

Copy link
Contributor Author

@andrewfg andrewfg Feb 25, 2025

Choose a reason for hiding this comment

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

@jlaur some background..

In ChannelType we have a tags element that currently allows an unlimited number of tag sub-elements, which have no XSD schema validation. So this allows developers to have an open ended number of strings having open ended meanings.

I think it is the wish of OH maintainers to restrict the number and the meaning of these tags. So there should be a maximum of two tag sub-elements. And strictly speaking one of those tag elements is a semantic point tag and the other is a semantic property tag. And the developer choices when entering such values shall be subject to stricter XSD schema validation in order to restrict the choice to only valid tags.

// as it is today (open ended number and meaning)
<tags>
    <tag>blah</tag>
    ..
    <tag>blah</tag>
</tags>

In #4615 we are trying to do this constraint and validation. However since the tag elements have the same name we cannot do it fully via the xml. We would need to change the schema to do that (see below) which would be a breaking change. So I am loth to go all the way in doing that. But nevertheless we are moving towards more strictness rather than less.

// as it should be (constrained number and meaning)
<tags>
    <semanticPropertyTag>XSD validated Property</semanticPropertyTag>
    <semanticPointTag>XSD validated Point</semanticPointTag>
</tags>

Now -- finally to get to the point -- as we are moving towards more strictness in the ChannelType tags (semantic property tag resp. semantic point tag), we should NOT be moving to introduce less strictness in ThingType.

Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
@andrewfg
Copy link
Contributor Author

andrewfg commented Feb 28, 2025

Ok. I have now tested this, and I think it is ready for review. See OH Rest API output below..

http://192.168.1.232:8080/rest/things?summary=true&staticDataOnly=true

[
  {
    "editable": true,
    "label": "Hue motion sensor 1",
    "bridgeUID": "hue:bridge-api2:001788fffe2157c7",
    "UID": "hue:device:001788fffe2157c7:70660557-692d-4d37-8b6b-e3ec63716a72",
    "thingTypeUID": "hue:device",
    "semanticEquipmentTag": "Sensor"
  },
  {
    "editable": true,
    "label": "Contact Sensor",
    "bridgeUID": "hue:bridge-api2:001788fffe2157c7",
    "UID": "hue:device:001788fffe2157c7:faac7940-a303-4e8e-9f06-075fffb7229c",
    "thingTypeUID": "hue:device",
    "semanticEquipmentTag": "AlarmSystem"
  },
  {
    "editable": true,
    "label": "Philips Hue (192.168.1.108)",
    "UID": "hue:bridge-api2:001788fffe2157c7",
    "thingTypeUID": "hue:bridge-api2",
    "semanticEquipmentTag": "NetworkDevice"
  },
  {
    "editable": true,
    "label": "Hue tap dial switch 1",
    "bridgeUID": "hue:bridge-api2:001788fffe2157c7",
    "UID": "hue:device:001788fffe2157c7:ebca68a4-9312-4d3b-86a9-59b5a4a6a988",
    "thingTypeUID": "hue:device",
    "semanticEquipmentTag": "WallSwitch"
  },
  {
    "editable": true,
    "label": "Conservatory Wallplate Switch",
    "bridgeUID": "hue:bridge-api2:001788fffe2157c7",
    "UID": "hue:device:001788fffe2157c7:a0509519-3ecb-47d0-9183-25db1e4ea2b2",
    "thingTypeUID": "hue:device",
    "semanticEquipmentTag": "WallSwitch"
  },
  {
    "editable": true,
    "label": "Office",
    "bridgeUID": "hue:bridge-api2:001788fffe2157c7",
    "UID": "hue:room:001788fffe2157c7:1166743f-fe3d-47d1-bd7d-b5bb378098cc",
    "thingTypeUID": "hue:room",
    "semanticEquipmentTag": "Lightbulb"
  },
  {
    "editable": true,
    "label": "Office Lamp",
    "bridgeUID": "hue:bridge-api2:001788fffe2157c7",
    "UID": "hue:device:001788fffe2157c7:24e7a04e-ad36-4192-961e-ca7f22103cbc",
    "thingTypeUID": "hue:device",
    "semanticEquipmentTag": "Lightbulb"
  }
]

Obviously it needs work now on the OH WebUI side in order to utilise this semanticEquipmentTag when creating the semantic model. => @mherwege :)

Notes:

@andrewfg andrewfg marked this pull request as ready for review February 28, 2025 12:32
@andrewfg andrewfg requested review from jlaur and mherwege February 28, 2025 12:32
@andrewfg
Copy link
Contributor Author

Ping @jimtng

Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
@andrewfg andrewfg changed the title XSD Add semantic tag on things Add semantic equipment tag on things Feb 28, 2025
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
@mherwege
Copy link
Contributor

mherwege commented Mar 4, 2025

Obviously it needs work now on the OH WebUI side in order to utilise this semanticEquipmentTag when creating the semantic model. => @mherwege :)

I don't think this is a very complex change in the UI. I can take care of it, but would prefer to finish the core code first. There are a lot of moving parts and dependencies here, and creating a core that has it all for testing a UI change against is a bit of a challenge. It will be easier to do when we get the core changes over the line first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add semantic equipment tag on things
5 participants