Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Changes to the Tradfri Binding to discover and use Groups #3799

Closed
wants to merge 4 commits into from

Conversation

S0urceror
Copy link

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.

sjsf
sjsf previously requested changes Jul 5, 2017
Copy link
Contributor

@sjsf sjsf left a 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"/>
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

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

I'll test this.

Copy link
Author

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
Copy link
Contributor

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?

Copy link
Author

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 {
Copy link
Contributor

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?

Copy link
Author

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() {
Copy link
Contributor

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.

Copy link
Author

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 {
Copy link
Contributor

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">
Copy link
Contributor

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.

Copy link
Author

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">
Copy link
Contributor

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)

Copy link
Author

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.

Copy link
Author

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 {
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

left-over //TODO

Copy link
Author

Choose a reason for hiding this comment

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

done

@S0urceror
Copy link
Author

S0urceror commented Jul 5, 2017 via email

@sjsf sjsf dismissed their stale review July 30, 2017 17:56

Removing my veto so others can take over reviewing.

@sjsf
Copy link
Contributor

sjsf commented Jul 30, 2017

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.

@S0urceror
Copy link
Author

S0urceror commented Jul 30, 2017 via email

@triller-telekom
Copy link
Contributor

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>
@S0urceror
Copy link
Author

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.

@thelaoshi
Copy link

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 :-(

@S0urceror
Copy link
Author

S0urceror commented Aug 18, 2017 via email

@thelaoshi
Copy link

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.

@S0urceror
Copy link
Author

S0urceror commented Aug 21, 2017 via email

@S0urceror
Copy link
Author

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

@thelaoshi
Copy link

Any news here ?

@S0urceror
Copy link
Author

S0urceror commented Aug 29, 2017 via email

@thelaoshi
Copy link

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

@sjsf
Copy link
Contributor

sjsf commented Aug 29, 2017

Apologies for the delay!

Should I close this PR and open a new one?

No, please don't! That's just add to the chaos we are fighting here...

The Travis PR build detected a test failure:

correctSupportedTypes(org.eclipse.smarthome.binding.tradfri.discovery.TradfriDiscoveryServiceTest)  Time elapsed: 0.025 sec  <<< FAILURE!
java.lang.AssertionError: 
Expected: is <2>
     but: was <3>
	at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
	at org.junit.Assert.assertThat(Assert.java:865)
	at org.junit.Assert.assertThat(Assert.java:832)
	at org.eclipse.smarthome.binding.tradfri.discovery.TradfriDiscoveryServiceTest.correctSupportedTypes(TradfriDiscoveryServiceTest.java:84)

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.

@openhab-bot
Copy link
Contributor

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

@hreichert
Copy link
Contributor

Hey @S0urceror
do you work on this any further?

@S0urceror
Copy link
Author

S0urceror commented Oct 6, 2017 via email

@hreichert
Copy link
Contributor

Your PR was not in a mergable state, see comment #3799 (comment)

@cweitkamp
Copy link
Contributor

@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.

@hreichert
Copy link
Contributor

I'm eagerly awaiting the native group support, too!
But my fear is the following:
@S0urceror puts further effort into rebasing/merging, meanwhile #4373 gets merged (with big refactorings?); and then there are new, maybe even bigger, conflicts; and @S0urceror is getting (even more?) frustrated.
Also I think that the implementation of native group support is getting easier, after #4373 is in. So maybe it's better to wait for this PR.

Just my 2 cents, what do you guys think?

And @S0urceror If you need help with something, you can always drop me a mail.

@S0urceror
Copy link
Author

S0urceror commented Oct 6, 2017 via email

@openhab-bot
Copy link
Contributor

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

@cweitkamp
Copy link
Contributor

@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?

@S0urceror
Copy link
Author

S0urceror commented Nov 13, 2017

Hi @cweitkamp,

Of course I can do that. Do you consider the current release stable to reinclude?

@cweitkamp
Copy link
Contributor

Yes, I do. Let me know if you need any help.

@openhab-bot
Copy link
Contributor

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

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

Successfully merging this pull request may close these issues.

None yet

7 participants