Skip to content

Commit

Permalink
fixed position channel:
Browse files Browse the repository at this point in the history
altered channel type from DateTime to Number:Time as suggested in https://community.openhab.org/t/display-elapsed-time-seconds-to-hhss/142572/4?u=stephanrichter
  • Loading branch information
Stephan Richter committed Dec 27, 2022
1 parent 14c83da commit b408b45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Expand Up @@ -28,8 +28,6 @@
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.time.Instant;
import java.time.ZoneOffset;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
Expand All @@ -40,7 +38,6 @@
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.binding.BaseThingHandler;
import org.openhab.core.types.Command;
import org.openhab.core.types.State;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -52,6 +49,7 @@
import de.qspool.clementineremote.backend.pb.ClementineRemote.ResponseCurrentMetadata;
import de.qspool.clementineremote.backend.pb.ClementineRemote.ResponseUpdateTrackPosition;
import de.qspool.clementineremote.backend.pb.ClementineRemote.SongMetadata;
import tech.units.indriya.unit.Units;

/**
* The {@link ClementineRemoteHandler} is responsible for handling commands, which are
Expand Down Expand Up @@ -290,8 +288,7 @@ private void handleNullableTrackPos(@Nullable Integer newPos) {
currentPos = 0;
}

var epoch = Instant.ofEpochSecond(currentPos).atZone(ZoneOffset.UTC);
updateState(CHANNEL_POSITION, new DateTimeType(epoch));
updateState(CHANNEL_POSITION, new QuantityType<>(currentPos, Units.SECOND));
}

private void handleTrackPos(ResponseUpdateTrackPosition message) {
Expand Down Expand Up @@ -339,10 +336,10 @@ public void initialize() {
// "Can not access device as username and/or password are invalid");
}

private void sendConnectMessage() {
private void sendConnectMessage() throws IOException {
RequestConnect req = builder.getRequestConnectBuilder().build();
Message msg = builder.setRequestConnect(req).build();
sendMessage(msg);
sendMessageOrThrow(msg);
}

private void sendSkip(int d) {
Expand All @@ -360,16 +357,20 @@ private void sendMessage(Message message) {
return;
}
try {
byte[] bytes = message.toByteArray();
out.writeInt(bytes.length);
out.write(bytes);
out.flush();
sendMessageOrThrow(message);
} catch (IOException e) {
logger.warn("sendMessage({}) failed: {}", message, e.getMessage());
disconnect();
}
}

private void sendMessageOrThrow(Message message) throws IOException {
byte[] bytes = message.toByteArray();
out.writeInt(bytes.length);
out.write(bytes);
out.flush();
}

private void sendPause() {
if (setState(State.paused)) {
sendMessage(MsgType.PAUSE);
Expand Down
Expand Up @@ -55,11 +55,10 @@

</channel-type>
<channel-type id="current-position">
<item-type>DateTime</item-type>
<item-type>Number:Time</item-type>
<label>Current Position</label><!-- Use uppercase words, except prepositions. 2-3 words, max 25 chars -->
<description>Current position within the playing track</description>
<state readOnly="true"/>

<state readOnly="true" pattern="%1$tT"/>
</channel-type>
<channel-type id="current-title">
<item-type>String</item-type>
Expand Down

0 comments on commit b408b45

Please sign in to comment.