Skip to content

Commit

Permalink
Suppress log entry about unknown device model for child devices
Browse files Browse the repository at this point in the history
Signed-off-by: David Pace <dev@davidpace.de>
  • Loading branch information
david-pace committed Feb 27, 2024
1 parent 06dc7b2 commit 5c1cda0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public class ThingDiscoveryService extends AbstractThingHandlerDiscoveryService<

private final Logger logger = LoggerFactory.getLogger(ThingDiscoveryService.class);

/**
* Device model representing logical child devices of Light Control II
*/
static final String DEVICE_MODEL_LIGHT_CONTROL_CHILD_DEVICE = "MICROMODULE_LIGHT_ATTACHED";

protected static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(
BoschSHCBindingConstants.THING_TYPE_INWALL_SWITCH, BoschSHCBindingConstants.THING_TYPE_TWINGUARD,
BoschSHCBindingConstants.THING_TYPE_WINDOW_CONTACT, BoschSHCBindingConstants.THING_TYPE_WINDOW_CONTACT_2,
Expand Down Expand Up @@ -285,6 +290,15 @@ private String getNiceName(String name, String roomName) {
if (thingTypeId != null) {
return new ThingTypeUID(BoschSHCBindingConstants.BINDING_ID, thingTypeId.getId());
}

if (DEVICE_MODEL_LIGHT_CONTROL_CHILD_DEVICE.equals(device.deviceModel)) {
// Light Control II exposes a parent device and two child devices.
// We only add one thing for the parent device and the child devices are logically included.
// Therefore we do not need to add separate things for the child devices and need to suppress the
// log entry about the unknown device model.
return null;
}

logger.debug("Unknown deviceModel '{}'! Please create a support request issue for this unknown device model.",
device.deviceModel);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@
package org.openhab.binding.boschshc.internal.discovery;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.UUID;
Expand Down Expand Up @@ -261,4 +267,12 @@ void testAddUserDefinedStates() {
// two calls for the two devices expected
verify(discoveryListener, times(2)).thingDiscovered(any(), any());
}

@Test
void getThingTypeUIDLightControl2ChildDevice() {
Device device = new Device();
device.deviceModel = ThingDiscoveryService.DEVICE_MODEL_LIGHT_CONTROL_CHILD_DEVICE;

assertThat(fixture.getThingTypeUID(device), is(nullValue()));
}
}

0 comments on commit 5c1cda0

Please sign in to comment.