mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-25 19:55:48 +01:00
Disable AutoUpdateManager for GroupItems (#1862)
* Disable AutoUpdateManager for GroupItems Fixes #1330 Signed-off-by: Simon Lamon <simonlamon93@hotmail.com>
This commit is contained in:
parent
85fcb7b141
commit
34a3487e3e
@ -12,12 +12,14 @@
|
||||
*/
|
||||
package org.openhab.core.thing.internal;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.events.EventPublisher;
|
||||
import org.openhab.core.items.GroupItem;
|
||||
import org.openhab.core.items.Item;
|
||||
import org.openhab.core.items.Metadata;
|
||||
import org.openhab.core.items.MetadataKey;
|
||||
@ -142,7 +144,7 @@ public class AutoUpdateManager {
|
||||
if (command instanceof State) {
|
||||
final State state = (State) command;
|
||||
|
||||
Recommendation autoUpdate = shouldAutoUpdate(itemName);
|
||||
Recommendation autoUpdate = shouldAutoUpdate(item);
|
||||
|
||||
// consider user-override via item meta-data
|
||||
MetadataKey key = new MetadataKey(AUTOUPDATE_KEY, itemName);
|
||||
@ -185,9 +187,15 @@ public class AutoUpdateManager {
|
||||
}
|
||||
}
|
||||
|
||||
private Recommendation shouldAutoUpdate(String itemName) {
|
||||
private Recommendation shouldAutoUpdate(Item item) {
|
||||
String itemName = item.getName();
|
||||
Recommendation ret = Recommendation.REQUIRED;
|
||||
|
||||
// check if the item is a group item
|
||||
if (item instanceof GroupItem) {
|
||||
return Recommendation.DONT;
|
||||
}
|
||||
|
||||
List<ChannelUID> linkedChannelUIDs = new ArrayList<>();
|
||||
for (ItemChannelLink link : itemChannelLinkRegistry.getLinks(itemName)) {
|
||||
linkedChannelUIDs.add(link.getLinkedUID());
|
||||
@ -279,14 +287,14 @@ public class AutoUpdateManager {
|
||||
// Look for class hierarchy
|
||||
for (Class<?> state : item.getAcceptedDataTypes()) {
|
||||
try {
|
||||
if (!state.isEnum() && state.newInstance().getClass().isAssignableFrom(newState.getClass())) {
|
||||
if (!state.isEnum() && state.getDeclaredConstructor().newInstance().getClass()
|
||||
.isAssignableFrom(newState.getClass())) {
|
||||
isAccepted = true;
|
||||
break;
|
||||
}
|
||||
} catch (InstantiationException e) {
|
||||
logger.warn("InstantiationException on {}", e.getMessage(), e); // Should never happen
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.warn("IllegalAccessException on {}", e.getMessage(), e); // Should never happen
|
||||
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException
|
||||
| InvocationTargetException e) {
|
||||
logger.warn("Exception on {}", e.getMessage(), e); // Should never happen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import org.mockito.quality.Strictness;
|
||||
import org.openhab.core.events.Event;
|
||||
import org.openhab.core.events.EventPublisher;
|
||||
import org.openhab.core.items.GenericItem;
|
||||
import org.openhab.core.items.GroupItem;
|
||||
import org.openhab.core.items.MetadataRegistry;
|
||||
import org.openhab.core.items.events.ItemCommandEvent;
|
||||
import org.openhab.core.items.events.ItemEventFactory;
|
||||
@ -72,6 +73,8 @@ public class AutoUpdateManagerTest {
|
||||
private static final ChannelUID CHANNEL_UID_HANDLER_MISSING = new ChannelUID(THING_UID_HANDLER_MISSING, "channel1");
|
||||
private ItemCommandEvent event;
|
||||
private GenericItem item;
|
||||
private ItemCommandEvent groupEvent;
|
||||
private GroupItem groupItem;
|
||||
|
||||
private @Mock ChannelTypeRegistry channelTypeRegistryMock;
|
||||
private @Mock EventPublisher eventPublisherMock;
|
||||
@ -92,6 +95,9 @@ public class AutoUpdateManagerTest {
|
||||
event = ItemEventFactory.createCommandEvent(ITEM_NAME, new StringType("AFTER"));
|
||||
item = new StringItem(ITEM_NAME);
|
||||
item.setState(new StringType("BEFORE"));
|
||||
groupEvent = ItemEventFactory.createCommandEvent("groupTest", new StringType("AFTER"));
|
||||
groupItem = new GroupItem("groupTest", new StringItem("test"));
|
||||
groupItem.setState(new StringType("BEFORE"));
|
||||
|
||||
when(iclRegistryMock.getLinks(eq(ITEM_NAME))).then(answer -> links);
|
||||
|
||||
@ -349,4 +355,13 @@ public class AutoUpdateManagerTest {
|
||||
assertPredictionEvent("AFTER", null);
|
||||
assertStateEvent("AFTER", AutoUpdateManager.EVENT_SOURCE_OPTIMISTIC); // no?
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoUpdateDisabledForGroupItems() {
|
||||
groupItem.addMember(item);
|
||||
aum.receiveCommand(groupEvent, groupItem);
|
||||
groupItem.removeMember(item);
|
||||
|
||||
assertNothingHappened();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user