mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[hue] Internationalization of discovery results (#11501)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
dfe577aec5
commit
c79fd06256
@ -33,6 +33,8 @@ import org.openhab.binding.hue.internal.handler.sensors.PresenceHandler;
|
|||||||
import org.openhab.binding.hue.internal.handler.sensors.TapSwitchHandler;
|
import org.openhab.binding.hue.internal.handler.sensors.TapSwitchHandler;
|
||||||
import org.openhab.binding.hue.internal.handler.sensors.TemperatureHandler;
|
import org.openhab.binding.hue.internal.handler.sensors.TemperatureHandler;
|
||||||
import org.openhab.core.config.core.Configuration;
|
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.Bridge;
|
||||||
import org.openhab.core.thing.Thing;
|
import org.openhab.core.thing.Thing;
|
||||||
import org.openhab.core.thing.ThingTypeUID;
|
import org.openhab.core.thing.ThingTypeUID;
|
||||||
@ -68,10 +70,15 @@ public class HueThingHandlerFactory extends BaseThingHandlerFactory {
|
|||||||
.flatMap(i -> i).collect(Collectors.toSet()));
|
.flatMap(i -> i).collect(Collectors.toSet()));
|
||||||
|
|
||||||
private final HueStateDescriptionProvider stateDescriptionProvider;
|
private final HueStateDescriptionProvider stateDescriptionProvider;
|
||||||
|
private final TranslationProvider i18nProvider;
|
||||||
|
private final LocaleProvider localeProvider;
|
||||||
|
|
||||||
@Activate
|
@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.stateDescriptionProvider = stateDescriptionProvider;
|
||||||
|
this.i18nProvider = i18nProvider;
|
||||||
|
this.localeProvider = localeProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -142,7 +149,7 @@ public class HueThingHandlerFactory extends BaseThingHandlerFactory {
|
|||||||
@Override
|
@Override
|
||||||
protected @Nullable ThingHandler createHandler(Thing thing) {
|
protected @Nullable ThingHandler createHandler(Thing thing) {
|
||||||
if (HueBridgeHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
|
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())) {
|
} else if (HueLightHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
|
||||||
return new HueLightHandler(thing, stateDescriptionProvider);
|
return new HueLightHandler(thing, stateDescriptionProvider);
|
||||||
} else if (DimmerSwitchHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
|
} else if (DimmerSwitchHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
|
||||||
|
@ -111,8 +111,11 @@ public class HueDeviceDiscoveryService extends AbstractDiscoveryService
|
|||||||
@Override
|
@Override
|
||||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||||
if (handler instanceof HueBridgeHandler) {
|
if (handler instanceof HueBridgeHandler) {
|
||||||
hueBridgeHandler = (HueBridgeHandler) handler;
|
HueBridgeHandler localHandler = (HueBridgeHandler) handler;
|
||||||
|
hueBridgeHandler = localHandler;
|
||||||
bridgeUID = handler.getThing().getUID();
|
bridgeUID = handler.getThing().getUID();
|
||||||
|
i18nProvider = localHandler.getI18nProvider();
|
||||||
|
localeProvider = localHandler.getLocaleProvider();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,8 +278,14 @@ public class HueDeviceDiscoveryService extends AbstractDiscoveryService
|
|||||||
Map<String, Object> properties = new HashMap<>();
|
Map<String, Object> properties = new HashMap<>();
|
||||||
properties.put(GROUP_ID, group.getId());
|
properties.put(GROUP_ID, group.getId());
|
||||||
|
|
||||||
String name = String.format("%s (%s)", "0".equals(group.getId()) ? "All lights" : group.getName(),
|
String name;
|
||||||
group.getType());
|
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)
|
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withThingType(THING_TYPE_GROUP)
|
||||||
.withProperties(properties).withBridge(localBridgeUID).withRepresentationProperty(GROUP_ID)
|
.withProperties(properties).withBridge(localBridgeUID).withRepresentationProperty(GROUP_ID)
|
||||||
.withLabel(name).build();
|
.withLabel(name).build();
|
||||||
|
@ -54,6 +54,8 @@ import org.openhab.binding.hue.internal.exceptions.LinkButtonException;
|
|||||||
import org.openhab.binding.hue.internal.exceptions.UnauthorizedException;
|
import org.openhab.binding.hue.internal.exceptions.UnauthorizedException;
|
||||||
import org.openhab.core.config.core.Configuration;
|
import org.openhab.core.config.core.Configuration;
|
||||||
import org.openhab.core.config.core.status.ConfigStatusMessage;
|
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.HSBType;
|
||||||
import org.openhab.core.library.types.OnOffType;
|
import org.openhab.core.library.types.OnOffType;
|
||||||
import org.openhab.core.library.types.StringType;
|
import org.openhab.core.library.types.StringType;
|
||||||
@ -98,6 +100,8 @@ public class HueBridgeHandler extends ConfigStatusBridgeHandler implements HueCl
|
|||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(HueBridgeHandler.class);
|
private final Logger logger = LoggerFactory.getLogger(HueBridgeHandler.class);
|
||||||
private final HueStateDescriptionProvider stateDescriptionOptionProvider;
|
private final HueStateDescriptionProvider stateDescriptionOptionProvider;
|
||||||
|
private final TranslationProvider i18nProvider;
|
||||||
|
private final LocaleProvider localeProvider;
|
||||||
|
|
||||||
private final Map<String, FullLight> lastLightStates = new ConcurrentHashMap<>();
|
private final Map<String, FullLight> lastLightStates = new ConcurrentHashMap<>();
|
||||||
private final Map<String, FullSensor> lastSensorStates = new ConcurrentHashMap<>();
|
private final Map<String, FullSensor> lastSensorStates = new ConcurrentHashMap<>();
|
||||||
@ -403,9 +407,12 @@ public class HueBridgeHandler extends ConfigStatusBridgeHandler implements HueCl
|
|||||||
|
|
||||||
private List<String> consoleScenesList = new ArrayList<>();
|
private List<String> consoleScenesList = new ArrayList<>();
|
||||||
|
|
||||||
public HueBridgeHandler(Bridge bridge, HueStateDescriptionProvider stateDescriptionOptionProvider) {
|
public HueBridgeHandler(Bridge bridge, HueStateDescriptionProvider stateDescriptionOptionProvider,
|
||||||
|
TranslationProvider i18nProvider, LocaleProvider localeProvider) {
|
||||||
super(bridge);
|
super(bridge);
|
||||||
this.stateDescriptionOptionProvider = stateDescriptionOptionProvider;
|
this.stateDescriptionOptionProvider = stateDescriptionOptionProvider;
|
||||||
|
this.i18nProvider = i18nProvider;
|
||||||
|
this.localeProvider = localeProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1040,4 +1047,12 @@ public class HueBridgeHandler extends ConfigStatusBridgeHandler implements HueCl
|
|||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TranslationProvider getI18nProvider() {
|
||||||
|
return i18nProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocaleProvider getLocaleProvider() {
|
||||||
|
return localeProvider;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -225,3 +225,7 @@ actionInputFadeTimeLabel = FadeTime
|
|||||||
actionInputFadeTimeDesc = The fade time to use for the light command in ms.
|
actionInputFadeTimeDesc = The fade time to use for the light command in ms.
|
||||||
actionLabel = send a light command with a custom fade time
|
actionLabel = send a light command with a custom fade time
|
||||||
actionDesc = 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
|
||||||
|
Loading…
Reference in New Issue
Block a user