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

[hdpowerview] Remove deprecated scene channels #14033

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import org.openhab.binding.hdpowerview.internal.exceptions.HubInvalidResponseException;
import org.openhab.binding.hdpowerview.internal.exceptions.HubMaintenanceException;
import org.openhab.binding.hdpowerview.internal.exceptions.HubProcessingException;
import org.openhab.core.library.CoreItemFactory;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Channel;
Expand All @@ -63,7 +62,6 @@
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.BaseBridgeHandler;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.thing.type.ChannelTypeUID;
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
Expand Down Expand Up @@ -100,7 +98,6 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
private List<SceneCollection> sceneCollectionCache = new CopyOnWriteArrayList<>();
private List<ScheduledEvent> scheduledEventCache = new CopyOnWriteArrayList<>();
private Instant userDataUpdated = Instant.MIN;
private Boolean deprecatedChannelsCreated = false;

private final ChannelTypeUID sceneChannelTypeUID = new ChannelTypeUID(HDPowerViewBindingConstants.BINDING_ID,
HDPowerViewBindingConstants.CHANNELTYPE_SCENE_ACTIVATE);
Expand Down Expand Up @@ -181,7 +178,6 @@ private void initializeChannels() {
sceneCache.clear();
sceneCollectionCache.clear();
scheduledEventCache.clear();
deprecatedChannelsCreated = false;
}

public HDPowerViewWebTargets getWebTargets() {
Expand Down Expand Up @@ -481,52 +477,9 @@ private List<Scene> updateSceneChannels()

updateThing(editThing().withChannels(channelBuilder.build()).build());

createDeprecatedSceneChannels(scenes);

return scenes;
}

/**
* Create backwards compatible scene channels if any items configured before release 3.2
* are still linked. Users should have a reasonable amount of time to migrate to the new
* scene channels that are connected to a channel group.
*/
private void createDeprecatedSceneChannels(List<Scene> scenes) {
if (deprecatedChannelsCreated) {
// Only do this once.
return;
}
ChannelGroupUID channelGroupUid = new ChannelGroupUID(thing.getUID(),
HDPowerViewBindingConstants.CHANNEL_GROUP_SCENES);
for (Scene scene : scenes) {
String channelId = Integer.toString(scene.id);
ChannelUID newChannelUid = new ChannelUID(channelGroupUid, channelId);
ChannelUID deprecatedChannelUid = new ChannelUID(getThing().getUID(), channelId);
String description = translationProvider.getText("dynamic-channel.scene-activate.deprecated.description",
scene.getName());
Channel channel = ChannelBuilder.create(deprecatedChannelUid, CoreItemFactory.SWITCH)
.withType(sceneChannelTypeUID).withLabel(scene.getName()).withDescription(description).build();
logger.debug("Creating deprecated channel '{}' ('{}') to probe for linked items", deprecatedChannelUid,
scene.getName());
updateThing(editThing().withChannel(channel).build());
if (this.isLinked(deprecatedChannelUid) && !this.isLinked(newChannelUid)) {
logger.warn("Created deprecated channel '{}' ('{}'), please link items to '{}' instead",
deprecatedChannelUid, scene.getName(), newChannelUid);
} else {
if (this.isLinked(newChannelUid)) {
logger.debug("Removing deprecated channel '{}' ('{}') since new channel '{}' is linked",
deprecatedChannelUid, scene.getName(), newChannelUid);

} else {
logger.debug("Removing deprecated channel '{}' ('{}') since it has no linked items",
deprecatedChannelUid, scene.getName());
}
updateThing(editThing().withoutChannel(deprecatedChannelUid).build());
}
}
deprecatedChannelsCreated = true;
}

private List<SceneCollection> fetchSceneCollections()
throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
SceneCollections sceneCollections = webTargets.getSceneCollections();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ offline.gone.shade-unknown-to-hub = Shade is unknown to Hub
# dynamic channels

dynamic-channel.scene-activate.description = Activates the scene ''{0}''
dynamic-channel.scene-activate.deprecated.description = DEPRECATED: Activates the scene ''{0}''
dynamic-channel.scene-group-activate.description = Activates the scene group ''{0}''
dynamic-channel.automation-enabled.description = Enables/disables the automation ''{0}''
dynamic-channel.automation-enabled.label = {0}, {1}, {2}
Expand Down