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
[DLinkSmartHome] add DSP-W215 Smart Plug #8648
Conversation
add DSP-W215 Smart Plug (2.5.x PR: openhab#8361) Signed-off-by: Pascal Bies <pascal.bies@k-lens.de>
Travis tests have failedHey @pasbi, |
<version>3.0.0-SNAPSHOT</version> | ||
<version>2.5.9-SNAPSHOT</version> |
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.
Is this change intentional?
* | ||
* @author Pascal Bies - Initial contribution | ||
*/ | ||
public abstract class DLinkHNAP { |
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 add the NonNullByDefault annotation.
public void start(ScheduledExecutorService scheduler) { | ||
try { | ||
pollFuture = scheduler.scheduleWithFixedDelay(this::poller, 0, DETECT_POLL_S, TimeUnit.SECONDS); | ||
} catch (Exception e) { |
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.
What type of exception do you expect here? Can you specify the concrete type?
} catch (Exception e) { | ||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR, | ||
"Unexpected internal error."); | ||
logger.error("Failed to start http client or scheduler."); |
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.
Bindings should only log to error if something severe happened, like the detection of a bug in your code. This could be warn.
Additionally, you could remove the logging statement at all, as updateStatus()
already does the logging.
} catch (CommunicationException e) { | ||
logger.error("Failed to get quantity (communication error)."); | ||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR); | ||
} catch (SOAPException e) { | ||
logger.error("Unexpected internal error."); | ||
updateStatus(ThingStatus.OFFLINE); | ||
} |
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.
You could include the exceptions message as third parameter to updateStatus()
to display the error in the UI.
You could remove the logging statement, as updateStatus()
already does the logging.
try { | ||
DLinkSmartPlugHandler.this.setState((OnOffType) command); | ||
} catch (ClassCastException e) { | ||
logger.error("Unexpected command type for channel '{}'.", DLinkSmartHomeBindingConstants.STATE); | ||
} |
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.
Unchecked exceptions should be cought only if necessary. Please check the type beforehand.
@Override | ||
public void dispose() { | ||
super.dispose(); | ||
hnap.stop(); |
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.
The super destructor should be called at the end of the implementing method.
private ChannelUID getChannelUID(final String name) { | ||
Channel channel = thing.getChannel(name); | ||
if (channel == null) { | ||
logger.error("Did not find channel '{}'.", name); |
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.
See above. this could be warn.
logger.error("Unexpected channel: '{}'.", channelID); | ||
throw new IllegalArgumentException("Unexpected channel."); |
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.
Uncought unchecked exceptions are logged by the framework. You could remove the logging message.
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0" | ||
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd"> | ||
|
||
<channel-type id="current_consumption" advanced="true"> |
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.
Is there are reason why you made all Channels advanced?
Can you also address the comments in #8361 that are shown under |
@pasbi What is the status of this PR? |
Sorry -- I'm totally confused right now. Please be patient with me. That confusion comes from two points:
So my proposal was to close this PR and start over again with the approach proposed in #8361 :
I'm willing to do that, but I need some advice from the code owner @MikeJMajor to refactor. please also see #8361 (comment) Edit: I've now updated my IDE and looked through the existing code, Everything is ready to start. |
I'm not quite sure what you are confused about. You already managed to migrate the code from 2.5 to 3.x. Next step would be to incorporate the review feedback, I gave in this PR. Maybe you could ask a concrete question, that @MikeJMajor or anybody else can answer? |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/developing-a-binding-for-dlink-plugs/24122/69 |
I'm planning to continue working on this PR, but I'm quite busy atm, unfortunately. If others want to contribute, go ahead 😄 |
Feel free to reopen this PR when you continue working on it. |
Note: the original PR (2.5.x) is #8361.
DESCRIPTION
Add support for a thing.
Read temperature, state and total/current power consumption of the thing, set the state of the thing.
No.
Yes, in the README.md
Not necessary.
Yes.
https://www.openhab.org/docs/developer/development/guidelines.html
It passed all the checks, and I'm not aware of any violation. Yet, I'm not sure. BTW, the link is broken.
https://www.openhab.org/docs/developer/development/bindings.html#static-code-analysis
Yes.
Yes.
TESTING