Skip to content

Commit

Permalink
fix channel typo
Browse files Browse the repository at this point in the history
Signed-off-by: Bernd Weymann <[email protected]>
  • Loading branch information
weymann committed Dec 3, 2024
1 parent b3bf3c2 commit e6b15f1
Show file tree
Hide file tree
Showing 45 changed files with 293 additions and 321 deletions.
33 changes: 18 additions & 15 deletions bundles/org.openhab.binding.dirigera/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -716,16 +716,16 @@ You can call these actions via rules or get the results via openHAB Developer To
```java
[
{
"actionUid": "dirigera.dumpToken",
"label": "Dump Gateway Token",
"description": "Dumps the current token to get access towards DIRIGERA gateway",
"actionUid": "dirigera.getToken",
"label": "Get Gateway Token",
"description": "Gets the current token to get access towards DIRIGERA gateway",
"inputs": [],
"outputs": []
},
{
"actionUid": "dirigera.dumpJSON",
"label": "Dump Device JSON Data",
"description": "Dumps the current JSON data connected to this device",
"actionUid": "dirigera.getJSON",
"label": "Get Device JSON Data",
"description": "Gets the current JSON data connected to this device",
"inputs": [],
"outputs": []
},
Expand All @@ -750,13 +750,13 @@ You can call these actions via rules or get the results via openHAB Developer To
]
```

### `dumpToken`
### `getToken`

The token can be obtained from any thing connected to DIRIGERA gateway.

```java
val dishwasherDebugActions = getActions("dirigera","dirigera:smart-plug:myhome:dishwasher")
val token = dishwasherDebugActions.dumpToken
val token = dishwasherDebugActions.getToken
logInfo("DIRIGERA","Token {}",token)
```

Expand All @@ -772,21 +772,23 @@ Replace content in curl command with following variables:
- $DEVICE - bulb id you want to control, take it from configuration
- $TOKEN - shortly stop / start DIRIGERA bridge and search for obtained token

### `dumpJSON`
### `getJSON`

Dumps the current JSON with attributes and capabilities of one device.
If thing UID from gateway is given dumo contains all devices connected to gateway.

```java
val gatewayActions = getActions("dirigera","dirigera:gateway:myhome")
// dumps your complete home
val json = gatewayActions.dumpJSON
// get JSON representation of all connected devices
val json = gatewayActions.getJSON
logInfo("DIRIGERA","JSON {}",json)
```

### `setDebug`

Enables logging for one specific device.
Enables logging for one specific device or all devices.
First boolean parameter: Enable debugging?
Second boolean parameter: debug flag valid for all devices?
Setting to true you'll see

- openhAB commands send to device handler
Expand All @@ -796,9 +798,10 @@ Setting to true you'll see

```java
val dishwasherDebugActions = getActions("dirigera","dirigera:gateway:myhome")
// dumps your complete home
dishwasherDebugActions.setDebug(true)
logInfo("DIRIGERA","JSON {}",json)
// enables debugging for dishwasher plug
dishwasherDebugActions.setDebug(true,false)
// after debugging one or several devices disable debugging for all devices
dishwasherDebugActions.setDebug(false,true)
```

## Full Example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@NonNullByDefault
public class Constants {
public static final String BINDING_ID = "dirigera";
public static final String BINDING_VERSION = "0.4-alpha";
public static final String BINDING_VERSION = "0.5-beta";

// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_GATEWAY = new ThingTypeUID(BINDING_ID, "gateway");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ public DirigeraHandlerFactory(@Reference StorageService storageService,
insecureClient.getProtocolHandlers().remove(WWWAuthenticationProtocolHandler.NAME);
} catch (Exception e) {
// catching exception is necessary due to the signature of HttpClient.start()
logger.warn("Failed to start http client: {}", e.getMessage());
logger.warn("DIRIGERA FACTORY Failed to start http client: {}", e.getMessage());
throw new IllegalStateException("Could not create HttpClient", e);
}
String ip = networkService.getPrimaryIpv4HostAddress();
if (ip == null) {
logger.warn("Cannot find host IP");
logger.info("DIRIGERA FACTORY Cannot find host IP");
ip = "";
} else {
manager.initialize(insecureClient, ip);
Expand All @@ -109,9 +109,7 @@ public DirigeraHandlerFactory(@Reference StorageService storageService,

@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
boolean isSupported = SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
// logger.warn("Request for {} is supported {}", thingTypeUID, isSupported);
return isSupported;
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
}

@Override
Expand Down Expand Up @@ -167,7 +165,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
} else if (THING_TYPE_AIR_PURIFIER.equals(thingTypeUID)) {
return new AirPurifierHandler(thing, AIR_PURIFIER_MAP);
} else {
logger.info("Request for {} doesn't match {}", thingTypeUID, THING_TYPE_GATEWAY);
logger.debug("DIRIGERA FACTORY Request for {} doesn't match {}", thingTypeUID, THING_TYPE_GATEWAY);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,54 +35,55 @@ public class DebugActions implements ThingActions {
private Optional<DebugHandler> thingHandler = Optional.empty();

/**
* Dump handler device JSON for debug purposes.
* Get handler device JSON for debug purposes.
*/
@RuleAction(label = "@text/actionDumpJsonLabel", description = "@text/actionDumpJsonDescription")
public @ActionOutput(name = "result", label = "Device JSON", type = "java.lang.String") String dumpJSON() {
@RuleAction(label = "@text/actionGetJsonLabel", description = "@text/actionGetJsonDescription")
public @ActionOutput(name = "result", label = "Device JSON", type = "java.lang.String") String getJSON() {
if (thingHandler.isPresent()) {
return thingHandler.get().dumpJSON();
return thingHandler.get().getJSON();
}
return "{}";
}

public static String dumpJSON(ThingActions actions) {
return ((DebugActions) actions).dumpJSON();
public static String getJSON(ThingActions actions) {
return ((DebugActions) actions).getJSON();
}

/**
* Dump gateway token from everywhere. No need to call it directly from gateway.
* Get gateway token from everywhere. No need to call it directly from gateway.
*/
@RuleAction(label = "@text/actionDumpTokenLabel", description = "@text/actionDumpTokenDescription")
public @ActionOutput(name = "result", label = "Token", type = "java.lang.String") String dumpToken() {
@RuleAction(label = "@text/actionGetTokenLabel", description = "@text/actionGetTokenDescription")
public @ActionOutput(name = "result", label = "Token", type = "java.lang.String") String getToken() {
if (thingHandler.isPresent()) {
return thingHandler.get().dumpToken();
return thingHandler.get().getToken();
}
return "no token available";
}

public static String dumpToken(ThingActions actions) {
return ((DebugActions) actions).dumpToken();
public static String getToken(ThingActions actions) {
return ((DebugActions) actions).getToken();
}

/**
* Set specific device into debug mode showing commands and updates on trace info level
*/
@RuleAction(label = "@text/actionSetDebugLabel", description = "@text/actionSetDebugDescription")
public void setDebug(
@ActionInput(name = "debug", label = "@text/debugFlagLabel", description = "@text/debugFlagDescription") boolean debug) {
@ActionInput(name = "debug", label = "@text/actionDebugFlagLabel", description = "@text/actionDebugFlagDescription") boolean debug,
@ActionInput(name = "all", label = "@text/actionDebugFlagForAllLabel", description = "@text/actionDebugFlagForAllDescription") boolean all) {
if (thingHandler.isPresent()) {
thingHandler.get().setDebug(debug);
thingHandler.get().setDebug(debug, all);
}
}

public static void setDebug(ThingActions actions, boolean debug) {
((DebugActions) actions).setDebug(debug);
public static void setDebug(ThingActions actions, boolean debug, boolean all) {
((DebugActions) actions).setDebug(debug, all);
}

@Override
public void setThingHandler(ThingHandler handler) {
if (handler instanceof DebugHandler dumpHandler) {
thingHandler = Optional.of(dumpHandler);
if (handler instanceof DebugHandler debugHandler) {
thingHandler = Optional.of(debugHandler);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*/
package org.openhab.binding.dirigera.internal.discovery;

import java.time.Duration;
import java.time.Instant;
import java.util.concurrent.ScheduledExecutorService;

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand Down Expand Up @@ -43,17 +41,15 @@ public class DirigeraDiscoveryManager {

@Activate
public DirigeraDiscoveryManager() {
logger.info("DIRIGERA Manager constructor");
}

public void initialize(HttpClient httpClient, String ip) {
logger.info("DIRIGERA Manager received {}", ip);
logger.trace("DIRIGERA DISCOVERY IP address {}", ip);
insecureClient = httpClient;
ipAddress = ip;
}

public void setDiscoverService(DirigeraDiscoveryService discoveryService) {
logger.info("DIRIGERA DiscoveryService registered");
this.discoveryService = discoveryService;
}

Expand All @@ -63,7 +59,6 @@ public void scanForHub() {
String proxyIpAddress = ipAddress;

if (currentDiscoveryService != null && currentInsecureClient != null && proxyIpAddress != null) {
Instant startTime = Instant.now();
String ipAddress = proxyIpAddress;
ScheduledExecutorService scheduler = ThreadPoolManager.getScheduledPool("dirigera-discovery");
if (!ipAddress.isBlank()) {
Expand All @@ -75,13 +70,11 @@ public void scanForHub() {
investigateIp, currentInsecureClient);
scheduler.execute(investigator);
}
logger.info("DIRIGERA DISCOVERY scan finished in {} seconds",
Duration.between(startTime, Instant.now()).getSeconds());
} else {
logger.info("DIRIGERA DISCOVERY cannot obtain IP address");
logger.debug("DIRIGERA DISCOVERY cannot obtain IP address");
}
} else {
logger.info("DIRIGERA DISCOVERY not ready yet");
logger.debug("DIRIGERA DISCOVERY not ready yet");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public DirigeraDiscoveryRunnable(DirigeraDiscoveryService discovery, String ipAd
@Override
public void run() {
String homeUrl = String.format(HOME_URL, ipAddress);
// logger.info("DIRIGERA DISCOVERY check {}", ipAddress);
ContentResponse response;
try {
response = httpClient.newRequest(homeUrl).header(HttpHeader.WWW_AUTHENTICATE, "Basic")
Expand All @@ -59,7 +58,7 @@ public void run() {
Map<String, Object> properties = new HashMap<>();
properties.put(PROPERTY_IP_ADDRESS, ipAddress);
discovery.gatewayDiscovered(ipAddress, properties);
logger.info("DIRIGERA DISCOVERY possible candidate {}", ipAddress);
logger.trace("DIRIGERA DISCOVERY possible candidate {}", ipAddress);
return;
}
} catch (InterruptedException | ExecutionException | TimeoutException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,12 @@ public DirigeraDiscoveryService(final @Reference DirigeraDiscoveryManager manage
super(SUPPORTED_THING_TYPES_UIDS, 90, true);
dirigeraDiscoveryManager = manager;
dirigeraDiscoveryManager.setDiscoverService(this);
logger.info("DIRIGERA DISCOVERY constructor");
}

public synchronized void gatewayDiscovered(String ip, Map<String, Object> properties) {
DiscoveryResult discoveryResult = DiscoveryResultBuilder
.create(new ThingUID(THING_TYPE_GATEWAY, ip.replace(".", "-"))).withLabel("DIRIGERA Gateway " + ip)
.withRepresentationProperty(PROPERTY_IP_ADDRESS).withProperties(properties).build();
logger.info("DIRIGERA DISCOVERY gateway type {} uid {} discovered - known {}",
discoveryResult.getThingTypeUID(), discoveryResult.getThingUID(), discoveryResult.getFlag());
thingDiscovered(discoveryResult);
}

Expand All @@ -68,7 +65,6 @@ public void deviceRemoved(DiscoveryResult result) {

@Override
protected void startScan() {
logger.info("DIRIGERA DISCOVERY searching manually for gateways");
dirigeraDiscoveryManager.scanForHub();
}
}
Loading

0 comments on commit e6b15f1

Please sign in to comment.