-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[thekeys] Initial contribution #16037
Conversation
71f9c80
to
7b1dde5
Compare
Binding for the smartlock TheKeys Signed-off-by: Jordan Martin <jo69270@gmail.com>
7b1dde5
to
86061e9
Compare
I will review your contribution. Just reading the README, I have already a first comment: firmware version should be a thing property, not a channel. |
I removed the version channel and fix some typo in the readme |
…o fix some doc typo Signed-off-by: Jordan Martin <jo69270@gmail.com>
Signed-off-by: Jordan Martin <jo69270@gmail.com>
7dbac76
to
b1deedf
Compare
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.
Review part 1
...ding.thekeys/src/main/java/org/openhab/binding/thekeys/internal/TheKeysBindingConstants.java
Outdated
Show resolved
Hide resolved
...hekeys/src/main/java/org/openhab/binding/thekeys/internal/gateway/TheKeysGatewayHandler.java
Outdated
Show resolved
Hide resolved
...ys/src/main/java/org/openhab/binding/thekeys/internal/smartlock/TheKeysSmartlockHandler.java
Outdated
Show resolved
Hide resolved
.../src/main/java/org/openhab/binding/thekeys/internal/gateway/TheKeysGatewayConfiguration.java
Outdated
Show resolved
Hide resolved
.../src/main/java/org/openhab/binding/thekeys/internal/gateway/TheKeysGatewayConfiguration.java
Outdated
Show resolved
Hide resolved
Notes for myself, items example to be reviewed. |
Signed-off-by: Jordan Martin <jo69270@gmail.com>
Signed-off-by: Jordan Martin <jo69270@gmail.com>
Signed-off-by: Jordan Martin <jo69270@gmail.com>
…perty Signed-off-by: Jordan Martin <jo69270@gmail.com>
Signed-off-by: Jordan Martin <jo69270@gmail.com>
Signed-off-by: Jordan Martin <jo69270@gmail.com>
b395d0f
to
1678465
Compare
Signed-off-by: Jordan Martin <jo69270@gmail.com>
You could have a look to compilation warnings. I see in particular several "Potential null pointer access". I will review the remaining part (real java code) soon. |
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 for you contribution!
This is not a full review, just a few comments on code style.
Javadoc runs w/o errors (warnings are ok). i18n is fine.
A lot of Null warnings.
Do you know how the gateway could be discovered (apparently there is a smartphone app which can do)? Just asking, as we try to suggest add-ons for installation if the devices are detected.
...ys/src/main/java/org/openhab/binding/thekeys/internal/smartlock/TheKeysDiscoveryService.java
Outdated
Show resolved
Hide resolved
...hekeys/src/main/java/org/openhab/binding/thekeys/internal/gateway/TheKeysGatewayHandler.java
Outdated
Show resolved
Hide resolved
...hekeys/src/main/java/org/openhab/binding/thekeys/internal/gateway/TheKeysGatewayHandler.java
Outdated
Show resolved
Hide resolved
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.
Some minor comments.
...b.binding.thekeys/src/main/java/org/openhab/binding/thekeys/internal/api/GatewayService.java
Show resolved
Hide resolved
...b.binding.thekeys/src/main/java/org/openhab/binding/thekeys/internal/api/GatewayService.java
Outdated
Show resolved
Hide resolved
...ng.thekeys/src/main/java/org/openhab/binding/thekeys/internal/api/model/GatewayInfosDTO.java
Outdated
Show resolved
Hide resolved
....binding.thekeys/src/main/java/org/openhab/binding/thekeys/internal/api/model/LockerDTO.java
Outdated
Show resolved
Hide resolved
...ng.thekeys/src/main/java/org/openhab/binding/thekeys/internal/api/model/LockerStatusDTO.java
Outdated
Show resolved
Hide resolved
...ys/src/main/java/org/openhab/binding/thekeys/internal/smartlock/TheKeysSmartlockHandler.java
Show resolved
Hide resolved
Signed-off-by: Jordan Martin <jo69270@gmail.com>
51a2958
to
51dd2b1
Compare
As far as I know, it is not possible to discover the gateway on the network. It doesn't use mDNS nor uPNP. |
Please update your last commit to add "Signed-off-by". I hope this is the only commit without it and leading a DCO being KO. |
It is. If you click "Details" you can see that only one commit is missing the sign-off, and there are instructions how to fix it. @lolodomo, in such cases we can still merge, we just have to make sure to pick one of the correct sign-offs for the squash merge commit message. |
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.
Review of the api package.
Mainly exception handling to improve.
...b.binding.thekeys/src/main/java/org/openhab/binding/thekeys/internal/api/GatewayService.java
Outdated
Show resolved
Hide resolved
...b.binding.thekeys/src/main/java/org/openhab/binding/thekeys/internal/api/GatewayService.java
Outdated
Show resolved
Hide resolved
...b.binding.thekeys/src/main/java/org/openhab/binding/thekeys/internal/api/GatewayService.java
Outdated
Show resolved
Hide resolved
...b.binding.thekeys/src/main/java/org/openhab/binding/thekeys/internal/api/GatewayService.java
Outdated
Show resolved
Hide resolved
...b.binding.thekeys/src/main/java/org/openhab/binding/thekeys/internal/api/GatewayService.java
Show resolved
Hide resolved
...ng.thekeys/src/main/java/org/openhab/binding/thekeys/internal/api/model/LockerStatusDTO.java
Outdated
Show resolved
Hide resolved
...ng.thekeys/src/main/java/org/openhab/binding/thekeys/internal/api/model/LockerStatusDTO.java
Outdated
Show resolved
Hide resolved
...binding.thekeys/src/main/java/org/openhab/binding/thekeys/internal/api/model/LockersDTO.java
Show resolved
Hide resolved
...ng.thekeys/src/main/java/org/openhab/binding/thekeys/internal/api/model/LockerStatusDTO.java
Show resolved
Hide resolved
...ing.thekeys/src/main/java/org/openhab/binding/thekeys/internal/api/model/SynchronizeDTO.java
Outdated
Show resolved
Hide resolved
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.
Last comment about files in resources folder
bundles/org.openhab.binding.thekeys/src/main/resources/OH-INF/thing/thing-types.xml
Outdated
Show resolved
Hide resolved
Remains to review: 3 Java classes (thing handlers and discovery class) + the test class + the example in README. |
The best option could be to catch different possible exceptions in your low level methods (get and post) and then rethrow only a TheKeysException. |
* @author Jordan Martin - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
@Component(service = TheKeyTranslationProvider.class) |
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.
With the latest changes in core you no longer need this.
@NonNullByDefault | ||
public class TheKeysDiscoveryService extends AbstractDiscoveryService implements ThingHandlerService { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(TheKeysDiscoveryService.class); | ||
|
||
@Nullable | ||
private TheKeysGatewayHandler gatewayHandler; |
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.
@NonNullByDefault | |
public class TheKeysDiscoveryService extends AbstractDiscoveryService implements ThingHandlerService { | |
private final Logger logger = LoggerFactory.getLogger(TheKeysDiscoveryService.class); | |
@Nullable | |
private TheKeysGatewayHandler gatewayHandler; | |
@Component(scope = ServiceScope.PROTOTYPE, service = TheKeysDiscoveryService.class) | |
@NonNullByDefault | |
public class TheKeysDiscoveryService extends AbstractThingHandlerDiscoveryService<TheKeysGatewayHandler> { | |
private final Logger logger = LoggerFactory.getLogger(TheKeysDiscoveryService.class); | |
private final Bundle bundle; |
private TheKeysGatewayHandler gatewayHandler; | ||
|
||
public TheKeysDiscoveryService() { | ||
super(Set.of(THING_TYPE_SMARTLOCK), 15, false); |
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.
super(Set.of(THING_TYPE_SMARTLOCK), 15, false); | |
super(TheKeysGatewayHandler.class, Set.of(THING_TYPE_SMARTLOCK), 15, false); | |
this.bundle = FrameworkUtil.getBundle(this.getClass()); |
TheKeysGatewayHandler gatewayHandler = Objects.requireNonNull(this.gatewayHandler); | ||
ThingUID gatewayThingUID = gatewayHandler.getThing().getUID(); | ||
String label = gatewayHandler.getTranslationProvider().getText("discovery.thekeys.smartlock.label"); |
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.
TheKeysGatewayHandler gatewayHandler = Objects.requireNonNull(this.gatewayHandler); | |
ThingUID gatewayThingUID = gatewayHandler.getThing().getUID(); | |
String label = gatewayHandler.getTranslationProvider().getText("discovery.thekeys.smartlock.label"); | |
ThingUID gatewayThingUID = thingHandler.getThing().getUID(); | |
String label = thingHandler.getTranslationProvider().getText("discovery.thekeys.smartlock.label"); |
The thingHandler
is now an implicit non-null field. You don't need null-checks.
TheKeysGatewayHandler gatewayHandler = Objects.requireNonNull(this.gatewayHandler); | ||
ThingUID gatewayThingUID = gatewayHandler.getThing().getUID(); |
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.
TheKeysGatewayHandler gatewayHandler = Objects.requireNonNull(this.gatewayHandler); | |
ThingUID gatewayThingUID = gatewayHandler.getThing().getUID(); | |
ThingUID gatewayThingUID = thingHandler.getThing().getUID(); |
|
||
@Override | ||
public @Nullable ThingHandler getThingHandler() { | ||
return gatewayHandler; | ||
} | ||
|
||
@Override | ||
public void setThingHandler(@Nullable ThingHandler handler) { | ||
if (handler instanceof TheKeysGatewayHandler theKeysGatewayHandler) { | ||
gatewayHandler = theKeysGatewayHandler; | ||
} | ||
} | ||
|
||
@Override | ||
public void deactivate() { | ||
super.deactivate(); | ||
} |
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.
@Override | |
public @Nullable ThingHandler getThingHandler() { | |
return gatewayHandler; | |
} | |
@Override | |
public void setThingHandler(@Nullable ThingHandler handler) { | |
if (handler instanceof TheKeysGatewayHandler theKeysGatewayHandler) { | |
gatewayHandler = theKeysGatewayHandler; | |
} | |
} | |
@Override | |
public void deactivate() { | |
super.deactivate(); | |
} |
Not needed anymore, this is already provided by the super class.
public TheKeysDiscoveryService() { | ||
super(Set.of(THING_TYPE_SMARTLOCK), 15, false); | ||
} | ||
|
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.
@Reference(unbind = "-") | |
public void bindTranslationProvider(TranslationProvider i18NProvider) { | |
this.i18NProvider = i18NProvider; | |
} | |
@Reference(unbind = "-") | |
public void bindLocaleProvider(LocaleProvider localeProvider) { | |
this.localeProvider = localeProvider; | |
} | |
public String getText(String key, @Nullable Object... arguments) { | |
try { | |
Locale locale = localeProvider.getLocale(); | |
return i18nProvider.getText(bundle, key, getDefaultText(key), locale, arguments); | |
} catch (IllegalArgumentException e) { | |
return "Unable to load message for key " + key; | |
} | |
} | |
public @Nullable String getDefaultText(String key) { | |
return i18nProvider.getText(bundle, key, key, Locale.ENGLISH); | |
} | |
bundles/org.openhab.binding.thekeys/src/main/resources/OH-INF/thing/thing-types.xml
Outdated
Show resolved
Hide resolved
@JordanMartin : I thought I was very late but now I see that you have pushed nothing since we published our comments. Please let the reviewers mark comments as resolved. This is difficult for us to follow what was really considered if you mark them as resolved even without providing any change. I will finish the review if you are still working on this binding and you push new code. |
c2486f5
to
37ff24e
Compare
Signed-off-by: Jordan Martin <jo69270@gmail.com>
Signed-off-by: Jordan Martin <jo69270@gmail.com>
Signed-off-by: Jordan Martin <jo69270@gmail.com>
Signed-off-by: Jordan Martin <jo69270@gmail.com>
37ff24e
to
5697a13
Compare
@lolodomo I've done almost all the requested changes but I haven't had time to test it yet. |
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.
Restart of the review
| batteryLevel | Number:Power | R | Current battery level | | ||
| lowBattery | Switch | R | Low battery warning | |
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.
Real channel names are "battery-level" and "low-battery".
Type for battery-level is Number, not Number:Power.
| syncInProgress | Switch | R | Indicates the pending update of the lock state | | ||
| lastSync | DateTime | R | Date of the last success sync with the lock | |
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.
Real channel names are "sync-in-progress" and "last-sync"
| status | String | R | Status of the smartlock | | ||
| batteryLevel | Number:Power | R | Current battery level | | ||
| lowBattery | Switch | R | Low battery warning | | ||
| rssi | Number | R | Bluetooth signal strength with the gateway | |
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.
Type is Number:Power
Number Smartlock_Battery_Level "Battery Level" <Battery> (Smartlock) ["Measurement", "Energy"] { channel="thekeys:smartlock:tk-gateway:1234:batteryLevel" } | ||
Switch Smartlock_Low_Battery "Low Battery" <LowBattery> (Smartlock) ["Energy", "LowBattery"] { channel="thekeys:smartlock:tk-gateway:1234:lowBattery" } |
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.
battery-level and low-battery for the channel ids
Switch Smartlock_Synchronization_In_Progress "Synchronization In Progress" (Smartlock) ["Point"] { channel="thekeys:smartlock:tk-gateway:1234:syncInProgress" } | ||
DateTime Smartlock_Last_Sync "Last Sync" (Smartlock) ["Point"] { channel="thekeys:smartlock:tk-gateway:1234:lastSync" } |
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.
sync-in-progress and last-sync for the channel ids
channel-type.thekeys.lock_status.label = Lock Status | ||
channel-type.thekeys.lock_status.description = Status of the smartlock |
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.
Please regenerate the i18n files, they contain old names for channels.
mvn i18n:generate-default-translations
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" |
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.
Look at in an existing POM file, these first 2 lines were slightly updated.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
public static final String CHANNEL_BATTERY_LEVEL = "batteryLevel"; | ||
public static final String CHANNEL_LOW_BATTERY = "lowBattery"; |
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.
Real channel names are "battery-level" and "low-battery".
public static final String CHANNEL_LAST_SYNC = "lastSync"; | ||
public static final String CHANNEL_SYNC_IN_PROGRESS = "syncInProgress"; |
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.
Real channel names are "sync-in-progress" and "last-sync"
* @param url The target url | ||
* @param timeoutMs The request timeout in ms | ||
* @param responseType The type of the response to be parsed | ||
* @return The parsed response or null if empty response |
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.
null cannot happen
* @param body The body to be posted | ||
* @param timeout The request timeout in ms | ||
* @param responseType The type of the response to be parsed | ||
* @return The parsed response or null if empty response |
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.
null cannot happen
* @return The parsed response or null if empty response | ||
* @throws TheKeysException If the request failed | ||
*/ | ||
public <T> T get(String url, int timeoutMs, Class<@NonNull T> responseType) throws TheKeysException { |
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.
@NonNull
is useless as @NonNullByDefault
is applied to your full class.
* @return The parsed response or null if empty response | ||
* @throws TheKeysException If the request failed | ||
*/ | ||
public <T> T post(String url, String body, int timeout, Class<T> responseType) throws TheKeysException { |
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.
Ultra minor: the parameter is timeout
in that method while timeoutMs
in the previous one. Suggestion (and not request for change): the naming could be consistent.
@@ -0,0 +1,101 @@ | |||
# The Keys Binding | |||
|
|||
This is the binding for [TheKeys Smartlock](https://www.the-keys.eu/en/produits/8-serrure-connectee.html). |
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.
Looks like https://www.the-keys.eu/ does not respond...
@JordanMartin : I restarted the review and added few new comments (that are easy to fix). I noticed that you already considered all my previous review comments, thank you for that. I will try to finish the full review during the coming week. If you are available to handle the last comments, we can probably conclude quickly. |
Gentle ping @JordanMartin are you able to proceed? |
I could finish the review but to not loose my free time, first I would like to have a comment from @JordanMartin to be sure he is still interested to finish this binding. PS: I could even push changes that I recommend to speed up the process but in that case I could no more be the unique reviewer. |
I’ll be available to review. But a comment from @JordanMartin would be best as this binding hardly has a future if the contributor stops development before the initial PR is finished. |
My smart lock is broken. |
That is very unfortunate. Also very good that you shared this, it saves spending any more time on this matter. I’ll close this PR for now as there seems no base to continue. |
Binding for the smartlock TheKeys
Description
This is the binding for TheKeys Smartlock.
This binding allows you to integrate, view, control and configure TheKeys Gateway and TheKeys Smartlock.
Full description of the binding capabilites in the README.md
Documentation
The logo is waiting this PR : openhab/openhab-docs#2171
Testing
The compiled jar bundle is available here : org.openhab.binding.thekeys-4.1.0-SNAPSHOT.jar