Skip to content

Commit

Permalink
Call, Contact, Image items: Don't create command descr from state des…
Browse files Browse the repository at this point in the history
…cr (#4097)

* Contact item: Fix command descriptions provided even though commands are not accepted

If a state description is set on a contact item, currently a command description is automatically created as well.
This is wrong as contact items do not accept commands (except refresh) and caused the UI to display a control for the default (list) widget for these contacts.

* Also fix Call and Image items & Allow explicitly setting command description

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
  • Loading branch information
florian-h05 committed Mar 3, 2024
1 parent bca1010 commit f4d6089
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,9 @@ public void setCategory(@Nullable String category) {

@Override
public @Nullable CommandDescription getCommandDescription(@Nullable Locale locale) {
if (commandDescriptionService != null) {
CommandDescription commandDescription = commandDescriptionService.getCommandDescription(this.name, locale);
if (commandDescription != null) {
return commandDescription;
}
CommandDescription commandOptions = getCommandOptions(locale);
if (commandOptions != null) {
return commandOptions;
}

StateDescription stateDescription = getStateDescription(locale);
Expand Down Expand Up @@ -504,6 +502,17 @@ protected void logSetTypeError(TimeSeries timeSeries) {
getName(), getClass().getSimpleName());
}

protected @Nullable CommandDescription getCommandOptions(@Nullable Locale locale) {
if (commandDescriptionService != null) {
CommandDescription commandDescription = commandDescriptionService.getCommandDescription(this.name, locale);
if (commandDescription != null) {
return commandDescription;
}
}

return null;
}

private CommandDescription stateOptions2CommandOptions(StateDescription stateDescription) {
CommandDescriptionBuilder builder = CommandDescriptionBuilder.create();
stateDescription.getOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
package org.openhab.core.library.items;

import java.util.List;
import java.util.Locale;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.items.GenericItem;
import org.openhab.core.library.CoreItemFactory;
import org.openhab.core.library.types.StringListType;
import org.openhab.core.types.Command;
import org.openhab.core.types.CommandDescription;
import org.openhab.core.types.RefreshType;
import org.openhab.core.types.State;
import org.openhab.core.types.TimeSeries;
Expand Down Expand Up @@ -68,4 +71,9 @@ public void setTimeSeries(TimeSeries timeSeries) {
logSetTypeError(timeSeries);
}
}

@Override
public @Nullable CommandDescription getCommandDescription(@Nullable Locale locale) {
return getCommandOptions(locale);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
package org.openhab.core.library.items;

import java.util.List;
import java.util.Locale;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.items.GenericItem;
import org.openhab.core.library.CoreItemFactory;
import org.openhab.core.library.types.OpenClosedType;
import org.openhab.core.types.Command;
import org.openhab.core.types.CommandDescription;
import org.openhab.core.types.RefreshType;
import org.openhab.core.types.State;
import org.openhab.core.types.TimeSeries;
Expand Down Expand Up @@ -68,4 +71,9 @@ public void setTimeSeries(TimeSeries timeSeries) {
logSetTypeError(timeSeries);
}
}

@Override
public @Nullable CommandDescription getCommandDescription(@Nullable Locale locale) {
return getCommandOptions(locale);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
package org.openhab.core.library.items;

import java.util.List;
import java.util.Locale;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.items.GenericItem;
import org.openhab.core.library.CoreItemFactory;
import org.openhab.core.library.types.RawType;
import org.openhab.core.types.Command;
import org.openhab.core.types.CommandDescription;
import org.openhab.core.types.RefreshType;
import org.openhab.core.types.State;
import org.openhab.core.types.TimeSeries;
Expand Down Expand Up @@ -66,4 +69,9 @@ public void setTimeSeries(TimeSeries timeSeries) {
logSetTypeError(timeSeries);
}
}

@Override
public @Nullable CommandDescription getCommandDescription(@Nullable Locale locale) {
return getCommandOptions(locale);
}
}

0 comments on commit f4d6089

Please sign in to comment.