Skip to content

Commit

Permalink
Use primitive types
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Lauterbach <thomas@pop-os.amfthome.org>
  • Loading branch information
Thomas Lauterbach committed Feb 17, 2025
1 parent b822c4a commit a424544
Show file tree
Hide file tree
Showing 11 changed files with 333 additions and 301 deletions.
1 change: 1 addition & 0 deletions bundles/org.openhab.binding.mqtt.awtrixlight/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ The button events can be used by rules to change the displayed app or perform an
## Channels

### Bridge Channels (`awtrixclock`)

| Channel | Type | Read/Write | Description |
|-------------------|----------------------|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `app` | String | R | Currently active app: Will show the name of the app that is currently shown on the display. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import static org.openhab.binding.mqtt.MqttBindingConstants.BINDING_ID;

import java.math.BigDecimal;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand All @@ -31,14 +30,10 @@
public class AwtrixLightBindingConstants {

// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_APP = new ThingTypeUID(BINDING_ID, "awtrixapp");
public static final ThingTypeUID THING_TYPE_BRIDGE = new ThingTypeUID(BINDING_ID, "awtrixclock");
public static final ThingTypeUID THING_TYPE_APP = new ThingTypeUID(BINDING_ID, "awtrix-app");
public static final ThingTypeUID THING_TYPE_BRIDGE = new ThingTypeUID(BINDING_ID, "awtrix-clock");
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_APP, THING_TYPE_BRIDGE);

// Thing Type IDs
public static final String AWTRIX_APP = "awtrixapp";
public static final String AWTRIX_CLOCK = "awtrixclock";

// Matrix Size
public static final int SCREEN_HEIGHT = 8;
public static final int SCREEN_WIDTH = 32;
Expand Down Expand Up @@ -176,9 +171,4 @@ public class AwtrixLightBindingConstants {
public static final String PUSH_ICON_OPTION_0 = "STATIC";
public static final String PUSH_ICON_OPTION_1 = "PUSHOUT";
public static final String PUSH_ICON_OPTION_2 = "PUSHOUTRETURN";

// Just some little helpers...
public static final BigDecimal MINUSONE = new BigDecimal(-1);
public static final BigDecimal ONEHUNDRED = new BigDecimal(100);
public static final BigDecimal THOUSAND = new BigDecimal(1000);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*/
package org.openhab.binding.mqtt.awtrixlight.internal;

import java.math.BigDecimal;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
Expand All @@ -26,5 +24,5 @@ public class BridgeConfigOptions {
public String basetopic = "awtrix";
public int appLockTimeout = 10;
public boolean discoverDefaultApps = false;
public BigDecimal lowBatteryThreshold = new BigDecimal(25);
public int lowBatteryThreshold = 25;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -33,7 +32,6 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.ToNumberPolicy;
import com.google.gson.reflect.TypeToken;

/**
Expand All @@ -46,7 +44,7 @@ public class Helper {

private static final Logger LOGGER = LoggerFactory.getLogger(Helper.class);

private static final Gson GSON = new GsonBuilder().setObjectToNumberStrategy(ToNumberPolicy.BIG_DECIMAL).create();
private static final Gson GSON = new GsonBuilder().create();

public static Map<String, Object> decodeStatsJson(String statsJson) {
Map<String, Object> stats = GSON.fromJson(statsJson, new TypeToken<Map<String, Object>>() {
Expand Down Expand Up @@ -110,9 +108,9 @@ public static byte[] decodeImage(String messageJSON) {
return bytes == null ? new byte[0] : bytes;
}

public static BigDecimal[] leftTrim(BigDecimal[] data, int length) {
public static int[] leftTrim(int[] data, int length) {
if (length < data.length) {
BigDecimal[] trimmed = new BigDecimal[length];
int[] trimmed = new int[length];
for (int i = data.length - length; i < data.length; i++) {
trimmed[i - (data.length - length)] = data[i];
}
Expand Down
Loading

0 comments on commit a424544

Please sign in to comment.