Skip to content
Permalink
Browse files

Introduction of Profiles (#4108)

* deprecating ThingHandler.handleUpdate() and adding a slave profile which could be used instead in order to configure channels to react on item state updates and therefore
running as "slave" of another one.
* Profiles determine the communication flow between the framework and the binding (i.e. ThingHandler). By now, the profiles are still statically set. Selecting a different
profile for a link will be done in a next step.

Signed-off-by: Simon Kaufmann <simon.kfm@googlemail.com>
  • Loading branch information...
sjka authored and kaikreuzer committed Sep 6, 2017
1 parent bf241d4 commit 74880d041ce6f704a299f79f8743a561058705b4
Showing with 1,322 additions and 228 deletions.
  1. +1 −1 bundles/core/org.eclipse.smarthome.core.thing.test/org.eclipse.smarthome.core.thing.test.launch
  2. +8 −57 ....thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/internal/ThingManagerOSGiTest.groovy
  3. +306 −0 ....thing.test/src/test/java/org/eclipse/smarthome/core/thing/internal/CommunicationManagerTest.java
  4. +126 −0 ...st/src/test/java/org/eclipse/smarthome/core/thing/internal/profiles/DefaultMasterProfileTest.java
  5. +126 −0 ...est/src/test/java/org/eclipse/smarthome/core/thing/internal/profiles/DefaultSlaveProfileTest.java
  6. +85 −0 ...src/test/java/org/eclipse/smarthome/core/thing/internal/profiles/RawButtonTriggerProfileTest.java
  7. +1 −0 bundles/core/org.eclipse.smarthome.core.thing/META-INF/MANIFEST.MF
  8. +1 −0 ...smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/BaseThingHandler.java
  9. +3 −0 ...pse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/ThingHandler.java
  10. +229 −111 ...home.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/CommunicationManager.java
  11. +2 −4 ...se.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/ThingManager.java
  12. +97 −0 ....thing/src/main/java/org/eclipse/smarthome/core/thing/internal/profiles/DefaultMasterProfile.java
  13. +105 −0 ...e.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/profiles/DefaultSlaveProfile.java
  14. +44 −0 ...ing/src/main/java/org/eclipse/smarthome/core/thing/internal/profiles/RawButtonTriggerProfile.java
  15. +24 −0 ...eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/profiles/Profile.java
  16. +35 −0 ....smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/profiles/ProfileFactory.java
  17. +66 −0 ...se.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/profiles/StateProfile.java
  18. +32 −0 ....smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/profiles/TriggerProfile.java
  19. +1 −0 docs/_includes/documentation-menu.html
  20. +30 −0 docs/documentation/concepts/profiles.md
  21. +0 −48 ...ro.test/src/test/groovy/org/eclipse/smarthome/binding/astro/handler/test/AstroReadOnlyTest.groovy
  22. +0 −7 ...me.binding.astro/src/main/java/org/eclipse/smarthome/binding/astro/handler/AstroThingHandler.java
@@ -34,7 +34,7 @@
<stringAttribute key="pde.version" value="3.3"/>
<stringAttribute key="product" value="org.eclipse.equinox.p2.director.app.product"/>
<booleanAttribute key="run_in_ui_thread" value="false"/>
<stringAttribute key="selected_target_plugins" value="ch.qos.logback.classic@default:default,ch.qos.logback.core@default:default,ch.qos.logback.slf4j@default:false,com.eclipsesource.jaxrs.jersey-min@default:default,com.google.gson@default:default,com.google.guava@default:default,com.ibm.icu.base@default:default,com.ibm.icu@default:default,javax.annotation@default:default,javax.inject@default:default,javax.transaction@default:false,javax.xml@default:default,org.apache.ant@default:default,org.apache.batik.css@default:default,org.apache.batik.util.gui@default:default,org.apache.batik.util@default:default,org.apache.commons.collections@default:default,org.apache.commons.io@default:default,org.apache.commons.lang@default:default,org.codehaus.groovy@default:default,org.eclipse.compare.core@default:default,org.eclipse.core.commands@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.core.databinding.observable@default:default,org.eclipse.core.databinding.property@default:default,org.eclipse.core.databinding@default:default,org.eclipse.core.expressions@default:default,org.eclipse.core.filesystem.java7@default:false,org.eclipse.core.filesystem.macosx@default:false,org.eclipse.core.filesystem@default:default,org.eclipse.core.jobs@default:default,org.eclipse.core.resources@default:default,org.eclipse.core.runtime.compatibility.registry@default:false,org.eclipse.core.runtime@default:true,org.eclipse.e4.core.commands@default:default,org.eclipse.e4.core.contexts@default:default,org.eclipse.e4.core.di.extensions@default:default,org.eclipse.e4.core.di@default:default,org.eclipse.e4.core.services@default:default,org.eclipse.e4.ui.bindings@default:default,org.eclipse.e4.ui.css.core@default:default,org.eclipse.e4.ui.css.swt.theme@default:default,org.eclipse.e4.ui.css.swt@default:default,org.eclipse.e4.ui.di@default:default,org.eclipse.e4.ui.model.workbench@default:default,org.eclipse.e4.ui.services@default:default,org.eclipse.e4.ui.widgets@default:default,org.eclipse.e4.ui.workbench.addons.swt@default:default,org.eclipse.e4.ui.workbench.renderers.swt.cocoa@default:false,org.eclipse.e4.ui.workbench.renderers.swt@default:default,org.eclipse.e4.ui.workbench.swt@default:default,org.eclipse.e4.ui.workbench3@default:default,org.eclipse.e4.ui.workbench@default:default,org.eclipse.emf.common@default:default,org.eclipse.emf.ecore.change@default:default,org.eclipse.emf.ecore.xmi@default:default,org.eclipse.emf.ecore@default:default,org.eclipse.equinox.app@default:default,org.eclipse.equinox.cm@default:default,org.eclipse.equinox.common@2:true,org.eclipse.equinox.ds@1:true,org.eclipse.equinox.event@default:true,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.region@default:false,org.eclipse.equinox.registry@default:default,org.eclipse.equinox.transforms.hook@default:false,org.eclipse.equinox.util@default:default,org.eclipse.equinox.weaving.hook@default:false,org.eclipse.help@default:default,org.eclipse.jface.databinding@default:default,org.eclipse.jface@default:default,org.eclipse.osgi.compatibility.state@default:false,org.eclipse.osgi.services@default:default,org.eclipse.osgi@-1:true,org.eclipse.swt.cocoa.macosx.x86_64@default:false,org.eclipse.swt@default:default,org.eclipse.team.core@default:default,org.eclipse.ui.cocoa@default:false,org.eclipse.ui.trace@default:default,org.eclipse.ui.workbench@default:default,org.eclipse.ui@default:default,org.hamcrest.core@default:default,org.hamcrest.integration@default:default,org.hamcrest.library@default:default,org.hamcrest.text@default:default,org.hamcrest@default:default,org.junit@default:default,org.mockito@default:default,org.objenesis@default:default,org.slf4j.api@default:default,org.w3c.css.sac@default:default,org.w3c.dom.events@default:default,org.w3c.dom.smil@default:default,org.w3c.dom.svg@default:default"/>
<stringAttribute key="selected_target_plugins" value="ch.qos.logback.classic@default:default,ch.qos.logback.core@default:default,ch.qos.logback.slf4j@default:false,com.eclipsesource.jaxrs.jersey-min@default:default,com.google.gson@default:default,com.google.guava@default:default,com.ibm.icu.base@default:default,com.ibm.icu@default:default,javax.annotation*1.2.0.v201401042248@default:default,javax.annotation*1.2.0.v201602091430@default:default,javax.inject@default:default,javax.transaction@default:false,javax.xml@default:default,org.apache.ant@default:default,org.apache.batik.css@default:default,org.apache.batik.util.gui@default:default,org.apache.batik.util@default:default,org.apache.commons.collections@default:default,org.apache.commons.io@default:default,org.apache.commons.lang@default:default,org.apache.felix.gogo.command@default:default,org.apache.felix.gogo.runtime@default:default,org.apache.felix.gogo.shell@default:default,org.apache.felix.scr@default:default,org.codehaus.groovy@default:default,org.eclipse.compare.core@default:default,org.eclipse.core.commands@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.core.databinding.observable@default:default,org.eclipse.core.databinding.property@default:default,org.eclipse.core.databinding@default:default,org.eclipse.core.expressions@default:default,org.eclipse.core.filesystem.macosx@default:false,org.eclipse.core.filesystem@default:default,org.eclipse.core.jobs@default:default,org.eclipse.core.resources@default:default,org.eclipse.core.runtime@default:true,org.eclipse.emf.common@default:default,org.eclipse.emf.ecore.change@default:default,org.eclipse.emf.ecore.xmi@default:default,org.eclipse.emf.ecore@default:default,org.eclipse.equinox.app@default:default,org.eclipse.equinox.cm@default:default,org.eclipse.equinox.common@2:true,org.eclipse.equinox.console@default:default,org.eclipse.equinox.ds@1:true,org.eclipse.equinox.event@default:true,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.region@default:false,org.eclipse.equinox.registry@default:default,org.eclipse.equinox.transforms.hook@default:false,org.eclipse.equinox.util@default:default,org.eclipse.equinox.weaving.hook@default:false,org.eclipse.help@default:default,org.eclipse.jface.databinding@default:default,org.eclipse.jface@default:default,org.eclipse.osgi.compatibility.state@default:false,org.eclipse.osgi.services@default:default,org.eclipse.osgi.util@default:default,org.eclipse.osgi@-1:true,org.eclipse.swt.cocoa.macosx.x86_64@default:false,org.eclipse.swt@default:default,org.eclipse.team.core@default:default,org.hamcrest.core@default:default,org.hamcrest.integration@default:default,org.hamcrest.library@default:default,org.hamcrest.text@default:default,org.hamcrest@default:default,org.junit@default:default,org.mockito@default:default,org.objenesis@default:default,org.slf4j.api@default:default,org.w3c.css.sac@default:default,org.w3c.dom.events@default:default,org.w3c.dom.smil@default:default,org.w3c.dom.svg@default:default"/>
<stringAttribute key="selected_workspace_plugins" value="org.eclipse.smarthome.config.core.test@default:false,org.eclipse.smarthome.config.core@default:default,org.eclipse.smarthome.config.xml.test@default:false,org.eclipse.smarthome.config.xml@default:default,org.eclipse.smarthome.core.autoupdate@default:default,org.eclipse.smarthome.core.test@default:false,org.eclipse.smarthome.core.thing.test@default:false,org.eclipse.smarthome.core.thing.xml@default:default,org.eclipse.smarthome.core.thing@default:true,org.eclipse.smarthome.core@default:true,org.eclipse.smarthome.io.console@default:default,org.eclipse.smarthome.test@default:default"/>
<booleanAttribute key="show_selected_only" value="false"/>
<booleanAttribute key="tracing" value="false"/>
@@ -25,7 +25,6 @@ import org.eclipse.smarthome.core.events.TopicEventFilter
import org.eclipse.smarthome.core.i18n.LocaleProvider
import org.eclipse.smarthome.core.items.Item
import org.eclipse.smarthome.core.items.ItemRegistry
import org.eclipse.smarthome.core.items.events.ItemCommandEvent
import org.eclipse.smarthome.core.items.events.ItemEventFactory
import org.eclipse.smarthome.core.items.events.ItemStateEvent
import org.eclipse.smarthome.core.library.items.StringItem
@@ -654,13 +653,13 @@ class ThingManagerOSGiTest extends OSGiTest {
registerThingTypeProvider()

def itemName = "name"
def handleUpdateWasCalled = false
def handleCommandWasCalled = false
def callback

managedThingProvider.add(THING)
managedItemChannelLinkProvider.add(new ItemChannelLink(itemName, CHANNEL_UID))
def thingHandler = [
handleUpdate: { ChannelUID channelUID, State newState -> handleUpdateWasCalled = true },
handleCommand: { ChannelUID channelUID, State newState -> handleCommandWasCalled = true },
setCallback: { callbackArg -> callback = callbackArg },
initialize: {},
dispose: {},
@@ -680,15 +679,15 @@ class ThingManagerOSGiTest extends OSGiTest {
callback.statusUpdated(THING, ThingStatusInfoBuilder.create(ThingStatus.ONLINE).build())

// event should be delivered
eventPublisher.post(ItemEventFactory.createStateEvent(itemName, new DecimalType(10)))
waitForAssert { assertThat handleUpdateWasCalled, is(true) }
eventPublisher.post(ItemEventFactory.createCommandEvent(itemName, new DecimalType(10)))
waitForAssert { assertThat handleCommandWasCalled, is(true) }

handleUpdateWasCalled = false
handleCommandWasCalled = false

// event should not be delivered, because the source is the same
eventPublisher.post(ItemEventFactory.createStateEvent(itemName, new DecimalType(10), CHANNEL_UID.toString()))
waitFor({handleUpdateWasCalled == true}, 1000)
assertThat handleUpdateWasCalled, is(false)
eventPublisher.post(ItemEventFactory.createCommandEvent(itemName, new DecimalType(10), CHANNEL_UID.toString()))
waitFor({handleCommandWasCalled == true}, 1000)
assertThat handleCommandWasCalled, is(false)
}

@Test
@@ -763,54 +762,6 @@ class ThingManagerOSGiTest extends OSGiTest {
waitForAssert { assertThat thingUpdatedWasCalled, is(true) }
}

@Test
void 'ThingManager handles post command correctly'() {

def itemName = "name"
def callback;

// Create item
Item item = new StringItem(itemName)
itemRegistry.add(item)

managedThingProvider.add(THING)
managedItemChannelLinkProvider.add(new ItemChannelLink(itemName, CHANNEL_UID))
def thingHandler = [
setCallback: {callbackArg -> callback = callbackArg },
initialize: {},
dispose: {},
getThing: {return THING}
] as ThingHandler

def thingHandlerFactory = [
supportsThingType: { thingTypeUID -> true},
registerHandler: {thing -> thingHandler },
unregisterHandler: {thing -> },
removeThing: {thingUID ->
}
] as ThingHandlerFactory
registerService(thingHandlerFactory)

Event receivedEvent = null
def itemCommandEventSubscriber = [
receive: { event -> receivedEvent = event },
getSubscribedEventTypes: { Sets.newHashSet(ItemCommandEvent.TYPE) },
getEventFilter: { new TopicEventFilter("smarthome/items/.*/command") },
] as EventSubscriber
registerService(itemCommandEventSubscriber)

// thing manager posts the command to the event bus via EventPublisher
callback.postCommand(CHANNEL_UID, new StringType("Value"))
waitForAssert { assertThat receivedEvent, not(null) }
assertThat receivedEvent, is(instanceOf(ItemCommandEvent))
ItemCommandEvent itemCommandEvent = receivedEvent as ItemCommandEvent
assertThat itemCommandEvent.getTopic(), is("smarthome/items/name/command")
assertThat itemCommandEvent.getItemName(), is(itemName)
assertThat itemCommandEvent.getSource(), is(CHANNEL_UID.toString())
assertThat itemCommandEvent.getItemCommand(), is(instanceOf(StringType))
assertThat itemCommandEvent.getItemCommand(), is("Value")
}

@Test
void 'ThingManager handles thing status updates online and offline correctly'() {
ThingHandlerCallback callback;

0 comments on commit 74880d0

Please sign in to comment.
You can’t perform that action at this time.