Changes to the Tradfri Binding to discover and use Groups #3799
Conversation
…onal Remotes added to empty ones)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your first contribution! Pretty cool to have native group support.
I left a few comments inside the code - mainly thoughts on whether it is possible to reduce some code duplications.
May I also ask you to sign a contributor license agreement at the Eclipse Foundation and include a "Signed-Off" line in your commit message(s)? (See also our Conventions for Pull Requests).
Unfortunately this is necessary once in order to meet the intellectual property requirements. Rest assured, the next PR is gonna be much easier once this is in place.
<description>A group of Tradfri lamps</description> | ||
|
||
<channels> | ||
<channel id="group_state" typeId="group_state"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do groups really only have an on/off feature, or could we rather reuse the existing brightness channel here? I noticed the return value also includes the "5851" (aka DIMMER) field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll test this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's write-only. Don't know if we should include the brightness channel if it behaves like this.
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage()); | ||
return; | ||
} | ||
devices.client.setEndpoint(endPoint); | ||
|
||
// setup GROUPS scanner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this more or less duplicates the code from above, could you please factor out the common parts into a separate method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
public void startScan() { | ||
if (endPoint != null) { | ||
deviceClient.get(new TradfriCoapHandler(this)); | ||
public class MyCoapCallback implements CoapCallback { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about naming it TradfriCoapCallback
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
private TradfriCoapClient client; | ||
private String gatewayURI; | ||
|
||
MyCoapCallback() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is empty, there is no need to implement it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* @author Kai Kreuzer - Initial contribution | ||
* @author Mario Smit - Group Handler added | ||
*/ | ||
public class TradfriGroupHandler extends BaseThingHandler implements CoapCallback { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is quite a lot of common code in TradfriLightHandler
and TradfriGroupHandler
, wouldn`t it make sense to inherit from each other or introduce a common abstract base class which both inherit from? I'm a bit concerned that all this copied code will be hard to be maintained consistently.
@@ -109,5 +129,11 @@ | |||
<description>Allows to control the color temperature of light.</description> | |||
<category>ColorLight</category> | |||
</channel-type> | |||
|
|||
|
|||
<channel-type id="group_state"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are constellations which don't expose a dimmer (5851) but only an ON/OFF (5850) so that this is really needed, I would suggest keeping it group-agnostic, i.e. name it switch
and remove all the references to groups from label & description, so that it can be used also directly in case they ever decide to offer a non-dimmable lamp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would advocate against this.
Currently Groups are a collection of lamps, a remote and/or a IR switch. And currently not all info of the group is exposed thought the gateway.
We don't know what devices Ikea will launch in the future but I heard rumours about mains-switches and colour bulbs. And hopefully they will also correct the problem of directly listening to the remote device instead of checking the group status.
I am sure this will change the behaviour of Groups extending their current switch behaviour. Remotes will become Switches and Dimmers exposed through the GW.
@@ -69,6 +69,26 @@ | |||
</parameter> | |||
</config-description> | |||
</thing-type> | |||
<thing-type id="group"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do groups really differ significantly from lamps (apart from their URL & ID, of course)? Or could they rather be considered as a single lamp? What I want to say with it: Do we really need a dedicated thing-type for them? (And this really is meant to be an open question)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi sjka,
I noticed different behaviours (which I will retest) from groups vs lights. In a group with 1 light the remote switches on the group and light within (which changes the brightness). If the brightness of the light is changed I don't see the group brightness changing. Maybe group brightness is only a write only variable. I will check and come back to this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed. Group brightness is a write-only variable. Setting it causes all lights to update it's brightness. After this it stays at this value even though we set all lights at another brightness value.
Don't know if we should include it if it has such strange behaviour. What do you think?
/** | ||
* This class is a Java wrapper for the raw JSON data about the group state. | ||
*/ | ||
private static class GroupData { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here again, my feeling from just looking at the code is that TradfriLightHandler.LightData
could be reused or at least should be made reusable.
@@ -56,6 +58,9 @@ protected ThingHandler createHandler(Thing thing) { | |||
return handler; | |||
} else if (SUPPORTED_LIGHT_TYPES_UIDS.contains(thingTypeUID)) { | |||
return new TradfriLightHandler(thing); | |||
} else if (thingTypeUID.equals(THING_TYPE_GROUP)) { | |||
// TODO: Construct Group Handler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left-over //TODO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Good points. Looks like I have work to do ;-). I'll follow up on you as
soon as I complete it.
…On 5 July 2017 at 16:49:27, Simon Kaufmann ***@***.***) wrote:
***@***.**** requested changes on this pull request.
Thanks a lot for your first contribution! Pretty cool to have native group
support.
I left a few comments inside the code - mainly thoughts on whether it is
possible to reduce some code duplications.
May I also ask you to sign a contributor license agreement at the Eclipse
Foundation and include a "Signed-Off" line in your commit message(s)? (See
also our Conventions for Pull Requests
<https://www.eclipse.org/smarthome/documentation/community/contributing.html#conventions-for-pull-requests>
).
Unfortunately this is necessary once in order to meet the intellectual
property requirements. Rest assured, the next PR is gonna be much easier
once this is in place.
------------------------------
In
extensions/binding/org.eclipse.smarthome.binding.tradfri/ESH-INF/thing/thing-types.xml
<#3799 (comment)>:
> @@ -69,6 +69,26 @@
</parameter>
</config-description>
</thing-type>
+ <thing-type id="group">
+ <supported-bridge-type-refs>
+ <bridge-type-ref id="gateway"/>
+ </supported-bridge-type-refs>
+
+ <label>Tradfri Group</label>
+ <description>A group of Tradfri lamps</description>
+
+ <channels>
+ <channel id="group_state" typeId="group_state"/>
do groups really only have an on/off feature, or could we rather reuse the
existing brightness channel here? I noticed the return value also includes
the "5851" (aka DIMMER) field.
------------------------------
In
extensions/binding/org.eclipse.smarthome.binding.tradfri/src/main/java/org/eclipse/smarthome/binding/tradfri/handler/TradfriGatewayHandler.java
<#3799 (comment)>:
> updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
return;
}
+ devices.client.setEndpoint(endPoint);
+
+ // setup GROUPS scanner
As this more or less duplicates the code from above, could you please
factor out the common parts into a separate method?
------------------------------
In
extensions/binding/org.eclipse.smarthome.binding.tradfri/src/main/java/org/eclipse/smarthome/binding/tradfri/handler/TradfriGatewayHandler.java
<#3799 (comment)>:
> @@ -125,74 +146,83 @@ public void dispose() {
super.dispose();
}
- /**
- * Does a request to the gateway to list all available devices/services.
- * The response is received and processed by the method ***@***.*** onUpdate(JsonElement data)}.
- */
- public void startScan() {
- if (endPoint != null) {
- deviceClient.get(new TradfriCoapHandler(this));
+ public class MyCoapCallback implements CoapCallback {
How about naming it TradfriCoapCallback?
------------------------------
In
extensions/binding/org.eclipse.smarthome.binding.tradfri/src/main/java/org/eclipse/smarthome/binding/tradfri/handler/TradfriGatewayHandler.java
<#3799 (comment)>:
> @@ -125,74 +146,83 @@ public void dispose() {
super.dispose();
}
- /**
- * Does a request to the gateway to list all available devices/services.
- * The response is received and processed by the method ***@***.*** onUpdate(JsonElement data)}.
- */
- public void startScan() {
- if (endPoint != null) {
- deviceClient.get(new TradfriCoapHandler(this));
+ public class MyCoapCallback implements CoapCallback {
+ private TradfriCoapClient client;
+ private String gatewayURI;
+
+ MyCoapCallback() {
As this is empty, there is no need to implement it.
------------------------------
In
extensions/binding/org.eclipse.smarthome.binding.tradfri/src/main/java/org/eclipse/smarthome/binding/tradfri/handler/TradfriGroupHandler.java
<#3799 (comment)>:
> +import org.eclipse.smarthome.core.types.RefreshType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonSyntaxException;
+
+/**
+ * The ***@***.*** TradfriGroupHandler} is responsible for handling commands for
+ * individual lights.
+ *
+ * @author Kai Kreuzer - Initial contribution
+ * @author Mario Smit - Group Handler added
+ */
+public class TradfriGroupHandler extends BaseThingHandler implements CoapCallback {
As there is quite a lot of common code in TradfriLightHandler and
TradfriGroupHandler, wouldn`t it make sense to inherit from each other or
introduce a common abstract base class which both inherit from? I'm a bit
concerned that all this copied code will be hard to be maintained
consistently.
------------------------------
In
extensions/binding/org.eclipse.smarthome.binding.tradfri/ESH-INF/thing/thing-types.xml
<#3799 (comment)>:
> @@ -109,5 +129,11 @@
<description>Allows to control the color temperature of light.</description>
<category>ColorLight</category>
</channel-type>
-
+
+ <channel-type id="group_state">
If there are constellations which don't expose a dimmer (5851) but only an
ON/OFF (5850) so that this is really needed, I would suggest keeping it
group-agnostic, i.e. name it switch and remove all the references to
groups from label & description, so that it can be used also directly in
case they ever decide to offer a non-dimmable lamp.
------------------------------
In
extensions/binding/org.eclipse.smarthome.binding.tradfri/ESH-INF/thing/thing-types.xml
<#3799 (comment)>:
> @@ -69,6 +69,26 @@
</parameter>
</config-description>
</thing-type>
+ <thing-type id="group">
Do groups really differ significantly from lamps (apart from their URL &
ID, of course)? Or could they rather be considered as a single lamp? What I
want to say with it: Do we really need a dedicated thing-type for them?
(And this really is meant to be an open question)
------------------------------
In
extensions/binding/org.eclipse.smarthome.binding.tradfri/src/main/java/org/eclipse/smarthome/binding/tradfri/handler/TradfriGroupHandler.java
<#3799 (comment)>:
> + logger.error("Unknown channel UID {}", channelUID);
+ }
+ }
+
+ private void handleGroupStateCommand(Command command) {
+ if (command instanceof OnOffType) {
+ setState(((OnOffType) command));
+ } else {
+ logger.debug("Cannot handle command {} for channel {}", command, CHANNEL_GROUP_STATE);
+ }
+ }
+
+ /**
+ * This class is a Java wrapper for the raw JSON data about the group state.
+ */
+ private static class GroupData {
Here again, my feeling from just looking at the code is that
TradfriLightHandler.LightData could be reused or at least should be made
reusable.
------------------------------
In
extensions/binding/org.eclipse.smarthome.binding.tradfri/src/main/java/org/eclipse/smarthome/binding/tradfri/internal/TradfriHandlerFactory.java
<#3799 (comment)>:
> @@ -56,6 +58,9 @@ protected ThingHandler createHandler(Thing thing) {
return handler;
} else if (SUPPORTED_LIGHT_TYPES_UIDS.contains(thingTypeUID)) {
return new TradfriLightHandler(thing);
+ } else if (thingTypeUID.equals(THING_TYPE_GROUP)) {
+ // TODO: Construct Group Handler
left-over //TODO
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3799 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEwvKLTk05-YCswJO4magmUyEfy_gZH2ks5sK6J3gaJpZM4ONqS4>
.
|
Signed-off-by: mario.smit.nl@gmail.com
Removing my veto so others can take over reviewing.
Would you mind rebasing your branch please? With the latest merge, this PR became unreadable because it does not only show your changes, but ~14k lines of others. |
I am currently enjoying my holidays. Please bear with me for another 1,5
weeks. I will take care of this asap.
On 30 July 2017 at 19:57:34, Simon Kaufmann (notifications@github.com) wrote:
Would you mind rebasing your branch please? With the latest merge, this PR
became unreadable because it does not only show your changes, but ~14k
lines of others.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3799 (comment)>,
or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AEwvKKTi2vrMOWbDyJwgPREst25n7qrjks5sTMQOgaJpZM4ONqS4>
.
|
While you are changing your commit history anyway, could you please also add a proper "Signed-of-by" statement to them? For this you also need to sign the Eclipse contribution agreement. |
Signed-off-by: Mario Smit <mario.smit.nl@gmail.com>
Have merged with the latest changes of 'master'. I have signed the Eclipse contribution agreement and added the signed-of-by statement. Please check if all is well and pull in the change please. |
Just tried your build and switching groups on/off works very well. Is it possible to detect motion sensors in this way though? Tried it with one but seems that it doesnt change the group state :-( |
Hi Mike,
I don’t have a motion sensor myself but I suspect that the Ikea gateway is
not emitting messages from this device (just like the remote) other then
the battery status. What I did is with the Tradfri App on my phone is
create a Group of lights (which may be empty) and bind the remote to this.
From that moment onward you can listen to the (empty) group status updates
with my updated binding and know what state the remote is in.
Maybe you can do the same with your motion sensor. Bind it to an (empty)
group with the App and then listen to the Group events with my updated
binding. This way you always know the status of your motion sensor which is
where you’re after. Right?
Let me know if it works. If not I need to buy a motion sensor myself to see
what the GW is emitting and update the binding to listen to those.
Best,
Mario
On 17 August 2017 at 22:32:41, Mike (notifications@github.com) wrote:
Just tried your build and switching groups on/off works very well. Is it
possible to detect motion sensors in this way though? Tried it with one but
seems that it doesnt change the group state :-(
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#3799 (comment)>,
or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AEwvKEGgwnU1WUd6Mw4ZxTkV6eClO4vYks5sZKNogaJpZM4ONqS4>
.
|
Hey Mario, |
Yes I think you’re right. I can research this further if I get a motion
sensor myself. With the binding in debug mode I can then better check the
log and step through the code to see if we can somehow add the motion
sensor to the binding. I’ll update you if I find something out.
On 18 August 2017 at 12:56:39, Mike (notifications@github.com) wrote:
Hey Mario,
that is exactly what I tried, but I get no group status update this way.
Tried a group with a sensor and lamps, only with sensor etc.
I have no remote though and cannot test if its working with it. But I can
turn off/on the bulbs that are are in a group with the group switch. So
basically it should work.
Maybe its just like the dimmer option on the remote.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#3799 (comment)>,
or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AEwvKG4-x5ftG3A13b7xeIatDURkHxN5ks5sZW3mgaJpZM4ONqS4>
.
|
People looking to try my changes, pending PR, can find them here: https://github.com/S0urceror/tradfri-jars Place the files in the addons folder. Groups (and lights) should automatically appear in the Inbox of Paper UI |
Any news here ? |
Hi Mike,
I am still waiting for someone to pick up my PR. A couple of weeks ago I
performed all the requested things like merging it with the latest head,
etc. But nothing happened.
What’s the best way to approach this? Should I close this PR and open a new
one?
Best,
Mario
On 29 August 2017 at 09:00:19, Mike (notifications@github.com) wrote:
Any news here ?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#3799 (comment)>,
or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AEwvKIMU_FbA1H6Ds6lr_FZIolnKee3Bks5sc7cBgaJpZM4ONqS4>
.
|
good question :-) I'm new to this, too What i noticed, when I last build the binding is, that the test failed, because of some kind of wrong number of types or sth lilke that. Maybe thats a problem (Mostly i disable the tests) ? Ah, and is it possible to use newer californium versions etc ? Wonder if they maybe make less problems with the connection to the gateway |
Apologies for the delay!
No, please don't! That's just add to the chaos we are fighting here... The Travis PR build detected a test failure:
I'd suggest that you fix that one first. In addition, as you can see in the failed "IP validation", there are some commits not properly signed-off or having a wrong committer entry. Please fix those - I'd suggest by properly rebasing your branch instead of merging the master into it. We will have a look as quickly as possible. |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/tradfri-remote-support/34695/3 |
Hey @S0urceror |
In summer I made it ready to be integrated but somehow it was not picked up by the maintainers. Now it is again behind the current development tree. I’ll try with a new PR soon after I merge it with the current tree.
From: Holger Reichert <notifications@github.com>
Reply-To: eclipse/smarthome <reply@reply.github.com>
Date: Monday, October 2, 2017 at 1:38 PM
To: eclipse/smarthome <smarthome@noreply.github.com>
Cc: S0urceror <mario.smit.nl@gmail.com>, Mention <mention@noreply.github.com>
Subject: Re: [eclipse/smarthome] Changes to the Tradfri Binding to discover and use Groups (#3799)
Hey @S0urceror
do you work on this any further?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Your PR was not in a mergable state, see comment #3799 (comment) |
@S0urceror isn't it possibly to rebase your work to the current master? Your work is great as well and I can't wait to get it merged into the master branch. |
I'm eagerly awaiting the native group support, too! Just my 2 cents, what do you guys think? And @S0urceror If you need help with something, you can always drop me a mail. |
Yes that’s what I will do soon and raise a new PR to get it included.
Groeten,
Mario
…On 6 October 2017 at 21:34:22, Christoph Weitkamp ***@***.***) wrote:
@S0urceror <https://github.com/s0urceror> isn't it possibly to rebase
your work to the current master?
Your work is great as well and I can't wait to get it merged into the
master branch.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3799 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEwvKGusyhtWQ8ajjGyrBUAvsEWRZtMqks5spoC-gaJpZM4ONqS4>
.
|
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/ikea-tradfri-gateway/26135/135 |
@S0urceror may I come back to you and ask if you like to contribute your implementation for group support based on the refactored code again? |
Hi @cweitkamp, Of course I can do that. Do you consider the current release stable to reinclude? |
Yes, I do. Let me know if you need any help. |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/ikea-tradfri-gateway/26135/181 |
I have updated the Tradfri Gateway binding so that it also correctly identifies groups (IPSO: 15004) of lamps bound to a remote. With the update I made they appear in the OpenHab Inbox as new Things. You can bind these to a Switch item.
Now it is easy to switch all lamps within a group on or off. Also it is possible to make a rule that executes when you select On/Off in the remote. Enabling to use the Ikea remotes for other purposes in OpenHAB as well.