brutella / hap

The HomeKit Accessory Protocol (hap) implemented in Go
Apache License 2.0
355 stars 43 forks source link

Thermostat need a struct value for current humidity. #48

Closed p000 closed 11 months ago

p000 commented 11 months ago

Please let me know if this feature to be supported.

I can try contribute as well, with your guidance.

brutella commented 11 months ago

If you need specific characteristics for an accessory, you can add them yourself. For example if you need the current humidity for a thermostat, you can create your custom thermostat service and add the humidity as a new property.

type CustomThermostat struct {
    *service.Thermostat

    CurrentHumidity *characteristic.CurrentRelativeHumidity
}

func NewCustomThermostat() *CustomThermostat {
    return &CustomThermostat{
        Thermostat:      service.NewThermostat(),
        CurrentHumidity: characteristic.NewCurrentRelativeHumidity(),
    }
}

func main() {
    info := accessory.Info{ Name: "Thermostat" }
    a := accessory.New(info, accessory.TypeThermostat)

    // Add your custom thermostat service
    thermostat := NewCustomThermostat()
    a.AddS(thermostat.S)

    // Update the relative humidity
    thermostat.CurrentHumidity.SetValue(60)
    ...
}
p000 commented 9 months ago

@brutella - Thanks for the sample. It worked and you are awesome 👍🏼 😍