use of org.openhab.core.events.Event in project openhab-core by openhab.
the class FirmwareUpdateServiceTest method firmwareStatusPropagatedRegularly.
@Test
public void firmwareStatusPropagatedRegularly() throws Exception {
final FirmwareStatusInfo unknownInfo = createUnknownInfo(thing3.getUID());
final FirmwareStatusInfo upToDateInfo = createUpToDateInfo(thing2.getUID());
final FirmwareStatusInfo updateExecutableInfoFw112 = createUpdateExecutableInfo(thing1.getUID(), V112);
assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V111));
assertThat(thing2.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V112));
updateConfig(1, 0, TimeUnit.SECONDS);
waitForAssert(() -> {
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventPublisherMock, times(3)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw112);
assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), upToDateInfo);
assertFirmwareStatusInfoEvent(THING3_UID, eventCaptor.getAllValues().get(2), unknownInfo);
});
reset(eventPublisherMock);
// Simulate addition of extra firmware provider
when(firmwareRegistryMock.getFirmware(eq(thing2), eq(VALPHA))).thenReturn(null);
when(firmwareRegistryMock.getFirmwares(any(Thing.class))).thenAnswer(invocation -> {
Thing thing = (Thing) invocation.getArguments()[0];
if (THING_TYPE_UID_WITHOUT_FW.equals(thing.getThingTypeUID()) || THING_TYPE_UID2.equals(thing.getThingTypeUID())) {
return Collections.emptySet();
} else {
return Set.of(FW113_EN);
}
});
waitForAssert(() -> {
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventPublisherMock, times(2)).post(eventCaptor.capture());
FirmwareStatusInfo updateExecutableInfoFw113 = createUpdateExecutableInfo(thing1.getUID(), V113);
assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw113);
updateExecutableInfoFw113 = createUpdateExecutableInfo(thing2.getUID(), V113);
assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), updateExecutableInfoFw113);
});
reset(eventPublisherMock);
// Simulate removed firmware provider - get back everything as it was initially
initialFirmwareRegistryMocking();
waitForAssert(() -> {
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventPublisherMock, times(2)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw112);
assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), upToDateInfo);
});
}
use of org.openhab.core.events.Event in project openhab-core by openhab.
the class FirmwareUpdateServiceTest method testUpdateFirmware.
@Test
public void testUpdateFirmware() {
final FirmwareStatusInfo upToDateInfo = createUpToDateInfo(thing1.getUID());
final FirmwareStatusInfo updateExecutableInfoFw112 = createUpdateExecutableInfo(thing1.getUID(), V112);
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(updateExecutableInfoFw112));
firmwareUpdateService.updateFirmware(THING1_UID, V112, null);
waitForAssert(() -> {
assertThat(thing1.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V112.toString()));
});
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING1_UID), is(upToDateInfo));
// verify that the corresponding events are sent
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventPublisherMock, times(2)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw112);
assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(1), upToDateInfo);
}
use of org.openhab.core.events.Event in project openhab-core by openhab.
the class FirmwareUpdateServiceTest method testUpdateFirmwareDowngrade.
@Test
public void testUpdateFirmwareDowngrade() {
final FirmwareStatusInfo upToDateInfo = createUpToDateInfo(thing2.getUID());
final FirmwareStatusInfo updateExecutableInfoFw112 = createUpdateExecutableInfo(thing2.getUID(), V112);
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING2_UID), is(upToDateInfo));
firmwareUpdateService.updateFirmware(THING2_UID, V111, null);
waitForAssert(() -> {
assertThat(thing2.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is(V111.toString()));
});
assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING2_UID), is(updateExecutableInfoFw112));
// verify that the corresponding events are sent
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventPublisherMock, times(2)).post(eventCaptor.capture());
assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(0), upToDateInfo);
assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), updateExecutableInfoFw112);
}
use of org.openhab.core.events.Event in project openhab-core by openhab.
the class AddonEventFactory method createEventByType.
@Override
protected Event createEventByType(String eventType, String topic, String payload, @Nullable String source) throws Exception {
if (topic.endsWith(ADDON_FAILURE_EVENT_TOPIC_POSTFIX)) {
String[] properties = deserializePayload(payload, String[].class);
Event event = new AddonEvent(topic, payload, properties[0], properties[1]);
return event;
} else {
String id = deserializePayload(payload, String.class);
Event event = new AddonEvent(topic, payload, id);
return event;
}
}
use of org.openhab.core.events.Event in project openhab-core by openhab.
the class ExpireManagerTest method testIgnoreStateUpdateDoesNotExtendExpiryOnStateUpdate.
@Test
void testIgnoreStateUpdateDoesNotExtendExpiryOnStateUpdate() throws InterruptedException, ItemNotFoundException {
Item testItem = new NumberItem(ITEMNAME);
when(itemRegistryMock.getItem(ITEMNAME)).thenReturn(testItem);
when(metadataRegistryMock.get(METADATA_KEY)).thenReturn(config("2s", Map.of(ExpireConfig.CONFIG_IGNORE_STATE_UPDATES, true)));
Event event = ItemEventFactory.createCommandEvent(ITEMNAME, new DecimalType(1));
expireManager.receive(event);
Thread.sleep(1500L);
event = ItemEventFactory.createStateEvent(ITEMNAME, new DecimalType(1));
expireManager.receive(event);
Thread.sleep(1500L);
verify(eventPublisherMock, times(1)).post(any());
}
Aggregations