Skip to content

[broadlink] Initial contribution - #11049

Closed
themillhousegroup wants to merge 10 commits into
openhab:mainfrom
themillhousegroup:openhab-3.2-broadlink-binding
Closed

[broadlink] Initial contribution#11049
themillhousegroup wants to merge 10 commits into
openhab:mainfrom
themillhousegroup:openhab-3.2-broadlink-binding

Conversation

@themillhousegroup

@themillhousegroup themillhousegroup commented Jul 22, 2021

Copy link
Copy Markdown

A binding that can communicate with the Broadlink family of WiFi-addressable devices, currently comprising:

A1 environmental sensor
RMx Remote IR blasters
SPx WiFi-controlled power switches
MPx WiFi-controlled multi-outlet power strips
Development of this binding was begun some four (!) years ago by one Cato Sognen, who unfortunately seems to have stopped development a few months after posting about it here:
https://community.openhab.org/t/broadlink-binding-for-rmx-a1-spx-and-mp-any-interest/22768

I reverse-engineered the binding's JAR file and gradually built up an understanding of its operation, fixing a few bugs and adding support for more devices along the way, including bringing it up through the 2.x and 3.x upgrade paths.

There has been significant interest and help provided by interested parties, as evidenced by the enormity of the above thread! It would be fantastic to get this binding into the official release to reward their patience :-)

Thanks also to @Skinah who provided invaluable guidance in previous PRs for this binding.
closes #322

Signed-off-by: John Marshall john@themillhousegroup.com

Signed-off-by: John Marshall <john.marshall.au@gmail.com>
@themillhousegroup
themillhousegroup requested a review from a team as a code owner July 22, 2021 23:30
@fwolter fwolter added the new binding If someone has started to work on a binding. For a new binding PR. label Jul 25, 2021
@fwolter

fwolter commented Jul 25, 2021

Copy link
Copy Markdown
Member

Is there any relationship to the broadlinkthermostat binding?

@themillhousegroup

Copy link
Copy Markdown
Author

Is there any relationship to the broadlinkthermostat binding?

They may be using the same communications protocol underneath. Beyond that I don't know.

@fwolter

fwolter commented Jul 26, 2021

Copy link
Copy Markdown
Member

It doesn't make much sense to have two bindings for the same system, speaking the same protocol. @flo-02-mu Is there any reason why you suffixed your binding with "thermostat"? Is that another subset of devices or different protocols or is it even the same vendor?

@Skinah

Skinah commented Aug 1, 2021

Copy link
Copy Markdown
Contributor

I took a look and the other already merged binding uses the library linked below, which does support RM2 and SP1 and SP2 devices. Sorry I cant comment on if the RM4 is different to a RM2 protocol and if it would work. However the library does not seem to get updated very often.

https://github.com/mob41/broadlink-java-api

@kaikreuzer kaikreuzer added rebuild Triggers Jenkins PR build and removed rebuild Triggers Jenkins PR build labels Aug 1, 2021
@Skinah Skinah added rebuild Triggers Jenkins PR build and removed rebuild Triggers Jenkins PR build labels Aug 16, 2021
@themillhousegroup

Copy link
Copy Markdown
Author

I understand the reluctance to accept a binding so similar to one that's already merged; however as mentioned by @Skinah the protocol library used by the -thermostat binding hasn't received any updates for a long time, and as such would not be able to support the most recent Broadlink devices. The maintainers have not merged a PR for over a year; I'm not sure I'd want to depend on it.

Due to the nature of the Broadlink device discovery mechanism, each supported device still has to be explicitly added to this binding anyway.

@Skinah

Skinah commented Aug 18, 2021

Copy link
Copy Markdown
Contributor

Can you add yourself to the codeowners file please?
Also the build is failing complaining about the pom, please make sure you have added the binding to the 2 different pom files.

Would be good to have this showing up with a green tick at passing the build. These 3 are described here.

https://www.openhab.org/docs/developer/bindings/#include-the-binding-in-the-build

Looking at the other library used in broadlinkthermostat binding in more depth I have concerns over it not only due to the last time it got any updates, but because it does not work on Java 11 and the PR to get this resolved has had no progress since April last year. Any PR would likely not progress = dead library.

a1aw/broadlink-java-api#27

The forum has a post on this here:
https://community.openhab.org/t/broadlink-floureon-hysen-thermostat-binding/81921/88
The post seems to indicate that the library may/was (?) modified to run under java 11 and the modified lib included.

My opinion is we should merge this binding after going through review.

…emillhousegroup/openhab2-addons into openhab-3.2-broadlink-binding

Signed-off-by: John Marshall <john.marshall.au@gmail.com>
…emillhousegroup/openhab2-addons into openhab-3.2-broadlink-binding

Signed-off-by: John Marshall <john.marshall.au@gmail.com>
…emillhousegroup/openhab2-addons into openhab-3.2-broadlink-binding

Signed-off-by: John Marshall <john.marshall.au@gmail.com>
@fwolter

fwolter commented Aug 21, 2021

Copy link
Copy Markdown
Member

I'm still trying to gather the facts. The forum post linked by @Skinah states that the library is not compatible with Java 11, but the OH 3.x addon uses exactly this library:

<groupId>com.github.mob41.blapi</groupId>
So, it must be Java 11 compatible.

I would have no problem replacing the existing broadlinkthermostat binding by this binding, if it supports all devices the -thermostat binding supports and the config of these is compatible. As far as I understand this binding supports more devices and doesn't use a third-party library, which makes it superior (without looking into the code in detail, yet).

@flo-02-mu as the owner of the broadlinkthermostat binding, can you join the discussion?

@flo-02-mu

Copy link
Copy Markdown
Contributor

The java 11 compatibility of the bl-library was a missunderstanding: For building the bl-library the jaxb dependency needed to be there when building with java 11. The usage of the assembled library is not an issue.
The broadlinkthermostat binding was focussing soley on this one specific type of broadlink devices (thermostats) which was pretty different compared to all the IR remote controllers (RMx) handled by the "old" broadlink binding. If I see it correctly, the new implementation also supports an A1 sensor, so adding the thermostats should be doable. Due to vacation period I don't have access to my thermostats right now so that I cannot run the discovery of the proposed binding against them, but I can try that mid of September.


The Broadlink RM family of devices can transmit IR codes.
The map file contains a list of IR command codes to send via the device.
The file uses the [Java Properties File format](https://en.wikipedia.org/wiki/.properties) and is stored in the `<OPENHAB_CONF>/transform` folder.

@Skinah Skinah Sep 8, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure the default should not be the conf/transform folder. From having other bindings get merged, I was told the correct place is this using the binding name as a sub folder.....
<OPENHAB_USER_DATA>/broadlink/<UID>.map
or
<OPENHAB_USER_DATA>/broadlink/<UID>/broadlink.map

This location will have write permissions on mac/win/linux
Also consider what happens if someone has multiple things, hence the suggestion to use the Unique ID of the thing in the filename or a sub folder, whatever makes sense.

Use this code to get the location...

OpenHAB.getUserDataFolder() + "/broadlink/" + this.thing.getUID().getId() + "/"

I like the idea of it in a file so you can share the files to others easily.

If you made the change suggested above, then you could remove this as a config and it would be handled automatically. I suspect leaving it as is, people that own two devices will forget to name the map to something different on the second device and that will cause it to wipe the file from the first. This is where having the UID will stop that occurring.

props.stringPropertyNames().forEach(k -> {
commandMap.put(k, props.getProperty(k));
});
logger.info("Read {} commands from {}", commandMap.size(), mapFilePath);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

info should rarely be used to keep logs clean, suggest this is debug.


public BroadlinkDiscoveryService() {
super(BroadlinkBindingConstants.SUPPORTED_THING_TYPES_UIDS_TO_NAME_MAP.keySet(), 10, true);
logger.info("BroadlinkDiscoveryService - Constructed");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

debug?

logger.trace("Comparing with desired mac: {}", missingThingConfig.getMacAddressAsString());

if (missingThingConfig.getMacAddressAsString().equals(remoteMAC)) {
logger.info("We have a match for target MAC {} at {} - reassociate!", remoteMAC, remoteAddress);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Debug seems a better fit.

logger.warn("Error while receiving", e);
}
}
logger.info("Receiver thread ended");

@Skinah Skinah Sep 12, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Debug seems a better fit, or remove it to give more performance.

socketReceiveThread.interrupt();
}
if (socket != null) {
logger.info("Socket closed");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Debug seems a better fit. If this happens a lot, then consider removing this to improve performance. There is a cost each time Java has to check if the logger is set to debug/info etc...

}

public void onDeviceRediscovered(String newIpAddress) {
logger.info("Rediscovered this device at IP {}", newIpAddress);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Debug seems a better fit.

@fwolter

fwolter commented Dec 11, 2021

Copy link
Copy Markdown
Member

I think the way to go is to ship both bindings, so users of the broadlinkthermostat binding are not fooled if their binding is removed from the distribution. @themillhousegroup Are you going to address @Skinah's review comments?

@fwolter fwolter added the awaiting feedback Awaiting feedback from the pull request author label Jan 1, 2022
@Cossey

Cossey commented Feb 15, 2022

Copy link
Copy Markdown
Contributor

This PR seems to be broken and modifies too many files outside of the binding. Someone here can probably offer help to fix - normally happens when you have opened PR a long time ago and you pull in new changes (has happened on my PRs and others before). If fixing is not feasible then you might want to close and re-open a new PR without the issues - just make sure you sort out all the remaining change requests first.

@peterhoeg

peterhoeg commented Feb 15, 2022 via email

Copy link
Copy Markdown

@themillhousegroup

Copy link
Copy Markdown
Author

Yep I'm going to kill this PR and try again. It feels like trying to nail jelly to a moving train getting this PR landed :-(

@alackmann

Copy link
Copy Markdown
Contributor

@themillhousegroup john - it seems you never re-opened your PR for this. Does this mean your project is now abandoned? Your version of the Broadlink binding seems to support RF devices, while the others do not sadly.

@themillhousegroup

Copy link
Copy Markdown
Author

Hi @alackmann yes I'm afraid I no longer have the time to give this binding the attention it requires; general maintenance tasks once in the main codebase might be possible, but unfortunately getting it merged has just proved to be too much.

Some months ago I did have a conversation with @rlarranaga regarding him trying to steer a fresh merge PR into openHAB, but I'm not sure what became of that.

@rlarranaga

Copy link
Copy Markdown

Hello,

I started work on the PR and managed to get a couple of things done, i.e: text header updates, upgrading junit, change log level of messages, all compiling and running succesfully on OH 3.3.

However, I have been trying to troubleshoot an issue where I get random BIG delays when sending commands (10+ seconds, most noticeable when trying to control a TV).
Have not been able to find the reason.

I upgraded OH to 3.4 though, and caught wind of the fact that the broadlinkthermostat add-in also supports RM Mini 3 (I have mostly RM mini 4s, but one 3. Delay was showing in all of them). with the broadlinkthermostat add-in, these delays appear not to be present. Currently, i am playing around with a modified version of broadlink-java-api, trying to add RM4 mini support to confirm if the pesky delay is gone.

beoadlinkthermostat's dependency on broadlink-java-api is an issue though. Not only it appears to be abandoned, but some of the components it uses (javax) need to be replaced soon too.

To this, you can add the fact that I haven't developed code in years, and work is currently not leaving much free time.

So progress is slow, to say the least. I would love to give a better update, with an ETA for submitting a PR, but I am afraid I am going to have to disappoint.

@rlarranaga

Copy link
Copy Markdown

Hi again @alackmann , @themillhousegroup @flo-02-mu ,

I decided to try one more time and compile the binding against OH 3.4.3
I made progress after figuring out that some libraries were not available anymore (org.eclipse.smarthome, org.apache.commons).

I am currently stuck with six errors of the same tipe that have to do with the handling of Nulls:

[ERROR] /home//git/openhab-addons/bundles/org.openhab.binding.broadlink/src/main/java/org/openhab/binding/broadlink/handler/BroadlinkBaseThingHandler.java:[141,57] Null type mismatch: required 'byte @org.eclipse.jdt.annotation.NonNull[]' but the provided value is inferred as @org.eclipse.jdt.annotation.Nullable
[ERROR] /home//git/openhab-addons/bundles/org.openhab.binding.broadlink/src/main/java/org/openhab/binding/broadlink/handler/BroadlinkStripModel11K3S2UHandler.java:[111,56] Null type mismatch: required 'byte @org.eclipse.jdt.annotation.NonNull[]' but the provided value is inferred as @org.eclipse.jdt.annotation.Nullable
[ERROR] /home//git/openhab-addons/bundles/org.openhab.binding.broadlink/src/main/java/org/openhab/binding/broadlink/handler/BroadlinkRemoteModel4Handler.java:[51,56] Null type mismatch: required 'byte @org.eclipse.jdt.annotation.NonNull[]' but the provided value is inferred as @org.eclipse.jdt.annotation.Nullable
[ERROR] /home//git/openhab-addons/bundles/org.openhab.binding.broadlink/src/main/java/org/openhab/binding/broadlink/handler/BroadlinkStripModel1Handler.java:[111,56] Null type mismatch: required 'byte @org.eclipse.jdt.annotation.NonNull[]' but the provided value is inferred as @org.eclipse.jdt.annotation.Nullable
[ERROR] /home//git/openhab-addons/bundles/org.openhab.binding.broadlink/src/main/java/org/openhab/binding/broadlink/handler/BroadlinkRemoteHandler.java:[129,40] Null type mismatch: required 'java.lang.@NonNull String' but the provided value is inferred as @org.eclipse.jdt.annotation.Nullable
[ERROR] /home//git/openhab-addons/bundles/org.openhab.binding.broadlink/src/main/java/org/openhab/binding/broadlink/handler/BroadlinkRemoteModel2Handler.java:[42,56] Null type mismatch: required 'byte @org.eclipse.jdt.annotation.NonNull[]' but the provided value is inferred as @org.eclipse.jdt.annotation.Nullable

Any idea how to handle these?

Additionally, i have around 25 warnings of the following type:

[WARNING] /home/git/openhab-addons/bundles/org.openhab.binding.broadlink/src/main/java/org/openhab/binding/broadlink/handler/BroadlinkBaseThingHandler.java:[120,39] Potential null pointer access: this expression has a '@Nullable' type

I have seen the "Nullable Annotations" discussion in the OpenHAB forum. but i am not sure i understand it enough. Can anyone point me towards a good basic resource to figure those out?

Lastly, i am currently trying to compile with:

mvn clean install -P check

but on the logs, i see:

[WARNING] The requested profile "check" could not be activated because it does not exist.

I am pretty sure i am missing a lot of code checking there. Any ideas what can be wrong with that?

Thanks

@rlarranaga

Copy link
Copy Markdown

Hi again @alackmann , @themillhousegroup @flo-02-mu ,

It looks like the errors i posted above stem from the fact that most of the methods are declared as @nullable (and in fact, explicitly return nulll), but the result of the method is being assigned to a byte array type.

Since i cannot really annotate the methods as @nonnull, is there a way to define a byte array as @nullable?

An example of this is:

byte response[] = sendAndReceiveDatagram(authRequest, "authentication");

In this case, sendAndReceiveDatagram is @nullable, and that is why the compiler throws an error when trying to assign its result to response. It does not seem i can annotate response[] as @nullable though.

Thanks!

@rlarranaga

rlarranaga commented Mar 3, 2023

Copy link
Copy Markdown

Hello @alackmann @themillhousegroup @flo-02-mu

I have managed to compile this binding with openhab 3.4.3 and am currently testing it. I have made all modification @flo-02-mu suggested except the change in the configuration file name. The binding uses a service model for retrieving the codes from the files that is not aware of thing instances. It is non trivial to make the change, so i won't be able to modify it in the short term.

In the mean time, i have a couple of warnings when compiling that i would like to know if you have suggestions on how to clean up:

The following come from mvn clean install:

[WARNING] /openhab-addons/bundles/org.openhab.binding.broadlink/src/test/java/org/openhab/binding/broadlink/handler/BroadlinkRemoteModel4HandlerTest.java:[190,56] Type safety: The constructor org.openhab.core.library.types.QuantityType(java.lang.Number, javax.measure.Unit) belongs to the raw type org.openhab.core.library.types.QuantityType. References to generic type org.openhab.core.library.types.QuantityType<T> should be parameterized
[WARNING] /openhab-addons/bundles/org.openhab.binding.broadlink/src/test/java/org/openhab/binding/broadlink/handler/BroadlinkRemoteModel4HandlerTest.java:[190,56] Type safety: The expression of type org.openhab.core.library.types.QuantityType needs unchecked conversion to conform to org.openhab.core.library.types.QuantityType<javax.measure.quantity.Dimensionless>
[WARNING] /openhab-addons/bundles/org.openhab.binding.broadlink/src/test/java/org/openhab/binding/broadlink/handler/BroadlinkRemoteModel4HandlerTest.java:[190,60] org.openhab.core.library.types.QuantityType is a raw type. References to generic type org.openhab.core.library.types.QuantityType<T> should be parameterized

The following come from the report summary:

image

Not sure how to handle either of these.

You can look at the code at the following fork:

https://github.com/rlarranaga/openhab-addons

I believe if we can knock these off, we are very close to a PR.

Thanks!

@rlarranaga

rlarranaga commented Mar 11, 2023

Copy link
Copy Markdown

Hello @alackmann , @themillhousegroup , @flo-02-mu
I have reopened this PR. with Issue number #14582

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting feedback Awaiting feedback from the pull request author new binding If someone has started to work on a binding. For a new binding PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Broadlink RM Pro Binding