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

[hue] Internationalization of discovery results #11501

Merged
merged 1 commit into from
Nov 8, 2021
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 @@ -33,6 +33,8 @@
import org.openhab.binding.hue.internal.handler.sensors.TapSwitchHandler;
import org.openhab.binding.hue.internal.handler.sensors.TemperatureHandler;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.i18n.LocaleProvider;
import org.openhab.core.i18n.TranslationProvider;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
Expand Down Expand Up @@ -68,10 +70,15 @@ public class HueThingHandlerFactory extends BaseThingHandlerFactory {
.flatMap(i -> i).collect(Collectors.toSet()));

private final HueStateDescriptionProvider stateDescriptionProvider;
private final TranslationProvider i18nProvider;
private final LocaleProvider localeProvider;

@Activate
public HueThingHandlerFactory(final @Reference HueStateDescriptionProvider stateDescriptionProvider) {
public HueThingHandlerFactory(final @Reference HueStateDescriptionProvider stateDescriptionProvider,
final @Reference TranslationProvider i18nProvider, final @Reference LocaleProvider localeProvider) {
this.stateDescriptionProvider = stateDescriptionProvider;
this.i18nProvider = i18nProvider;
this.localeProvider = localeProvider;
}

@Override
Expand Down Expand Up @@ -142,7 +149,7 @@ private ThingUID getThingUID(ThingTypeUID thingTypeUID, String id, @Nullable Thi
@Override
protected @Nullable ThingHandler createHandler(Thing thing) {
if (HueBridgeHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
return new HueBridgeHandler((Bridge) thing, stateDescriptionProvider);
return new HueBridgeHandler((Bridge) thing, stateDescriptionProvider, i18nProvider, localeProvider);
} else if (HueLightHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
return new HueLightHandler(thing, stateDescriptionProvider);
} else if (DimmerSwitchHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ public HueDeviceDiscoveryService() {
@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof HueBridgeHandler) {
hueBridgeHandler = (HueBridgeHandler) handler;
HueBridgeHandler localHandler = (HueBridgeHandler) handler;
hueBridgeHandler = localHandler;
bridgeUID = handler.getThing().getUID();
i18nProvider = localHandler.getI18nProvider();
localeProvider = localHandler.getLocaleProvider();
}
}

Expand Down Expand Up @@ -275,8 +278,14 @@ public void addGroupDiscovery(FullGroup group) {
Map<String, Object> properties = new HashMap<>();
properties.put(GROUP_ID, group.getId());

String name = String.format("%s (%s)", "0".equals(group.getId()) ? "All lights" : group.getName(),
group.getType());
String name;
if ("0".equals(group.getId())) {
name = "@text/discovery.group.all_lights.label";
} else if ("Room".equals(group.getType())) {
name = group.getName();
} else {
name = String.format("%s (%s)", group.getName(), group.getType());
}
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withThingType(THING_TYPE_GROUP)
.withProperties(properties).withBridge(localBridgeUID).withRepresentationProperty(GROUP_ID)
.withLabel(name).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import org.openhab.binding.hue.internal.exceptions.UnauthorizedException;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.config.core.status.ConfigStatusMessage;
import org.openhab.core.i18n.LocaleProvider;
import org.openhab.core.i18n.TranslationProvider;
import org.openhab.core.library.types.HSBType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.StringType;
Expand Down Expand Up @@ -98,6 +100,8 @@ public class HueBridgeHandler extends ConfigStatusBridgeHandler implements HueCl

private final Logger logger = LoggerFactory.getLogger(HueBridgeHandler.class);
private final HueStateDescriptionProvider stateDescriptionOptionProvider;
private final TranslationProvider i18nProvider;
private final LocaleProvider localeProvider;

private final Map<String, FullLight> lastLightStates = new ConcurrentHashMap<>();
private final Map<String, FullSensor> lastSensorStates = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -403,9 +407,12 @@ private void setBridgeSceneChannelStateOptions(List<Scene> scenes, Map<String, F

private List<String> consoleScenesList = new ArrayList<>();

public HueBridgeHandler(Bridge bridge, HueStateDescriptionProvider stateDescriptionOptionProvider) {
public HueBridgeHandler(Bridge bridge, HueStateDescriptionProvider stateDescriptionOptionProvider,
TranslationProvider i18nProvider, LocaleProvider localeProvider) {
super(bridge);
this.stateDescriptionOptionProvider = stateDescriptionOptionProvider;
this.i18nProvider = i18nProvider;
this.localeProvider = localeProvider;
}

@Override
Expand Down Expand Up @@ -1040,4 +1047,12 @@ public Collection<ConfigStatusMessage> getConfigStatus() {
return List.of();
}
}

public TranslationProvider getI18nProvider() {
return i18nProvider;
}

public LocaleProvider getLocaleProvider() {
return localeProvider;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,7 @@ actionInputFadeTimeLabel = FadeTime
actionInputFadeTimeDesc = The fade time to use for the light command in ms.
actionLabel = send a light command with a custom fade time
actionDesc = Send a light command with a custom fade time.

# discovery results

discovery.group.all_lights.label = All lights