-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jacob Laursen <[email protected]>
- Loading branch information
Showing
19 changed files
with
1,328 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...main/java/org/openhab/binding/bluetooth/grundfosalpha/internal/CharacteristicRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright (c) 2010-2025 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.bluetooth.grundfosalpha.internal; | ||
|
||
import java.util.Arrays; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.binding.bluetooth.BluetoothCharacteristic; | ||
import org.openhab.binding.bluetooth.BluetoothDevice; | ||
import org.openhab.binding.bluetooth.grundfosalpha.internal.protocol.MessageType; | ||
import org.openhab.core.util.HexUtils; | ||
|
||
/** | ||
* This represents a request for writing characteristic to a Bluetooth device. | ||
* | ||
* This can be used for adding such requests to a queue. | ||
* | ||
* @author Jacob Laursen - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class CharacteristicRequest { | ||
private UUID uuid; | ||
private byte[] value; | ||
|
||
/** | ||
* Creates a new request object. | ||
* | ||
* @param uuid The UUID of the characteristic | ||
* @param messageType The {@link MessageType} containing the data to write | ||
*/ | ||
public CharacteristicRequest(UUID uuid, MessageType messageType) { | ||
this.uuid = uuid; | ||
this.value = messageType.request(); | ||
} | ||
|
||
/** | ||
* Writes the characteristic to the provided {@link BluetoothDevice}. | ||
* | ||
* @param device The Bluetooth device | ||
* @return true if written, false if the characteristic is not found in the device | ||
*/ | ||
public boolean send(BluetoothDevice device) { | ||
BluetoothCharacteristic characteristic = device.getCharacteristic(uuid); | ||
if (characteristic != null) { | ||
device.writeCharacteristic(characteristic, value); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public UUID getUUID() { | ||
return uuid; | ||
} | ||
|
||
public byte[] getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public boolean equals(@Nullable Object o) { | ||
if (o == this) { | ||
return true; | ||
} | ||
if (!(o instanceof CharacteristicRequest other)) { | ||
return false; | ||
} | ||
|
||
return uuid.equals(other.uuid) && Arrays.equals(value, other.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(uuid, value); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return uuid + ": " + HexUtils.bytesToHex(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.