Skip to content

Add custom valid values to remaining enum characteristics - #210

Open
yfre wants to merge 1 commit into
masterfrom
feature/163-custom-valid-values
Open

yfre wants to merge 1 commit into
masterfrom
feature/163-custom-valid-values

Conversation

@yfre

@yfre yfre commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Closes #163

What

35 enum characteristics always advertised every value of their enum. Each now gets a constructor that takes XxxEnum[] validValues as its first parameter, followed by the existing parameters. The existing constructor delegates with XxxEnum.values(). This is the same pattern as ProgrammableSwitchEventCharacteristic.

Included: all enum characteristics that had no valid-values constructor yet, e.g. CurrentSlatState, CurrentDoorState/TargetDoorState, CurrentFanState/TargetFanState, CurrentHumidifierDehumidifierState, LockCurrentState/LockTargetState, PositionState, TemperatureDisplayUnit, RotationDirection, SwingMode, Active, and the television/input source characteristics.

Not changed (two-value sensor and status flags, where restricting values makes no sense): AccessoryFlags, CarbonDioxideDetected, CarbonMonoxideDetected, ContactSensorState, FilterChangeIndication, InUse, IsConfigured, LeakDetectedState, OccupancyDetected, SecuritySystemAlarmType, SmokeDetected, StatusFault, StatusLowBattery, StatusTampered.

Compatibility

No breaking changes: existing constructors, methods and output are unchanged, and only constructors are added.

When using a custom list, the existing EnumCharacteristic behavior applies:

  • only the listed values are sent as valid-values, which also limits the options the Home app offers for target states
  • writes of values outside the list are ignored
  • the first listed value is the default when no value is available

Testing

mvn -B package on JDK 11: all 25 tests pass. The new CustomValidValuesCharacteristicsTest covers:

  • default constructors: the serialized JSON of all 35 must exactly match output captured from master before this change
  • custom constructors: all 35 advertise exactly the given valid-values
  • writes outside the custom list are ignored, using TemperatureDisplayUnit restricted to Celsius
  • the default is the first custom value, using PositionState

Note: like #207 and #209, this adds a # HAP-Java 2.0.10 section to CHANGES.md, so the later merges need a one-line conflict resolution.

#163)

Add a constructor taking the valid values as first parameter to 35 enum
characteristics, following ProgrammableSwitchEventCharacteristic. The
existing constructors delegate with all enum values, so their serialized
output is unchanged. Two-value sensor and status flags are left as is.
@ccutrer

ccutrer commented Oct 19, 2026

Copy link
Copy Markdown
Member

I want to look deeper at this before merging. It seems like a lot of these enums really are only two values (Active state, for example), or there wouldn't really be any advantage to telling Home that you only support two of three states; you just are never in the third state. But I'm on my phone at the moment so it's a pain to cross reference to actually enum lists (or to test with Home app to see how it reacts to a limited set).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The additive overloads preserve existing behavior, reuse established enum handling, and include focused regression coverage with no blocking issues identified.

No open issues 🎉

What changed in this PR

Extends HAP-Java’s custom enum-value support to 35 characteristics, addressing #163 while preserving existing constructors and defaults.

Changes:

  • Adds constructors accepting custom valid-value arrays.
  • Adds regression tests for serialization, restricted writes, and defaults.
  • Documents the feature in the changelog.
File Description
src/​test/​java/​io/​github/​hapjava/​characteristics/​impl/​CustomValidValuesCharacteristicsTest.java Tests compatibility and custom-value behavior.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​windowcovering/​PositionStateCharacteristic.java Adds custom position states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​valve/​ValveTypeCharacteristic.java Adds custom valve types.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​thermostat/​TemperatureDisplayUnitCharacteristic.java Adds custom temperature units.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​televisionspeaker/​VolumeSelectorCharacteristic.java Adds custom volume commands.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​televisionspeaker/​VolumeControlTypeCharacteristic.java Adds custom volume-control types.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​television/​TargetMediaStateCharacteristic.java Adds custom target media states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​television/​SleepDiscoveryModeCharacteristic.java Adds custom discovery modes.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​television/​RemoteKeyCharacteristic.java Adds custom remote keys.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​television/​PowerModeCharacteristic.java Adds custom power modes.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​television/​PictureModeCharacteristic.java Adds custom picture modes.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​television/​CurrentMediaStateCharacteristic.java Adds custom current media states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​television/​ClosedCaptionsCharacteristic.java Adds custom caption states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​slat/​SlatTypeCharacteristic.java Adds custom slat types.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​slat/​CurrentSlatStateCharacteristic.java Adds custom slat states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​lock/​LockTargetStateCharacteristic.java Adds custom target lock states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​lock/​LockCurrentStateCharacteristic.java Adds custom current lock states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​inputsource/​TargetVisibilityStateCharacteristic.java Adds custom target visibility states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​inputsource/​InputSourceTypeCharacteristic.java Adds custom input-source types.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​inputsource/​InputDeviceTypeCharacteristic.java Adds custom input-device types.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​inputsource/​CurrentVisibilityStateCharacteristic.java Adds custom current visibility states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​humidifier/​CurrentHumidifierDehumidifierStateCharacteristic.java Adds custom humidifier/dehumidifier states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​garagedoor/​TargetDoorStateCharacteristic.java Adds custom target door states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​garagedoor/​CurrentDoorStateCharacteristic.java Adds custom current door states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​fan/​TargetFanStateCharacteristic.java Adds custom target fan states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​fan/​SwingModeCharacteristic.java Adds custom swing modes.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​fan/​RotationDirectionCharacteristic.java Adds custom rotation directions.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​fan/​LockPhysicalControlsCharacteristic.java Adds custom control-lock states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​fan/​CurrentFanStateCharacteristic.java Adds custom current fan states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​common/​ServiceLabelNamespaceCharacteristic.java Adds custom label namespaces.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​common/​ProgramModeCharacteristic.java Adds custom program modes.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​common/​ActiveCharacteristic.java Adds custom active states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​battery/​ChargingStateCharacteristic.java Adds custom charging states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​airquality/​AirQualityCharacteristic.java Adds custom air-quality values.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​airpurifier/​TargetAirPurifierStateCharacteristic.java Adds custom target purifier states.
src/​main/​java/​io/​github/​hapjava/​characteristics/​impl/​airpurifier/​CurrentAirPurifierCharacteristic.java Adds custom current purifier states.
CHANGES.md Documents custom enum-value support.

Review effort: Balanced

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add support for custom value list

3 participants