Skip to content

Commit

Permalink
Configure zone on panel even if the channel is not yet linked (openha…
Browse files Browse the repository at this point in the history
…b#13380)

Signed-off-by: Haavar Valeur <haavar@haavar.com>
Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
  • Loading branch information
haavar authored and andrasU committed Nov 12, 2022
1 parent da97fda commit 7186e6f
Showing 1 changed file with 39 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,53 +328,49 @@ private String constructSettingsPayload() {
payload.setDiscovery(config.discovery);
this.getThing().getChannels().forEach(channel -> {
// ChannelUID channelId = channel.getUID();
if (isLinked(channel.getUID())) {
// adds linked channels to list based on last value of Channel ID
// which is set to a number
// get the zone number in integer form
ZoneConfiguration zoneConfig = channel.getConfiguration().as(ZoneConfiguration.class);
// if the pin is an actuator add to actuator string
// else add to sensor string
// This is determined based off of the accepted item type, contact types are sensors
// switch types are actuators
String channelType = channel.getChannelTypeUID().getAsString();
logger.debug("The channeltypeID is: {}", channelType);
KonnectedModuleGson module = new KonnectedModuleGson();
module.setZone(thingID, zoneConfig.zone);
if (channelType.contains(CHANNEL_SWITCH)) {
payload.addSensor(module);
logger.trace("Channel {} will be configured on the konnected alarm panel as a switch", channel);
} else if (channelType.contains(CHANNEL_ACTUATOR)) {
payload.addActuators(module);
logger.trace("Channel {} will be configured on the konnected alarm panel as an actuator", channel);
} else if (channelType.contains(CHANNEL_HUMIDITY)) {
// the humidity channels do not need to be added because the supported sensor (dht22) is added under
// the temp sensor
logger.trace("Channel {} is a humidity channel.", channel);
} else if (channelType.contains(CHANNEL_TEMPERATURE)) {
logger.trace("Channel {} will be configured on the konnected alarm panel as a temperature sensor",
// adds channels to list based on last value of Channel ID
// which is set to a number
// get the zone number in integer form
ZoneConfiguration zoneConfig = channel.getConfiguration().as(ZoneConfiguration.class);
// if the pin is an actuator add to actuator string
// else add to sensor string
// This is determined based off of the accepted item type, contact types are sensors
// switch types are actuators
String channelType = channel.getChannelTypeUID().getAsString();
logger.debug("The channeltypeID is: {}", channelType);
KonnectedModuleGson module = new KonnectedModuleGson();
module.setZone(thingID, zoneConfig.zone);
if (channelType.contains(CHANNEL_SWITCH)) {
payload.addSensor(module);
logger.trace("Channel {} will be configured on the konnected alarm panel as a switch", channel);
} else if (channelType.contains(CHANNEL_ACTUATOR)) {
payload.addActuators(module);
logger.trace("Channel {} will be configured on the konnected alarm panel as an actuator", channel);
} else if (channelType.contains(CHANNEL_HUMIDITY)) {
// the humidity channels do not need to be added because the supported sensor (dht22) is added under
// the temp sensor
logger.trace("Channel {} is a humidity channel.", channel);
} else if (channelType.contains(CHANNEL_TEMPERATURE)) {
logger.trace("Channel {} will be configured on the konnected alarm panel as a temperature sensor",
channel);
module.setPollInterval(zoneConfig.pollInterval);
logger.trace("The Temperature Sensor Type is: {} ", zoneConfig.dht22);
if (zoneConfig.dht22) {
// add it as a dht22 module
payload.addDht22(module);
logger.trace(
"Channel {} will be configured on the konnected alarm panel as a DHT22 temperature sensor",
channel);
module.setPollInterval(zoneConfig.pollInterval);
logger.trace("The Temperature Sensor Type is: {} ", zoneConfig.dht22);
if (zoneConfig.dht22) {
// add it as a dht22 module
payload.addDht22(module);
logger.trace(
"Channel {} will be configured on the konnected alarm panel as a DHT22 temperature sensor",
channel);
} else {
// add to payload as a DS18B20 module if the parameter is false
payload.addDs18b20(module);
logger.trace(
"Channel {} will be configured on the konnected alarm panel as a DS18B20 temperature sensor",
channel);
}
} else {
logger.debug("Channel {} is of type {} which is not supported by the konnected binding", channel,
channelType);
// add to payload as a DS18B20 module if the parameter is false
payload.addDs18b20(module);
logger.trace(
"Channel {} will be configured on the konnected alarm panel as a DS18B20 temperature sensor",
channel);
}
} else {
logger.debug("The Channel {} is not linked to an item", channel.getUID());
logger.debug("Channel {} is of type {} which is not supported by the konnected binding", channel,
channelType);
}
});
// Create Json to Send to Konnected Module
Expand Down

0 comments on commit 7186e6f

Please sign in to comment.