use of org.openhab.binding.onewire.internal.device.OwChannelConfig in project openhab-addons by openhab.
the class BAE091xSensorThingHandler method configureThingChannels.
@Override
protected void configureThingChannels() {
ThingUID thingUID = getThing().getUID();
logger.debug("configuring sensors for {}", thingUID);
BAE091xHandlerConfiguration configuration = getConfig().as(BAE091xHandlerConfiguration.class);
Set<OwChannelConfig> wantedChannel = new HashSet<>();
wantedChannel.addAll(SENSOR_TYPE_CHANNEL_MAP.getOrDefault(sensorType, Set.of()));
// Pin1:
switch(configuration.pin1) {
case CONFIG_BAE_PIN_DISABLED:
break;
case CONFIG_BAE_PIN_COUNTER:
wantedChannel.add(new OwChannelConfig(CHANNEL_COUNTER, CHANNEL_TYPE_UID_BAE_COUNTER));
break;
default:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "unknown configuration option for pin 1");
return;
}
// Pin2:
switch(configuration.pin2) {
case CONFIG_BAE_PIN_DISABLED:
break;
case CONFIG_BAE_PIN_OUT:
wantedChannel.add(new OwChannelConfig(CHANNEL_DIGITAL2, CHANNEL_TYPE_UID_BAE_DIGITAL_OUT, "Digital Out Pin 2"));
break;
case CONFIG_BAE_PIN_PWM:
wantedChannel.add(new OwChannelConfig(CHANNEL_PWM_DUTY3, CHANNEL_TYPE_UID_BAE_PWM_DUTY, "Duty Cycle PWM 3"));
wantedChannel.add(new OwChannelConfig(CHANNEL_PWM_FREQ1, CHANNEL_TYPE_UID_BAE_PWM_FREQUENCY, "Frequency PWM 1/3"));
break;
default:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "unknown configuration option for pin 2");
return;
}
// Pin6:
switch(configuration.pin6) {
case CONFIG_BAE_PIN_DISABLED:
break;
case CONFIG_BAE_PIN_PIO:
wantedChannel.add(new OwChannelConfig(CHANNEL_DIGITAL6, CHANNEL_TYPE_UID_BAE_PIO, "PIO Pin 6"));
break;
case CONFIG_BAE_PIN_PWM:
wantedChannel.add(new OwChannelConfig(CHANNEL_PWM_DUTY4, CHANNEL_TYPE_UID_BAE_PWM_DUTY, "Duty Cycle PWM 4"));
wantedChannel.add(new OwChannelConfig(CHANNEL_PWM_FREQ2, CHANNEL_TYPE_UID_BAE_PWM_FREQUENCY, "Frequency PWM 2/4"));
break;
default:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "unknown configuration option for pin 6");
return;
}
// Pin7:
switch(configuration.pin7) {
case CONFIG_BAE_PIN_DISABLED:
break;
case CONFIG_BAE_PIN_ANALOG:
wantedChannel.add(new OwChannelConfig(CHANNEL_VOLTAGE, CHANNEL_TYPE_UID_BAE_ANALOG, "Analog Input"));
break;
case CONFIG_BAE_PIN_OUT:
wantedChannel.add(new OwChannelConfig(CHANNEL_DIGITAL7, CHANNEL_TYPE_UID_BAE_DIGITAL_OUT, "Digital Out Pin 7"));
break;
case CONFIG_BAE_PIN_PWM:
wantedChannel.add(new OwChannelConfig(CHANNEL_PWM_DUTY2, CHANNEL_TYPE_UID_BAE_PWM_DUTY, "Duty Cycle PWM 2"));
wantedChannel.add(new OwChannelConfig(CHANNEL_PWM_FREQ2, CHANNEL_TYPE_UID_BAE_PWM_FREQUENCY, "Frequency PWM 2/4"));
break;
default:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "unknown configuration option for pin 7");
return;
}
// Pin8:
switch(configuration.pin8) {
case CONFIG_BAE_PIN_DISABLED:
break;
case CONFIG_BAE_PIN_IN:
wantedChannel.add(new OwChannelConfig(CHANNEL_DIGITAL8, CHANNEL_TYPE_UID_BAE_DIN, "Digital In Pin 8"));
break;
case CONFIG_BAE_PIN_OUT:
wantedChannel.add(new OwChannelConfig(CHANNEL_DIGITAL8, CHANNEL_TYPE_UID_BAE_DOUT, "Digital Out Pin 8"));
break;
case CONFIG_BAE_PIN_PWM:
wantedChannel.add(new OwChannelConfig(CHANNEL_PWM_DUTY1, CHANNEL_TYPE_UID_BAE_PWM_DUTY, "Duty Cycle PWM 1"));
wantedChannel.add(new OwChannelConfig(CHANNEL_PWM_FREQ1, CHANNEL_TYPE_UID_BAE_PWM_FREQUENCY, "Frequency PWM 1/3"));
break;
default:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "unknown configuration option for pin 8");
return;
}
ThingBuilder thingBuilder = editThing();
// remove unwanted channels
Set<String> existingChannelIds = thing.getChannels().stream().map(channel -> channel.getUID().getId()).collect(Collectors.toSet());
Set<String> wantedChannelIds = wantedChannel.stream().map(channelConfig -> channelConfig.channelId).collect(Collectors.toSet());
existingChannelIds.stream().filter(channelId -> !wantedChannelIds.contains(channelId)).forEach(channelId -> removeChannelIfExisting(thingBuilder, channelId));
// add or update wanted channels
wantedChannel.stream().forEach(channelConfig -> {
addChannelIfMissingAndEnable(thingBuilder, channelConfig);
});
updateThing(thingBuilder.build());
try {
sensors.get(0).configureChannels();
} catch (OwException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
return;
}
validConfig = true;
updateStatus(ThingStatus.UNKNOWN, ThingStatusDetail.NONE);
}
use of org.openhab.binding.onewire.internal.device.OwChannelConfig in project openhab-addons by openhab.
the class AdvancedMultisensorThingHandler method configureThingChannels.
@Override
protected void configureThingChannels() {
Configuration configuration = getConfig();
ThingBuilder thingBuilder = editThing();
// delete unwanted channels
Set<String> existingChannelIds = thing.getChannels().stream().map(channel -> channel.getUID().getId()).collect(Collectors.toSet());
Set<String> wantedChannelIds = SENSOR_TYPE_CHANNEL_MAP.get(sensorType).stream().map(channelConfig -> channelConfig.channelId).collect(Collectors.toSet());
wantedChannelIds.add(CHANNEL_TEMPERATURE);
wantedChannelIds.add(CHANNEL_HUMIDITY);
existingChannelIds.stream().filter(channelId -> !wantedChannelIds.contains(channelId)).forEach(channelId -> removeChannelIfExisting(thingBuilder, channelId));
// add or update wanted channels
SENSOR_TYPE_CHANNEL_MAP.get(sensorType).stream().forEach(channelConfig -> {
addChannelIfMissingAndEnable(thingBuilder, channelConfig);
});
// temperature channel
if (configuration.containsKey(CONFIG_TEMPERATURESENSOR) && configuration.get(CONFIG_TEMPERATURESENSOR).equals("DS18B20")) {
addChannelIfMissingAndEnable(thingBuilder, new OwChannelConfig(CHANNEL_TEMPERATURE, CHANNEL_TYPE_UID_TEMPERATURE_POR_RES), 1);
} else {
addChannelIfMissingAndEnable(thingBuilder, new OwChannelConfig(CHANNEL_TEMPERATURE, CHANNEL_TYPE_UID_TEMPERATURE));
}
// humidity channel
addChannelIfMissingAndEnable(thingBuilder, new OwChannelConfig(CHANNEL_HUMIDITY, CHANNEL_TYPE_UID_HUMIDITY), new Configuration(new HashMap<String, Object>() {
private static final long serialVersionUID = 1L;
{
put(CONFIG_HUMIDITY, "/HIH4000/humidity");
}
}));
// configure light channel
if (sensorType == OwSensorType.AMS_S || sensorType == OwSensorType.BMS_S) {
if (hwRevision <= 13) {
((DS2438) sensors.get(0)).setLightSensorType(LightSensorType.ELABNET_V1);
} else {
((DS2438) sensors.get(0)).setLightSensorType(LightSensorType.ELABNET_V2);
}
}
updateThing(thingBuilder.build());
try {
for (AbstractOwDevice sensor : sensors) {
sensor.configureChannels();
}
} catch (OwException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
return;
}
validConfig = true;
updateStatus(ThingStatus.UNKNOWN, ThingStatusDetail.NONE);
}
Aggregations