use of org.openhab.core.thing.binding.builder.ThingBuilder in project openhab-addons by openhab.
the class AirQualityStationHandler method discoverAttributes.
private void discoverAttributes() {
getAirQualityData().ifPresent(data -> {
// Update thing properties
Map<String, String> properties = new HashMap<>();
properties.put(ATTRIBUTIONS, data.getAttributions());
PointType serverLocation = locationProvider.getLocation();
if (serverLocation != null) {
PointType stationLocation = new PointType(data.getCity().getGeo());
double distance = serverLocation.distanceFrom(stationLocation).doubleValue();
properties.put(DISTANCE, new QuantityType<>(distance / 1000, KILO(SIUnits.METRE)).toString());
}
// Search and remove missing pollutant channels
List<Channel> channels = new ArrayList<>(getThing().getChannels());
Stream.of(Pollutant.values()).forEach(pollutant -> {
String groupName = pollutant.name().toLowerCase();
double value = data.getIaqiValue(pollutant);
channels.removeIf(channel -> value == -1 && groupName.equals(channel.getUID().getGroupId()));
});
// Update thing configuration
Configuration config = editConfiguration();
config.put(AirQualityConfiguration.STATION_ID, data.getStationId());
ThingBuilder thingBuilder = editThing();
thingBuilder.withChannels(channels).withConfiguration(config).withProperties(properties).withLocation(data.getCity().getName());
updateThing(thingBuilder.build());
});
}
use of org.openhab.core.thing.binding.builder.ThingBuilder in project openhab-addons by openhab.
the class IntesisBoxHandler method addChannel.
public void addChannel(String channelId, String itemType) {
if (thing.getChannel(channelId) == null) {
logger.trace("Channel '{}' for UID to be added", channelId);
ThingBuilder thingBuilder = editThing();
final ChannelTypeUID channelTypeUID = new ChannelTypeUID(BINDING_ID, channelId);
Channel channel = ChannelBuilder.create(new ChannelUID(getThing().getUID(), channelId), itemType).withType(channelTypeUID).withKind(ChannelKind.STATE).build();
thingBuilder.withChannel(channel);
updateThing(thingBuilder.build());
}
if (limits.containsKey(channelId)) {
List<StateOption> options = new ArrayList<>();
for (String mode : limits.get(channelId)) {
options.add(new StateOption(mode, mode.substring(0, 1).toUpperCase() + mode.substring(1).toLowerCase()));
}
intesisStateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), channelId), options);
}
}
use of org.openhab.core.thing.binding.builder.ThingBuilder in project openhab-addons by openhab.
the class JablotronJa100FHandler method createPGChannel.
private void createPGChannel(String name, String label) {
ChannelTypeUID pgmStatus = new ChannelTypeUID(BINDING_ID, "pgm_state");
ThingBuilder thingBuilder = editThing();
Channel channel = ChannelBuilder.create(new ChannelUID(thing.getUID(), name), "Switch").withLabel(label).withType(pgmStatus).build();
thingBuilder.withChannel(channel);
updateThing(thingBuilder.build());
}
use of org.openhab.core.thing.binding.builder.ThingBuilder in project openhab-addons by openhab.
the class JablotronJa100FHandler method createStateChannel.
private void createStateChannel(String name, String label) {
ChannelTypeUID alarmStatus = new ChannelTypeUID(BINDING_ID, "ja100f_alarm_state");
ThingBuilder thingBuilder = editThing();
Channel channel = ChannelBuilder.create(new ChannelUID(thing.getUID(), name), "String").withLabel(label).withType(alarmStatus).build();
thingBuilder.withChannel(channel);
updateThing(thingBuilder.build());
}
use of org.openhab.core.thing.binding.builder.ThingBuilder in project openhab-addons by openhab.
the class EcobeeSensorThingHandler method updateCapabilityChannels.
private void updateCapabilityChannels(RemoteSensorCapabilityDTO capability) {
ChannelUID uid = new ChannelUID(thing.getUID(), capability.type);
Channel channel = thing.getChannel(uid);
if (channel == null) {
logger.debug("SensorThing: Create channel '{}'", uid);
ThingBuilder thingBuilder;
thingBuilder = editThing();
channel = ChannelBuilder.create(uid, getAcceptedItemType(capability.type)).withLabel("Sensor " + WordUtils.capitalize(capability.type)).withType(getChannelTypeUID(capability.type)).build();
thingBuilder.withChannel(channel);
updateThing(thingBuilder.build());
}
logger.trace("Capability '{}' has type '{}' with value '{}'", capability.id, capability.type, capability.value);
updateCapabilityState(capability.type, capability.value);
}
Aggregations