Skip to content

Commit

Permalink
Implementing SHUTTER Home Node
Browse files Browse the repository at this point in the history
Signed-off-by: clinique <gael@lhopital.org>
  • Loading branch information
clinique committed Dec 29, 2022
1 parent df557a1 commit 856b497
Show file tree
Hide file tree
Showing 19 changed files with 436 additions and 172 deletions.
12 changes: 6 additions & 6 deletions bundles/org.openhab.binding.freeboxos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The *player* thing requires the following configuration parameters:
|------------------|-----------------|----------------------------------------------------------------------------|----------|---------|
| MAC Address | macAddress | The MAC address of the player device. | Yes | |
| ID | id | Id of the player within Freebox Api | Yes | 1 |
| Player port | port | | No | 24322 |
| Player port | port | | No | 24322 |
| Password | password | AirPlay password | No | |
| Remote Code | remoteCode | Code associated to remote control | No | |
| Accept all MP3 | acceptAllMp3 | Accept any bitrate for MP3 audio or only bitrates greater than 64 kbps | No | true |
Expand All @@ -86,10 +86,10 @@ The *landline* thing requires the following configuration parameters:

The *host* and *wifihost* things requires the following configuration parameters:

| Parameter Label | Parameter ID | Description | Required | Default |
|------------------|-----------------|----------------------------------------------------------------------------|----------|---------|
| MAC Address | macAddress | The MAC address of the network host . | Yes | |
| Refresh Interval | refreshInterval | The refresh interval in seconds which is used to poll for phone state. | No | 30 |
| Parameter Label | Parameter ID | Description | Required | Default |
|------------------|-----------------|------------------------------------------------------------------------|----------|---------|
| MAC Address | macAddress | The MAC address of the network host . | Yes | |
| Refresh Interval | refreshInterval | The refresh interval in seconds which is used to poll for phone state. | No | 30 |

### Repeater and Vm thing

Expand All @@ -107,7 +107,7 @@ The *basic_shutter* thing requires the following configuration parameters:

| Parameter Label | Parameter ID | Description | Required | Default |
|------------------|-----------------|------------------------------------------------------------------|----------|---------|
| Node ID | nodeId | Id of the Home Node. | Yes | |
| ID | id | Id of the Home Node | Yes | 1 |
| UP Slot ID | upSlotId | Id of the UP Slot. | Yes | 0 |
| STOP Slot ID | stopSlotId | Id of the STOP Slot. | Yes | 1 |
| DOWN Slot ID | downSlotId | Id of the DOWN Slot. | Yes | 2 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class FreeboxOsBindingConstants {
public static final ThingTypeUID THING_TYPE_VM = new ThingTypeUID(BINDING_ID, "vm");
public static final ThingTypeUID THING_TYPE_REPEATER = new ThingTypeUID(BINDING_ID, "repeater");
public static final ThingTypeUID THING_TYPE_HOME_BASIC_SHUTTER = new ThingTypeUID(BINDING_ID, "basic_shutter");
public static final ThingTypeUID THING_TYPE_HOME_SHUTTER = new ThingTypeUID(BINDING_ID, "shutter");

// Configuration elements
public static final String TIMEOUT = "timeout";
Expand All @@ -59,7 +60,7 @@ public class FreeboxOsBindingConstants {
public static final Set<ThingTypeUID> BRIDGE_TYPE_UIDS = Set.of(BRIDGE_TYPE_API);
public static final Set<ThingTypeUID> THINGS_TYPES_UIDS = Set.of(THING_TYPE_LANDLINE, THING_TYPE_HOST,
THING_TYPE_VM, THING_TYPE_PLAYER, THING_TYPE_ACTIVE_PLAYER, THING_TYPE_DELTA, THING_TYPE_REVOLUTION,
THING_TYPE_REPEATER, THING_TYPE_WIFI_HOST, THING_TYPE_HOME_BASIC_SHUTTER);
THING_TYPE_REPEATER, THING_TYPE_WIFI_HOST, THING_TYPE_HOME_BASIC_SHUTTER, THING_TYPE_HOME_SHUTTER);

protected static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Stream
.concat(BRIDGE_TYPE_UIDS.stream(), THINGS_TYPES_UIDS.stream()).collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
import org.openhab.binding.freeboxos.internal.api.ApiHandler;
import org.openhab.binding.freeboxos.internal.api.rest.FreeboxOsSession;
import org.openhab.binding.freeboxos.internal.handler.ActivePlayerHandler;
import org.openhab.binding.freeboxos.internal.handler.BasicShutterHandler;
import org.openhab.binding.freeboxos.internal.handler.FreeboxOsHandler;
import org.openhab.binding.freeboxos.internal.handler.HomeNodeBasicShutterHandler;
import org.openhab.binding.freeboxos.internal.handler.HostHandler;
import org.openhab.binding.freeboxos.internal.handler.LandlineHandler;
import org.openhab.binding.freeboxos.internal.handler.PlayerHandler;
import org.openhab.binding.freeboxos.internal.handler.RepeaterHandler;
import org.openhab.binding.freeboxos.internal.handler.RevolutionHandler;
import org.openhab.binding.freeboxos.internal.handler.ServerHandler;
import org.openhab.binding.freeboxos.internal.handler.ShutterHandler;
import org.openhab.binding.freeboxos.internal.handler.VmHandler;
import org.openhab.binding.freeboxos.internal.handler.WifiHostHandler;
import org.openhab.core.audio.AudioHTTPServer;
Expand Down Expand Up @@ -96,7 +97,9 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
} else if (THING_TYPE_REPEATER.equals(thingTypeUID)) {
return new RepeaterHandler(thing);
} else if (THING_TYPE_HOME_BASIC_SHUTTER.equals(thingTypeUID)) {
return new HomeNodeBasicShutterHandler(thing);
return new BasicShutterHandler(thing);
} else if (THING_TYPE_HOME_SHUTTER.equals(thingTypeUID)) {
return new ShutterHandler(thing);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public class ApiHandler {

private final Logger logger = LoggerFactory.getLogger(ApiHandler.class);
private final HttpClient httpClient;
private final FBDeserializer deserializer;
private final FreeboxDeserializer deserializer;
private long timeoutInMs = TimeUnit.SECONDS.toMillis(8);

@Activate
public ApiHandler(@Reference HttpClientFactory httpClientFactory, @Reference FBDeserializer deserializer,
public ApiHandler(@Reference HttpClientFactory httpClientFactory, @Reference FreeboxDeserializer deserializer,
Map<String, Object> config) {
this.httpClient = httpClientFactory.getCommonHttpClient();
this.deserializer = deserializer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
import com.google.gson.JsonSyntaxException;

/**
* The {@link FBDeserializer} is responsible to instantiate suitable Gson (de)serializer
* The {@link FreeboxDeserializer} is responsible to instantiate suitable Gson (de)serializer
*
* @author Gaël L'hopital - Initial contribution
*/
@NonNullByDefault
@Component(service = FBDeserializer.class)
public class FBDeserializer {
@Component(service = FreeboxDeserializer.class)
public class FreeboxDeserializer {
private final Gson gson;

@Activate
public FBDeserializer(@Reference TimeZoneProvider timeZoneProvider) {
public FreeboxDeserializer(@Reference TimeZoneProvider timeZoneProvider) {
gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.registerTypeAdapter(ZonedDateTime.class,
(JsonDeserializer<ZonedDateTime>) (json, type, jsonDeserializationContext) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
import org.openhab.binding.freeboxos.internal.api.rest.RestManager;

/**
* The {@link HomeManager} is the Java class used to handle api requests
* related to home
* The {@link HomeManager} is the Java class used to handle api requests related to home
*
* @author ben12 - Initial contribution
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public HomeNodeStatus getStatus() {
}

public List<HomeNodeEndpoint> getShowEndpoints() {
return showEndpoints != null ? showEndpoints : List.of();
List<HomeNodeEndpoint> localList = showEndpoints;
return localList != null ? localList : List.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.openhab.binding.freeboxos.internal.api.Response;

import com.google.gson.JsonElement;
import com.google.gson.annotations.SerializedName;

/**
* The {@link HomeNodeEndpointState} is a Java class used to map the
Expand All @@ -29,17 +30,28 @@ public class HomeNodeEndpointState {
public static class HomeNodeEndpointStateResponse extends Response<HomeNodeEndpointState> {
}

private @Nullable JsonElement value;

private @Nullable String valueType;
public static enum ValueType {
@SerializedName("bool")
BOOL,
@SerializedName("int")
INT,
@SerializedName("float")
FLOAT,
@SerializedName("void")
VOID,
@SerializedName("string")
STRING;
}

private int refresh;
private @Nullable JsonElement value;
private ValueType valueType = ValueType.VOID;
private long refresh;

public @Nullable JsonElement getValue() {
return value;
}

public @Nullable String getValueType() {
public ValueType getValueType() {
return valueType;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* 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.freeboxos.internal.config;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.freeboxos.internal.api.FreeboxException;
import org.openhab.binding.freeboxos.internal.api.home.HomeNode;
import org.openhab.binding.freeboxos.internal.api.home.HomeNodeEndpoint;
import org.openhab.binding.freeboxos.internal.api.home.HomeNodeEndpoint.EpType;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;

/**
* The {@link BasicShutterConfiguration} is responsible for holding configuration informations associated to a Basic
* Shutter thing type
*
* @author Gaël L'hopital - Initial contribution
*/
@NonNullByDefault
public class BasicShutterConfiguration extends ClientConfiguration {
public static final String UP_SLOT_ID = "upSlotId";
public static final String STOP_SLOT_ID = "stopSlotId";
public static final String DOWN_SLOT_ID = "downSlotId";
public static final String STATE_SIGNAL_ID = "stateSignalId";

public int upSlotId = 0;
public int stopSlotId = 1;
public int downSlotId = 2;
public int stateSignalId = 3;

public static void configure(DiscoveryResultBuilder discoveryResultBuilder, HomeNode homeNode)
throws FreeboxException {
for (HomeNodeEndpoint endPoint : homeNode.getShowEndpoints()) {
String name = endPoint.getName();
if (EpType.SLOT.equals(endPoint.getEpType()) && name != null) {
switch (name) {
case "up":
discoveryResultBuilder.withProperty(UP_SLOT_ID, endPoint.getId());
break;
case "stop":
discoveryResultBuilder.withProperty(STOP_SLOT_ID, endPoint.getId());
break;
case "down":
discoveryResultBuilder.withProperty(DOWN_SLOT_ID, endPoint.getId());
break;
default:
throw new FreeboxException("Unknown endpoint name :" + name);
}
} else if (EpType.SIGNAL.equals(endPoint.getEpType()) && "state".equals(name)) {
discoveryResultBuilder.withProperty(STATE_SIGNAL_ID, endPoint.getId());
}
}
}
}

This file was deleted.

Loading

0 comments on commit 856b497

Please sign in to comment.