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

[insteon] Rewrite with backward compatibility #17146

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

Conversation

jsetton
Copy link
Contributor

@jsetton jsetton commented Jul 25, 2024

This is a rewrite of the Insteon binding adding some much needed improvements while keeping some of its core code refactored. Apart from simplifying the user experience by retrieving all the configuration directly from the device when possible, and improving the way the Insteon things are configured in MainUI, here is an exhaustive list of the changes:

  • introduced device configuration automated determination
  • converted mode-based number items to string type with descriptive states
  • added number items uom support
  • added distinct scenes and x10 device things
  • added distinct bridge things for supported hub/plm devices
  • added button event trigger channels
  • added device products configuration layer
  • added device link database support
  • added device cache storage
  • added device operating flags controls
  • added modem configuration flags controls
  • added related devices synchronization feature
  • added heartbeat timeout monitor
  • added ability to link/unlink a device to the modem
  • added ability to add missing default links
  • added link database & scene management support
  • added scene state support
  • added new i3 devices basic support
  • added ezrain sprinkler device support
  • revamped console commands with auto-completion support
  • improved discovery service
  • improved thing status

Since the configuration process was revamp, this would require existing users of the binding to reconfigure their Insteon setup.
However, backward compatibility is provided as some of the legacy code was kept with some adaptation to interface with updated core components. Existing device legacy things connected to a network legacy bridge will be migrated to the legacy-device thing type while still keeping the same ids to prevent any breakage.

@jsetton jsetton requested a review from a team as a code owner July 25, 2024 02:26
@jsetton jsetton force-pushed the insteon branch 3 times, most recently from 41db1f9 to f096ded Compare July 26, 2024 05:08
@lsiepel
Copy link
Contributor

lsiepel commented Jul 26, 2024

I thought you would wait for me to comment on the other PR, but youre going fast. I'll try to look at this and the other PR (might close that one) next week.

@jsetton jsetton force-pushed the insteon branch 2 times, most recently from 56505e5 to 70b99f3 Compare July 26, 2024 16:51
@jsetton
Copy link
Contributor Author

jsetton commented Jul 26, 2024

As I mentioned in the other PR, I wanted to make sure that the binding would be maintainable by having the legacy classes use the updated folder structure with minimal redundancy. Anyway, I think the way I structured this PR might be easier to review.

@jsetton jsetton force-pushed the insteon branch 8 times, most recently from 7dfc222 to c45173e Compare August 1, 2024 14:18
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/insteon-binding-beta-4-1-0-5-0-0/154128/1

@lsiepel
Copy link
Contributor

lsiepel commented Aug 29, 2024

Spend some time looking at this PR. Pretty impressed by the documentation. On a high level i think this is the way forward. There also seem to be changed in the legacy part that i can't directly link as essential to integrating. They also don;t seem wrong, but with a large rewrite as this regressions are expected.
I guess you already tested and upgrade your own setup, did you share this version and/or do you have test results from others?
I'll try to complete my review soon, but 157 files.. this might take some time.

@jsetton
Copy link
Contributor Author

jsetton commented Sep 3, 2024

I guess you already tested and upgrade your own setup,

I did test the legacy code with my own setup without any issue. There are no change in behavior for existing users. As far as the new changes, I have been solely using my implementation for couple years now to test and fix any issues.

did you share this version

Yes, it is available in the marketplace as beta version.

do you have test results from others?

I have had several test results for the new changes from others over the previous PR comments and community forum posts. I have reached out to several of them asking for feedback and if possible to test the backward compatibility support.

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/insteon-binding-beta-4-1-0-5-0-0/154128/8

@lsiepel
Copy link
Contributor

lsiepel commented Sep 3, 2024

Can you try not to force push as then it is hard to review / track changes.

@jsetton
Copy link
Contributor Author

jsetton commented Sep 4, 2024

@lsiepel I did some refactoring around the transport message code improving the separation between a Msg object and the MsgDefinition object it is derived from. Let me know if you want me to push this change to this PR or wait until you finish reviewing the current changes.

@lsiepel
Copy link
Contributor

lsiepel commented Sep 5, 2024

@lsiepel I did some refactoring around the transport message code improving the separation between a Msg object and the MsgDefinition object it is derived from. Let me know if you want me to push this change to this PR or wait until you finish reviewing the current changes.

Let us first finish this PR before we do further refactoring.

Copy link
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

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

Not covered everything yet (114 / 157 files), but made some progress revieweing this PR and don't want to hold it back.

bundles/org.openhab.binding.insteon/README.md Outdated Show resolved Hide resolved
bundles/org.openhab.binding.insteon/README.md Outdated Show resolved Hide resolved
bundles/org.openhab.binding.insteon/README.md Outdated Show resolved Hide resolved
Comment on lines -110 to +116
<channel-type id="acDelay">
<channel-type id="legacyAcDelay">
Copy link
Contributor

Choose a reason for hiding this comment

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

Updating the channel type id's for existing thing's would require upgrade instructions. (applies to all changed type id's in this file.

Copy link
Contributor Author

@jsetton jsetton Sep 18, 2024

Choose a reason for hiding this comment

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

This is handled by InsteonLegacyDeviceHandler during the initialization as it creates all the channels using the legacy types. There is no need for upgrade instructions.

<item-type>Switch</item-type>
<label>Fast On/Off Button H</label>
<config-description-ref uri="channel-type:insteon:keypad-button-fastonoff"/>
<config-description-ref uri="channel-type:insteon:legacy-keypad-button-fastonoff"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect this to be a breaking change.
If you have a legacy device configured, and you upgrade to this binding, the configuration uri is not updated in the store (json db) resulting in an unconfigured device. Noit 100% if this can be fixed with upgrade instructions, so depending on your test result you might 1. add it to the ugprade instructions or 2. revert this change.

Copy link
Contributor Author

@jsetton jsetton Sep 18, 2024

Choose a reason for hiding this comment

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

This is why I added a way to store the existing channel configuration in InsteonLegacyNetworkHandler which are restored during the InsteonLegacyDeviceHandler initialization, part of the migration process.

Newly created channels will use the new config description uri along with the stored channel configuration since the channel uid isn't changing. I was able to test it with my setup.

private void changeThingType(ThingTypeUID thingTypeUID, @Nullable BridgeHandler bridgeHandler) {
if (bridgeHandler instanceof InsteonLegacyNetworkHandler legacyNetworkHandler) {
Map<ChannelUID, Configuration> channelConfigs = getThing().getChannels().stream()
.collect(Collectors.toMap(Channel::getUID, Channel::getConfiguration));
legacyNetworkHandler.addChannelConfigs(channelConfigs);
}
changeThingType(thingTypeUID, getConfig());
}

private Channel createChannel(String channelId, String channelTypeId, ThingHandlerCallback callback) {
ChannelUID channelUID = new ChannelUID(getThing().getUID(), channelId);
ChannelTypeUID channelTypeUID = new ChannelTypeUID(InsteonBindingConstants.BINDING_ID,
CHANNEL_TYPE_ID_PREFIX + StringUtils.capitalize(channelTypeId));
Configuration channelConfig = getChannelConfig(channelUID);
Channel channel = getThing().getChannel(channelUID);
if (channel == null) {
channel = callback.createChannelBuilder(channelUID, channelTypeUID).withConfiguration(channelConfig)
.build();
}
return channel;
}

Signed-off-by: jsetton <jeremy.setton@gmail.com>
* introduced device configuration automated determination
* converted mode-based number items to string type with descriptive states
* added number items uom support
* added scenes and x10 device things
* added distinct bridge things for supported hub/plm devices
* added button event trigger channels
* added device products configuration layer
* added device link database support
* added device cache storage
* added device operating flags controls
* added modem configuration flags controls
* added related devices synchronization feature
* added heartbeat timeout monitor
* added ability to link/unlink a device to the modem
* added ability to add missing default links
* added link database & scene management support
* added scene state support
* added new i3 devices basic support
* added ezrain sprinkler device support
* revamped console commands with auto-completion support
* improved discovery service
* improved thing status

Signed-off-by: jsetton <jeremy.setton@gmail.com>
Signed-off-by: jsetton <jeremy.setton@gmail.com>
Signed-off-by: jsetton <jeremy.setton@gmail.com>
Signed-off-by: jsetton <jeremy.setton@gmail.com>
Signed-off-by: jsetton <jeremy.setton@gmail.com>
@jsetton
Copy link
Contributor Author

jsetton commented Sep 18, 2024

Sorry about the force push, I had to rebase my changes to clear a merge conflict.

All the changes I made related to your code review starts from 2eabeb9.

Signed-off-by: jsetton <jeremy.setton@gmail.com>
Signed-off-by: jsetton <jeremy.setton@gmail.com>
Signed-off-by: jsetton <jeremy.setton@gmail.com>
Signed-off-by: jsetton <jeremy.setton@gmail.com>
Signed-off-by: jsetton <jeremy.setton@gmail.com>
Signed-off-by: jsetton <jeremy.setton@gmail.com>
Signed-off-by: jsetton <jeremy.setton@gmail.com>
Signed-off-by: jsetton <jeremy.setton@gmail.com>
Signed-off-by: jsetton <jeremy.setton@gmail.com>
Signed-off-by: jsetton <jeremy.setton@gmail.com>
Signed-off-by: jsetton <jeremy.setton@gmail.com>
Signed-off-by: jsetton <jeremy.setton@gmail.com>
Signed-off-by: jsetton <jeremy.setton@gmail.com>
Signed-off-by: jsetton <jeremy.setton@gmail.com>
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