Rest api

It might sound silly but, if you have a binding,

  1. How do you know the itemname and since the urls are the same how do you distinguish the two
    [POST] /items/{itemname} -------------------------------------sends a command to an item
    [GET] /items/{itemname]---------------------------------------- gets a single item

  2. How do you know the thingUID since a handler is created for each dscovered thing I am right.
    [POST] /inbox/{thingUID}/approve -----------------------------Approves the discovery result by adding the thing to the registry.

Added openhab2 tag to the post so hopefully the right people will notice.

For 1) the difference is the request type but in both cases you need to know the item name you want to send the command to or get the information about.

If you send a correctly formatted POST request to /items/{itemname} it will send a command to {itemname} but if you send a GET request to /items/{itemname} it will retrieve information about {itemname}.

For your second point, assuming the discovery has occurred you can check your inbox in Paper UI to find the thingUID. Alternatively you could send a GET request to /inbox/ to see a list of things awaiting approval.

  1. does that mean the thingUID is generated by the system
  2. how do I know the itemname
  1. A ThingUID consists of the binding, thing type and unique identifier for that Thing.

So either the binding will have some logic to generate the unique identifier part of the ThingUID if it can be auto-discovered. Or you manually create the Thing from the Paper UI and you manually specify the identifier part of the ThingUID.

  1. openHAB can either automatically create an item from a channel, with it’s name being the binding, thing type, identifier and channel name all concatenated with underscore Or you can manually create an item yourself and link the channel and item, in which case you already know the item name.

Because all I see in most bindings is getThing().getUID(), I don’t actually see them creating the ideas like you are explaining to me.

Can you provide a specific example of your problem or question?

this snapshot is from the KeContactP20Handler. This particular binding doesnt have a discovery service but what I dont get is how does the handler know which thing to send a command to.

and this one is from the wemo binding, which has a discovery service implemented and creates a thinUID as you said earlier but from the handler they used getThing().getUID() as I said but how do you know which of the discovered things you are sending the command to.

the whole thing is a bit confusing to me. I might be a bit annoying with my numerous questions. itemname and thingUID.
creation of the thingUID I get it from the wemo discovery serivces. For example from the wemo binding how will you know the itemname.

And finally is UID created for a thing each time it is discovered even if it has already being discovered.

Each Handler instance is created to handle one Thing instance. The constructor for the Handler class expects the Thing as a parameter so it will always know what Thing it will be sending commands to.

If you’re looking examples of creating a ThingUID then look at the Wemo Discovery Service class, you should see a few lines like:

uid = new ThingUID(WEMO_SOCKET_TYPE_UID, wemoUDN);

If you’re thinking about writing an OH2 binding, forget about items. The OH2 framework is different and the new bindings have no knowledge or understanding of items.

It is OH2 binding.Yeah I get the Handler part very well.
And I now understand the wemo discovery service. So it means that when a handler is created for a thing the getThing().getUID() gets the ThingUID from registry