use of org.openhab.core.events.Event in project openhab-addons by openhab.
the class LightsAndGroupsTests method changeGroupItemSwitchState.
@Test
public void changeGroupItemSwitchState() {
assertThat(((HueStatePlug) cs.ds.groups.get("10").action).on, is(false));
String body = "{'on':true}";
Response response = commonSetup.client.target(commonSetup.basePath + "/testuser/groups/10/action").request().put(Entity.json(body));
assertEquals(200, response.getStatus());
assertThat(response.readEntity(String.class), containsString("success"));
assertThat(((HueStatePlug) cs.ds.groups.get("10").action).on, is(true));
verify(commonSetup.eventPublisher).post(argThat((Event t) -> {
assertThat(t.getPayload(), is("{\"type\":\"OnOff\",\"value\":\"ON\"}"));
return true;
}));
}
use of org.openhab.core.events.Event in project openhab-addons by openhab.
the class LightsAndGroupsTests method changeSwitchState.
@Test
public void changeSwitchState() {
assertThat(((HueStatePlug) cs.ds.lights.get("1").state).on, is(false));
String body = "{'on':true}";
Response response = commonSetup.client.target(commonSetup.basePath + "/testuser/lights/1/state").request().put(Entity.json(body));
assertEquals(200, response.getStatus());
assertThat(response.readEntity(String.class), containsString("success"));
assertThat(((HueStatePlug) cs.ds.lights.get("1").state).on, is(true));
verify(commonSetup.eventPublisher).post(argThat((Event t) -> {
assertThat(t.getPayload(), is("{\"type\":\"OnOff\",\"value\":\"ON\"}"));
return true;
}));
}
use of org.openhab.core.events.Event in project openhab-core by openhab.
the class AddonResource method postFailureEvent.
private void postFailureEvent(String addonId, @Nullable String msg) {
Event event = AddonEventFactory.createAddonFailureEvent(addonId, msg);
eventPublisher.post(event);
}
use of org.openhab.core.events.Event in project openhab-core by openhab.
the class SitemapSubscriptionService method receive.
@Override
public void receive(Event event) {
if (event instanceof ItemStatePredictedEvent) {
ItemStatePredictedEvent prediction = (ItemStatePredictedEvent) event;
Item item = itemUIRegistry.get(prediction.getItemName());
if (item instanceof GroupItem) {
// members and predictions aren't really possible in that case (or at least would be highly complex).
return;
}
for (PageChangeListener pageChangeListener : pageChangeListeners.values()) {
if (prediction.isConfirmation()) {
pageChangeListener.keepCurrentState(item);
} else {
pageChangeListener.changeStateTo(item, prediction.getPredictedState());
}
}
} else if (event instanceof ChannelDescriptionChangedEvent) {
ChannelDescriptionChangedEvent channelDescriptionChangedEvent = (ChannelDescriptionChangedEvent) event;
channelDescriptionChangedEvent.getLinkedItemNames().forEach(itemName -> {
for (PageChangeListener pageChangeListener : pageChangeListeners.values()) {
pageChangeListener.descriptionChanged(itemName);
}
});
}
}
use of org.openhab.core.events.Event in project openhab-core by openhab.
the class InboxOSGiTest method assertThatInboxEventSubscribersReceiveEventsAboutDiscoveryResultChanges.
@Test
public void assertThatInboxEventSubscribersReceiveEventsAboutDiscoveryResultChanges() {
ThingTypeUID thingTypeUID = new ThingTypeUID("some", "thing");
ThingUID thingUID = new ThingUID(thingTypeUID, "uid");
final AsyncResultWrapper<Event> receivedEvent = new AsyncResultWrapper<>();
EventSubscriber inboxEventSubscriber = new EventSubscriber() {
@Override
public void receive(Event event) {
receivedEvent.set(event);
}
@Override
public Set<String> getSubscribedEventTypes() {
return Set.of(InboxAddedEvent.TYPE, InboxRemovedEvent.TYPE, InboxUpdatedEvent.TYPE);
}
@Override
@Nullable
public EventFilter getEventFilter() {
return null;
}
};
registerService(inboxEventSubscriber);
// add discovery result
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID).withTTL(DEFAULT_TTL).build();
addDiscoveryResult(discoveryResult);
waitForAssert(() -> assertThat(receivedEvent.getWrappedObject(), not(nullValue())));
assertThat(receivedEvent.getWrappedObject(), is(instanceOf(InboxAddedEvent.class)));
receivedEvent.reset();
// update discovery result
discoveryResult = DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID).withTTL(DEFAULT_TTL).build();
addDiscoveryResult(discoveryResult);
waitForAssert(() -> assertThat(receivedEvent.getWrappedObject(), not(nullValue())));
assertThat(receivedEvent.getWrappedObject(), is(instanceOf(InboxUpdatedEvent.class)));
receivedEvent.reset();
// remove discovery result
removeDiscoveryResult(thingUID);
waitForAssert(() -> assertThat(receivedEvent.getWrappedObject(), not(nullValue())));
assertThat(receivedEvent.getWrappedObject(), is(instanceOf(InboxRemovedEvent.class)));
}
Aggregations