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

[tplinksmarthome] Added configuring devices by deviceId #4182

Merged
merged 4 commits into from
Nov 8, 2018

Conversation

Hilbrand
Copy link
Member

With the configuration option a device can be configured using the device id instead of ip address. This makes it resilient to ip address updated on the device.

This makes it resilient to ip address changes.
It's not using the mac address for this because the mac address can also be changed (by the user).

Signed-off-by: Hilbrand Bouwkamp <[email protected]>
Copy link
Member

@martinvw martinvw 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 PR I added some remarks

The thing can be configured or by `ipAddress` or by `deviceId`.
If the one of them is used the other is automatically set by the binding.
When manually configured it's preferred to set the `deviceId` because if the ip address of the device would change this will be automatically updated.
When setting the `deviceId` it can take up to 1 minute before the ip address is set. By manually triggering a discovery process it will update it faster.
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

If this merely means that a manual discovery creates a DiscoveryResult quicker and that the framework then syncs the discovered ip address property from the DiscoveryResult to the Thing, this sounds alright to me as it does not mean that the discovery code is itself directly linked to the ThingHandlers by passing data to it.

Copy link
Member

Choose a reason for hiding this comment

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

So @kaikreuzer if you can only use the :deviceId-only-configuration while Discovery is enabled that is not a problem? Great!

Copy link
Member

Choose a reason for hiding this comment

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

Well, that's the to-be-accepted drawback of that kind of configuration then.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated the documentation to better state it's dependency on the discovery service. It works @kaikreuzer mentions. it's only used to set the ip address in case the user doesn't set the ip address or in case there the ip address of the device changed. It doesn't depend on discovery for status or controlling the device.
I thought about some more fancy code by triggering the discovery when no ip address is know. This would make it independent on (background) discovery, but would require the binding handling timeout, correctly stopping and some more checks to make it clean and efficient. But that seem to be to much for the gains it would get and make the code much more complex (and probably spending a lot of time to get it correct)

@@ -105,15 +120,64 @@ Connection createConnection(TPLinkSmartHomeConfiguration config) {
return new Connection(config.ipAddress);
}

private DeviceState refreshCache() {
private Optional<DeviceState> refreshCache() {
Copy link
Member

Choose a reason for hiding this comment

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

Does this make much sense now you have to handle and optional, should you just make this method return a Nullable DeviceState?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes it does make sense. It was the only simple way I could think of to get this to work without getting compiler errors. The problem is I added @NonNullByDefault (silly me 😄) And this causes a problem with the ExpiringCache. The problem is the method getValue on that class is Nullable. But the only way to get a null value is if the Supplier would return a null. However because the @NonNullByDefault in the class enforces the non nullable on the Supplier. This would all not be a problem if my implementation wasn't based on a getValue that does return null in case no value could be given. So I have a value that can be null, but the Supplier doesn't accept the value to be null. To fix this the method should not return null anymore. One way is to introduce an empty object that is returned when no value is present, but that is basically the whole reason to have an Optional. Hence the Optional was introduced.

Copy link
Member

@martinvw martinvw Nov 5, 2018

Choose a reason for hiding this comment

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

Wouldn’t it make more sense to mark it Nullable? Because it shall also return null if the key is not available.

Sorry you already suggested that it might make sense 😉

See you this Thursday!

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes but I don't know how. It would require to mark the get method on the FunctionalInterface Supplier Nullable in ExpireCache. Marking refreshCache() nullable won't help much.

Copy link
Member

Choose a reason for hiding this comment

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

I added a PR to your repo and one to ESH:

Hilbrand#1
eclipse-archived/smarthome#6485

- Better explained dependency on discovery service.
- Added logging on RuntimeException as it might contain valuable information about what caused the exception and where it was triggered.

Signed-off-by: Hilbrand Bouwkamp <[email protected]>
Signed-off-by: Martin van Wingerden <[email protected]>
Signed-off-by: Martin van Wingerden <[email protected]>
@martinvw
Copy link
Member

martinvw commented Nov 8, 2018

Lets wait for a green build

@martinvw martinvw merged commit e9b14d4 into openhab:master Nov 8, 2018
@martinvw
Copy link
Member

martinvw commented Nov 8, 2018

Thanks!

@Hilbrand Hilbrand deleted the tplink_mac branch November 8, 2018 20:59
mherwege pushed a commit to mherwege/openhab-addons that referenced this pull request Nov 13, 2018
* Added configuring devices by deviceId

This makes it resilient to ip address changes.
It's not using the mac address for this because the mac address can also be changed (by the user).

- Better explained dependency on discovery service.
- Added logging on RuntimeException as it might contain valuable information about what caused the exception and where it was triggered.

Also-by: Martin van Wingerden <[email protected]>
Signed-off-by: Hilbrand Bouwkamp <[email protected]>
@martinvw martinvw added this to the 2.4 milestone Dec 9, 2018
chaton78 pushed a commit to chaton78/openhab-addons that referenced this pull request Jan 1, 2019
* Added configuring devices by deviceId

This makes it resilient to ip address changes.
It's not using the mac address for this because the mac address can also be changed (by the user).

- Better explained dependency on discovery service.
- Added logging on RuntimeException as it might contain valuable information about what caused the exception and where it was triggered.

Also-by: Martin van Wingerden <[email protected]>
Signed-off-by: Hilbrand Bouwkamp <[email protected]>
Signed-off-by: Pascal Larin <[email protected]>
ne0h pushed a commit to ne0h/openhab-addons that referenced this pull request Sep 15, 2019
* Added configuring devices by deviceId

This makes it resilient to ip address changes.
It's not using the mac address for this because the mac address can also be changed (by the user).

- Better explained dependency on discovery service.
- Added logging on RuntimeException as it might contain valuable information about what caused the exception and where it was triggered.

Also-by: Martin van Wingerden <[email protected]>
Signed-off-by: Hilbrand Bouwkamp <[email protected]>
Signed-off-by: Maximilian Hess <[email protected]>
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.

3 participants