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

[intellicenter2] Initial contribution #13334

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

valdisrigdon
Copy link

Adds a new binding for the IntelliCenter 2 pool automation system from
Pentair.

This adds a new binding for Pentair pool automation systems using IntelliCenter 2. This is different from the Pentair binding as the protocol is completely different and does not require any additional hardware to activate.

I have been running a version of this binding on 3.2 for a few months without any issues.

@valdisrigdon valdisrigdon requested a review from a team as a code owner August 29, 2022 19:15
@jlaur jlaur changed the title - [intellicenter2] - new binding [intellicenter2] Initial contribution Aug 29, 2022
@jlaur jlaur added the new binding If someone has started to work on a binding. For a new binding PR. label Aug 29, 2022
@valdisrigdon valdisrigdon force-pushed the intellicenter2 branch 3 times, most recently from 39798d3 to 4643a69 Compare August 29, 2022 19:44
@valdisrigdon
Copy link
Author

@jlaur This is ready for a review -- how can I get this assigned for a review?

Copy link
Contributor

@jlaur jlaur 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 your contribution! I have just started a review, but will need to do it in an incremental way to not keep you waiting for too long. So I have provided some initial feedback, which I hope you can use to get started, while I will continue my review as soon as possible.

Comment on lines +3 to +76
_Give some details about what this binding is meant for - a protocol, system, specific device._

_If possible, provide some resources like pictures (only PNG is supported currently), a video, etc. to give an impression of what can be done with this binding._
_You can place such resources into a `doc` folder next to this README.md._

_Put each sentence in a separate line to improve readability of diffs._

## Supported Things

_Please describe the different supported things / devices including their ThingTypeUID within this section._
_Which different types are supported, which models were tested etc.?_
_Note that it is planned to generate some part of this based on the XML files within ```src/main/resources/OH-INF/thing``` of your binding._

- `bridge`: Short description of the Bridge, if any
- `sample`: Short description of the Thing with the ThingTypeUID `sample`

## Discovery

_Describe the available auto-discovery features here._
_Mention for what it works and what needs to be kept in mind when using it._

## Binding Configuration

_If your binding requires or supports general configuration settings, please create a folder ```cfg``` and place the configuration file ```<bindingId>.cfg``` inside it._
_In this section, you should link to this file and provide some information about the options._
_The file could e.g. look like:_

```
# Configuration for the IntelliCenter2 Binding
#
# Default secret key for the pairing of the IntelliCenter2 Thing.
# It has to be between 10-40 (alphanumeric) characters.
# This may be changed by the user for security reasons.
secret=openHABSecret
```

_Note that it is planned to generate some part of this based on the information that is available within ```src/main/resources/OH-INF/binding``` of your binding._

_If your binding does not offer any generic configurations, you can remove this section completely._

## Thing Configuration

_Describe what is needed to manually configure a thing, either through the UI or via a thing-file._
_This should be mainly about its mandatory and optional configuration parameters._

_Note that it is planned to generate some part of this based on the XML files within ```src/main/resources/OH-INF/thing``` of your binding._

### `sample` Thing Configuration

| Name | Type | Description | Default | Required | Advanced |
|-----------------|---------|---------------------------------------|---------|----------|----------|
| hostname | text | Hostname or IP address of the device | N/A | yes | no |
| password | text | Password to access the device | N/A | yes | no |
| refreshInterval | integer | Interval the device is polled in sec. | 600 | no | yes |

## Channels

_Here you should provide information about available channel types, what their meaning is and how they can be used._

_Note that it is planned to generate some part of this based on the XML files within ```src/main/resources/OH-INF/thing``` of your binding._

| Channel | Type | Read/Write | Description |
|---------|--------|------------|-----------------------------|
| control | Switch | RW | This is the control channel |

## Full Example

_Provide a full usage example based on textual configuration files._
_*.things, *.items examples are mandatory as textual configuration is well used by many users._
_*.sitemap examples are optional._

## Any custom content here!

_Feel free to add additional sections for whatever you think should also be mentioned about your binding!_
Copy link
Contributor

Choose a reason for hiding this comment

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

Please document the binding in this file.

*/
package org.openhab.binding.intellicenter2.internal;

import org.apache.commons.lang3.builder.ToStringBuilder;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this dependency, see #7722.

Copy link
Contributor

@lsiepel lsiepel Feb 24, 2023

Choose a reason for hiding this comment

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

}
}
} catch (Exception e) {
logger.error("Unable to discover IntelliCenter2 hardware for {}", discoveryArg, e);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this will not prevent the binding from working, log level should be reduced.

"Unable to connect to host " + config.hostname);
} catch (Exception e) {
logger.error("Error initializing.", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR, e.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

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

This thing status detail is not correct, i.e. it doesn't correspond to the status. Please see https://www.openhab.org/docs/concepts/things.html#status-details.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

String msg = String.format("unknown host name: %s", config.hostname);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, msg);
} catch (IOException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be COMMUNICATION_ERROR. In this case, how will the binding come online?

} catch (Exception ignored) {
}
}
updateStatus(ThingStatus.OFFLINE);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not needed.

updateProperty("propertyName", systemInfo.getPropertyName());
updateProperty("version", systemInfo.getVersion());
logger.info("Bridge is ONLINE.");
if (!systemInfo.getIntellicenterVersion().equals("1.064")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the difference between systemInfo.getVersion() and systemInfo.getIntellicenterVersion()? Would it make sense to keep both as properties?

*
* @see Circuit
*/
@SuppressWarnings("UnstableApiUsage")
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason for this?

Copy link
Contributor

@jlaur jlaur left a comment

Choose a reason for hiding this comment

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

I have provided some additional comments after second review session. In general the code looks good!

*
* @see IntelliBrite
*/
@SuppressWarnings("UnstableApiUsage")
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason for this?

updateState(channelUID, OnOffType.from(pool.isHeating()));
break;
default:
logger.error("Unable to update state for {}", channelUID);
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not prevent the binding from working, so could be reduced to log level WARN. See https://next.openhab.org/docs/developer/guidelines.html#f-logging

Comment on lines 76 to 88
@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
super.handleCommand(channelUID, command);
switch (channelUID.getId()) {
case CHANNEL_PUMP_GPM:
if (command instanceof DecimalType) {
// var request = ICRequest.setParamList(
// new RequestObject(getObjectName(), Map.of(Attribute.GPM, command.toString())));
// getProtocol().submit(request);
}
break;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be removed, or did you mean to implement something in this override?

// get an updated model from IC
final ICProtocol protocol = getProtocol();
if (protocol == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a valid combination, it should most likely be CONFIGURATION_ERROR, assuming that protocol being null is caused by missing reference to parent bridge handler. See https://www.openhab.org/docs/concepts/things.html#status-details

getProtocol().subscribe(this, model.asRequestObject());
updateStatus(ThingStatus.ONLINE);
updateState(model);
} catch (Exception e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to catch Exception here, or could you handle only specializations?

logger.trace("Sending request {}", jsonRequest);
write(jsonRequest);
} catch (Exception e) {
logger.error("Error writing request {}", jsonRequest);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this log needed - where will the exception thrown below be caught?

subscriptions.get(request.getObjectName()).add(listener);
String response = getUnchecked(submit(ICRequest.requestParamList(request))).getResponse();
if (!"200".equals(response)) {
logger.error("Error subscribing listener {} for request {}", listener, request);
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose this should not prevent the binding from working, so probably log level can be reduced?

protected void updateState(ChannelUID channelUID, Body pool) {
switch (channelUID.getId()) {
case CHANNEL_CURRENT_TEMPERATURE:
updateState(channelUID, new DecimalType(pool.getCurrentTemperature()));
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe channel type is defined as "Number:Temperature", so you need QuantityType here for correctly supporting UoM:

Suggested change
updateState(channelUID, new DecimalType(pool.getCurrentTemperature()));
updateState(channelUID, new QuantityType<>(pool.getCurrentTemperature()), SIUnits.CELSIUS);

updateState(channelUID, new DecimalType(pool.getCurrentTemperature()));
break;
case CHANNEL_TARGET_TEMPERATURE:
updateState(channelUID, new DecimalType(pool.getTargetTemperature()));
Copy link
Contributor

Choose a reason for hiding this comment

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

And the same here.

@lsiepel
Copy link
Contributor

lsiepel commented Feb 24, 2023

@valdisrigdon do you need anything to proceed with this PR?

@lsiepel lsiepel added the awaiting feedback Awaiting feedback from the pull request author label Feb 24, 2023
@valdisrigdon
Copy link
Author

@isiepel nope, I just need time to respond and update based on all the feedback.

@lsiepel lsiepel removed the awaiting feedback Awaiting feedback from the pull request author label Feb 24, 2023
@jlaur jlaur added the awaiting feedback Awaiting feedback from the pull request author label Apr 26, 2023
@gutermhub
Copy link

Hey guys, do you need help merging suggested changes / getting this over the line?
I'd love to see intellicenter2 support in openhab, will try to help.

@valdisrigdon
Copy link
Author

@gutermhub I would love some help merging the suggested changes and getting this over the line. I've been running with this build and it's been super stable.

@lsiepel
Copy link
Contributor

lsiepel commented Apr 29, 2024

ve some help merging the suggested changes and getting this over the line. I've been running with this build and it's been super stable.

Anything specific you need help with? There are some review comments to address, you also need to get the PR updated from the main branch.

@lsiepel lsiepel added the stale As soon as a PR is marked stale, it can be removed 6 months later. label Sep 6, 2024
@lsiepel
Copy link
Contributor

lsiepel commented Dec 5, 2024

Unless someone want to continue on this PR, i'm about to close this due to inactivty. There are some comments open without repsonses for over two years.

@valdisrigdon
Copy link
Author

Could you keep it open? I just picked this up the other day after upgrading to 4.2.0. I'll push up the changes and address the comments soon.

@lsiepel
Copy link
Contributor

lsiepel commented Dec 5, 2024

just picked this up the other day after upg

Ah great, will leave this open.

@lsiepel lsiepel removed the stale As soon as a PR is marked stale, it can be removed 6 months later. label Dec 5, 2024
<parent>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
<version>4.3.0-SNAPSHOT</version>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<version>4.3.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>

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.

5 participants