Skip to content
Permalink
Browse files

Initial action support

  • Loading branch information
guyou committed Nov 5, 2019
1 parent 732c008 commit 8dc62fe74f1426b3b3f9634f25a0c22f45e015b3
@@ -29,6 +29,23 @@ Things support the following channels:
|-----------------|-----------|-------------------------------------------|
| message | Text | This channel lets send message to account |

## Rule Actions

This binding includes a rule action, which allows to send a message to a configured account.
There is a separated instance for each account.

```
var actions = getActions()
```

```
actions.sendMessage()
```

| Parameter | Description |
|-----------|----------------------|
| message | The message to send. |

## Full Example

demo.things:
@@ -0,0 +1,49 @@
/**
* Copyright (c) 2010-2019 Contributors to the openHAB project.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.freemobilesms.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.thing.binding.ThingActions;
import org.eclipse.smarthome.core.thing.binding.ThingActionsScope;
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.openhab.core.automation.annotation.ActionInput;
import org.openhab.core.automation.annotation.RuleAction;


@ThingActionsScope(name = "freemobilesms") // Your bindings id is usually the scope
@NonNullByDefault
public class FreeMobileSmsActions implements ThingActions {
private @Nullable FreeMobileSmsHandler handler;

@Override
public void setThingHandler(@Nullable ThingHandler handler) { handler = (FreeMobileSmsHandler) handler; }

This comment has been minimized.

Copy link
@Hilbrand

Hilbrand Nov 24, 2019

Here is your problem 😄

public void setThingHandler(@Nullable ThingHandler handler) { 
    this.handler = (FreeMobileSmsHandler) handler;
}

This comment has been minimized.

Copy link
@guyou

guyou Nov 25, 2019

Author Owner

Damn!


@Override
public @Nullable ThingHandler getThingHandler() { return handler; }

@RuleAction(label = "@text/actionLabel", description = "@text/actionDesc")
public void sendMessage(
@ActionInput(name = "message", label = "@text/actionInputMessageLabel", description = "@text/actionInputMessageDesc") @Nullable String message) {
this.handler.sendMessage(message);
}

public static void sendMessage(@Nullable ThingActions actions, @Nullable String message) {
if (actions instanceof FreeMobileSmsActions) {
((FreeMobileSmsActions) actions).sendMessage(message);
} else {
throw new IllegalArgumentException("Instance is not an FreeMobileSmsActions class.");
}
}

}
@@ -15,6 +15,8 @@
import static org.openhab.binding.freemobilesms.internal.FreeMobileSmsBindingConstants.*;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -24,6 +26,7 @@
import org.eclipse.smarthome.core.thing.ThingStatus;
import org.eclipse.smarthome.core.thing.ThingStatusDetail;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerService;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.library.types.StringType;
import org.slf4j.Logger;
@@ -98,4 +101,9 @@ public void initialize() {

logger.debug("Finished initializing!");
}

@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(FreeMobileSmsActions.class);
}
}

0 comments on commit 8dc62fe

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