Skip to content

Valve duration characteristics advertise int instead of uint32 #202

Closed

Description

@lsiepel

Summary

SetDurationCharacteristic (D3) and RemainingDurationCharacteristic (D4) serialize their characteristic metadata with "format": "int". Both characteristics should advertise "format": "uint32".

Reproduced with HAP-Java 2.0.8 and OpenJDK 21.0.6. The same inheritance and format definition are present on the current master branch.

Expected behavior

Apple specifies UInt32 for both Set Duration and Remaining Duration, with values in seconds and a range of 0–3600:

The serialized metadata should therefore contain "format": "uint32".

Minimal reproduction

Run this class with HAP-Java 2.0.8 and its runtime dependencies:

import java.util.concurrent.CompletableFuture;
import io.github.hapjava.characteristics.impl.valve.SetDurationCharacteristic;
import io.github.hapjava.characteristics.impl.valve.RemainingDurationCharacteristic;

public class DurationFormatReproducer {
    public static void main(String[] args) {
        var duration = new SetDurationCharacteristic(
                () -> CompletableFuture.completedFuture(300),
                value -> {}, callback -> {}, () -> {});
        var remaining = new RemainingDurationCharacteristic(
                () -> CompletableFuture.completedFuture(180),
                callback -> {}, () -> {});

        System.out.println(duration.toJson(12).join());
        System.out.println(remaining.toJson(13).join());
    }
}

Actual output, reproduced locally:

{"iid":12,"type":"D3","perms":["pr","pw","ev"],"format":"int","value":300,"minValue":0,"maxValue":3600,"minStep":1,"unit":"s"}
{"iid":13,"type":"D4","perms":["pr","ev"],"format":"int","value":180,"minValue":0,"maxValue":3600,"minStep":1,"unit":"s"}

Implementation

Both SetDurationCharacteristic and RemainingDurationCharacteristic extend IntegerCharacteristic, whose constructor passes the hard-coded format "int" to BaseCharacteristic.

A fix should let these two duration characteristics advertise uint32 and add serialization regression tests for their formats. Their Java values can remain Integer for the currently supported 0–3600 range. The formats of other integer-based characteristics should be preserved.

Context

Discovered while investigating openhab/openhab-addons#18245. The metadata mismatch is confirmed independently of Apple Home. Whether correcting it resolves the reported countdown display or responsiveness problems has not been established; this report concerns the verified protocol-format mismatch.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions