hap-java / HAP-Java

Java implementation of the HomeKit Accessory Protocol
MIT License
152 stars 83 forks source link

How to add Thermostat / HeaterCooler that just Heats? #108

Closed christiantschoerner closed 3 years ago

christiantschoerner commented 4 years ago

The questions says it all. I have a fan that can just heat but not cool. Which Accessory should I use?

ccutrer commented 4 years ago

You would adjust the TargetHeaterCoolMode characteristic to have an allowed value of only Off and Heat; but that's not currently possible.

jvaclavovic commented 3 years ago

Hello, I'm trying to modify library to support "heating-only" mode. I modified EnumCharacteristic, metod makeBuilder. I replaced minValue/maxValue by list of valid-values. Its works, I have device only with on/off switch without "auto-heat-cool-off" switch. But it works only few (~20) seconds after pairing. Then some update is started and all devices again have "auto-heat-cool-off" switch. Is there any other place in the code that needs to be modified?

public EnumCharacteristic(
  ...
  protected CompletableFuture<JsonObjectBuilder> makeBuilder(int iid) {
    return super.makeBuilder(iid)
        .thenApply(
            builder -> {
              return builder
                  // .add("minValue", 0)
                  // .add("maxValue", maxValue)
                  // .add("minStep", 1)
                  .add("valid-values", validValuesBuilder);
yfre commented 3 years ago

i would suggest to change

ccutrer commented 3 years ago

@yfre:

I dunno, that seems like a pain to create specific enum/characteristic every time we need to restrict the possible values.

b) for targetheatingcoolingstate, there are multiple combinations that make sense:

Seems like a better solution would be for enum-type characteristics, we add a way to define them with a list of valid values. then just keep re-using the existing Enum for them (you can only restrict, you can't add).

@jvaclavovic : maybe you need to also restrict the values for the CurrentHeatingCoolingState for HomeKit to accept it?

yfre commented 3 years ago

just checked in HAP specification, sub-set of defined enum values is supported by HAP "2.3.3.1 Valid Characteristic Values Accessory characteristics that support only a sub-set of the Apple-defined enum values can indicate the supported values as part of the characteristicʼs metadata."

jvaclavovic commented 3 years ago

@ccutrer

This is exactly what I'm doing: I have implemented valid-values for EnumCharacteristic, instead of minValue and maxValue, because I think that min,max do not make sense for enum values. I set only INACTIVE and HEATING for CurrentHeaterCoolerStateEnum and HEAT for TargetHeaterCoolerStateEnum and it works - but only for few seconds (~ 30 seconds).

After pairing I have Heating with on/off switch. But after few seconds the Heating switches to off/cool/heat/auto mode. It is some update from HomeKit, not from my side, because I have only implemented initial state and temperature, without any updates.

@yfre

I tried to remove unnecessary values from both enums, but it had no effect :/

jvaclavovic commented 3 years ago

Oh, I was my stupid mistake... I use repeately JsonArrayBuilder for creating list of valid values, but method build() on this object after creating list removes all values... so this works only for the first time and after accessories update valid-values was sent empty...

So, valid-values on EnumCharacteristics works perfectly and I have "heats-only" HeaterCooler.

Thank you for your help and I apologize for the inconvenience

ccutrer commented 3 years ago

a recent PR implemented proper enums, so you can now build a heating only accessory