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

Generic buttons defined by attribute changes #346

Merged
merged 4 commits into from
Feb 8, 2019

Conversation

t-8ch
Copy link
Member

@t-8ch t-8ch commented Dec 23, 2018

This PR extends the generic button functionality. It allows the definition of buttons based on attribute changed events.
An example configuration for a Xiaomi Aqara wallswitch is provided.

The logic and checks to validate the configuration should be cleaned up.
Also tests are need.
If there is interest in this feature I will provide them.

Copy link
Contributor

@cdjackson cdjackson left a comment

Choose a reason for hiding this comment

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

Thanks @t-8ch I'll probably let @hsudbrock review this since he wrote the initial implementation. From a quick look though it looks fine. As you say - tests are needed, and I might also suggest the occasional line or two of comments ;)

@t-8ch
Copy link
Member Author

t-8ch commented Dec 23, 2018

Will do!

@t-8ch t-8ch force-pushed the generic-button-attributes branch from ac88934 to 42c5777 Compare December 23, 2018 22:35
@t-8ch
Copy link
Member Author

t-8ch commented Dec 23, 2018

Currently the value of the attribute is compared via via its string representation.
This works nicely around the fact, that the configuration only allows string values, while the actual attribute may have a wider range of types.
However this will make it impossible to specify integer values as hex, like the other values.
Do we want to:

  • Force users to specify the exact string versions
  • Special-case integer attribute values
  • Only allow integer attribute values
    ?

@t-8ch
Copy link
Member Author

t-8ch commented Dec 23, 2018

How should the tests be grouped/ordered in relation to the existing command tests?
Should they by similar functionality or group by command/attribute?

@t-8ch t-8ch force-pushed the generic-button-attributes branch from 42c5777 to 10e4a27 Compare December 24, 2018 08:27
@t-8ch
Copy link
Member Author

t-8ch commented Dec 24, 2018

It seems the channels can't be linked from the UI, as no profile can be selected.
Is this intentional/known or a bug in thing definition?

Edit: It's probably because the channel only triggers and has no state

@t-8ch t-8ch force-pushed the generic-button-attributes branch 2 times, most recently from d9d8828 to 71f7284 Compare December 24, 2018 10:43
@t-8ch
Copy link
Member Author

t-8ch commented Dec 26, 2018

@cdjackson One question about the configuration application:
Currently after pairing the switch from the inbox it will take some time until it is fully discovered. After the device is fully discovered a second Thing, with the properties and channels configured via the XML files, appears in the Inbox.
Adding this Thing will again trigger a full discovery process.
In the end there are two Things configured, one generic and one properly usable.
Is this intentional or is my configuration somehow broken?

@cdjackson
Copy link
Contributor

cdjackson commented Dec 26, 2018 via email

@t-8ch
Copy link
Member Author

t-8ch commented Dec 26, 2018

Ok. Maybe someone with one of the other configured devices can try to reproduce the issue.
Otherwise I will have to do some digging.

@hsudbrock
Copy link
Contributor

Hi @t-8ch, thanks for contributing!

I had a first look at the PR, and before I start a detail-level review, I have a general question. The reason for the question is that, at first glance, it looks a little odd to me to use trigger channels in combination with ZigBee attribute reporting - but maybe this is only due to how the Xiaomi Aqara wall switch (which I have not used so far) is implemented.

You have added three trigger channels for the wall switch, left, right, and range-check; consider left for now, assuming that this models button presses for the left button of the wall switch.

The channel triggers when the device reports a new value for the attribute 85 of cluster 0x12 (value 1 for single press, 0 for long press, and 2 for double press).

The question: Will the value of the attribute always indicate the last press that was performed on the left button of the device? I.e., imaging doing a double press, then waiting for 10 seconds, and then reading the attribute from the device. Will the attribute value still be 2? If not, which attribute value will the device show when reading the attribute after 10 seconds?

Background of the question: It seems strange to me that an attribute is used to model an action like a button press, and I wonder why this is modeled like this for the wall switch. Attributes smell like some state that can be retrieved from the device - which could, maybe, be better modeled with a state channel and not a trigger channel in openHAB.

@t-8ch
Copy link
Member Author

t-8ch commented Jan 3, 2019

To be honest, I only ever used the attribute changed commands emitted by the switch presses.
(That always and promptly are emitted on each button press, even when the same button was already pressed last time).
I will have to double check on the actual value of the attribute.

@t-8ch
Copy link
Member Author

t-8ch commented Jan 3, 2019

Also the physical device itself does not indicate any state to the user.
The buttons always (mechanically) reset back into the non-pressed state.

@hsudbrock
Copy link
Contributor

Thanks for the feedback, @t-8ch. From what you write, it sounds like the wall switch uses attributes in a - for me - strange way (which might be completely normal when looking at it from another angle though...) From what you write, it sounds reasonable to cover this with the GenericButtonConverter.

Copy link
Contributor

@hsudbrock hsudbrock left a comment

Choose a reason for hiding this comment

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

I had a look at the changes, see comments inline.

@t-8ch
Copy link
Member Author

t-8ch commented Jan 8, 2019

Thanks for the feedback. I will try to implement it soon.

@t-8ch t-8ch changed the title [RFC] Generic buttons defined by attribute changes Generic buttons defined by attribute changes Jan 8, 2019
@t-8ch t-8ch force-pushed the generic-button-attributes branch from 023589f to 364db45 Compare January 9, 2019 19:29
@t-8ch
Copy link
Member Author

t-8ch commented Jan 9, 2019

@hsudbrock I update the PR to incorporate your suggestions.
Could you have another look?

FYI: Currently I don't have access to the switch, so this version of the PR is not actually tested with a physical device.

@t-8ch
Copy link
Member Author

t-8ch commented Jan 16, 2019

The CI seems to be happy now.

@hsudbrock
Copy link
Contributor

@t-8ch Thanks for the update. Sorry, I did not get to have a look again yet, will do this soon!

Just one hint, as I see that you force-pushed to your branch: For the reviewer, it is often easier if you add new commits instead of changing commits, so that one can see what has changed in addition. (When merging the PR github will squash the commits anyway...)

@t-8ch
Copy link
Member Author

t-8ch commented Jan 18, 2019

If you prefer it this way sure.
I tried to create logical commits, as the PR does multiple things. Would it be ok, if I add more commits and just before the merge I reorganize them to be 3 (or 2) commits again?

@hsudbrock
Copy link
Contributor

If you prefer it this way sure.

Thanks; no need to change anything now for the review though, just as hint for next time :)

Would it be ok, if I add more commits and just before the merge I reorganize them to be 3 (or 2) commits again?

Fine for me; as far as I recall, github will squash the commits though when merging, creating a commit that has the PR title as commit message, so the reorganization might not be visible in this project's commit history anymore. Not sure 100% though...

@t-8ch
Copy link
Member Author

t-8ch commented Jan 18, 2019

You should be able to choose when performing the merge.

@hsudbrock
Copy link
Contributor

OK, thanks for the hint!

@t-8ch
Copy link
Member Author

t-8ch commented Jan 18, 2019

Hm, I will also perform some cosmetic cleanups. (Rewording, things that should not be changed, etc)

Copy link
Contributor

@hsudbrock hsudbrock left a comment

Choose a reason for hiding this comment

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

Thanks for the update to the PR! I have added some small comments inline.

@t-8ch
Copy link
Member Author

t-8ch commented Jan 18, 2019

@hsudbrock I addressed your comments.

Copy link
Contributor

@hsudbrock hsudbrock left a comment

Choose a reason for hiding this comment

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

Thanks, lgtm! OK to merge from your side, @cdjackson ?

@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/zigbee-binding/15763/1912

@hsudbrock
Copy link
Contributor

Hi @t-8ch; could you please rebase the PR on the master branch, so that it can be merged?

I just had a look at the merge conflict, I think it is only two things to do:

        boolean matches(ZclCommand command) {
            if (commandId == null) {
                return false;
            }
            boolean commandIdMatches = command.getCommandId().intValue() == commandId;
            return commandIdMatches
                    && (commandParameterName == null || commandParameterValue == null || matchesParameter(command));
        }

WDYT?

@t-8ch t-8ch force-pushed the generic-button-attributes branch from 2a22eff to 3ec985b Compare February 8, 2019 16:22
@t-8ch
Copy link
Member Author

t-8ch commented Feb 8, 2019

@hsudbrock Done

@t-8ch t-8ch force-pushed the generic-button-attributes branch from 3ec985b to d809a97 Compare February 8, 2019 16:25
@hsudbrock hsudbrock merged commit 5c7f6dc into openhab:master Feb 8, 2019
@hsudbrock
Copy link
Contributor

@t-8ch Thanks!

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.

4 participants