Browse Source

add support for hue temp sensor, fix saturation not working for hue bulbs.

pull/1/head
Gisle Aune 4 years ago
parent
commit
677d9aa9b1
  1. 1
      internal/drivers/hue/data.go
  2. 3
      internal/drivers/hue/driver.go
  3. 19
      internal/drivers/hue/state.go
  4. 19
      models/device.go
  5. 1
      models/event.go

1
internal/drivers/hue/data.go

@ -132,6 +132,7 @@ type SensorData struct {
ButtonEvent int `json:"buttonevent"`
LastUpdated string `json:"lastupdated"`
Presence bool `json:"presence"`
Temperature int
} `json:"state"`
Config struct {
On bool `json:"on"`

3
internal/drivers/hue/driver.go

@ -266,6 +266,9 @@ func (d *Driver) ListDevices(ctx context.Context, bridge models.Bridge) ([]model
case "ZLLPresence":
device.Capabilities = append(device.Capabilities, models.DCPresence)
device.Icon = "sensor"
case "ZLLTemperature":
device.Capabilities = append(device.Capabilities, models.DCTemperatureSensor)
device.Icon = "thermometer"
case "Daylight":
continue
}

19
internal/drivers/hue/state.go

@ -31,7 +31,7 @@ func (s *hueLightState) Update(state models.DeviceState) {
s.stale = true
}
input.Sat = ptrInt(int(state.Color.Hue * 255))
input.Sat = ptrInt(int(state.Color.Saturation * 255))
if *input.Sat > 254 {
*input.Sat = 254
}
@ -118,6 +118,7 @@ func (state *hueSensorState) Update(newData SensorData) *models.Event {
switch newData.Type {
case "ZLLSwitch":
{
// Ignore old events.
if time.Since(stateTime) > time.Second*3 {
return nil
}
@ -151,7 +152,6 @@ func (state *hueSensorState) Update(newData SensorData) *models.Event {
}
case "ZLLPresence":
{
// TODO: Test this!
if state.prevData != nil && state.prevData.State.Presence != newData.State.Presence {
name := models.ENSensorPresenceStarted
if !newData.State.Presence {
@ -177,6 +177,21 @@ func (state *hueSensorState) Update(newData SensorData) *models.Event {
}
}
}
case "ZLLTemperature":
if time.Since(stateTime) > (time.Minute * 15) {
return nil
}
if !state.prevTime.Equal(stateTime) {
return &models.Event{
Name: models.ENSensorTemperature,
Payload: map[string]string{
"temperature": strconv.FormatFloat(float64(newData.State.Temperature)/100, 'f', 2, 64),
"deviceId": strconv.Itoa(state.externalID),
"deviceInternalId": newData.UniqueID,
},
}
}
}
return nil

19
models/device.go

@ -48,13 +48,14 @@ type DeviceRepository interface {
}
var (
DCPower DeviceCapability = "Power"
DCColorHS DeviceCapability = "ColorHS"
DCColorKelvin DeviceCapability = "ColorKelvin"
DCButtons DeviceCapability = "Buttons"
DCPresence DeviceCapability = "Presence"
DCIntensity DeviceCapability = "Intensity"
DCTemperature DeviceCapability = "Temperature"
DCPower DeviceCapability = "Power"
DCColorHS DeviceCapability = "ColorHS"
DCColorKelvin DeviceCapability = "ColorKelvin"
DCButtons DeviceCapability = "Buttons"
DCPresence DeviceCapability = "Presence"
DCIntensity DeviceCapability = "Intensity"
DCTemperatureControl DeviceCapability = "TemperatureControl"
DCTemperatureSensor DeviceCapability = "TemperatureSensor"
)
var Capabilities = []DeviceCapability{
@ -62,8 +63,10 @@ var Capabilities = []DeviceCapability{
DCColorHS,
DCColorKelvin,
DCButtons,
DCPresence,
DCIntensity,
DCTemperature,
DCTemperatureControl,
DCTemperatureSensor,
}
func (d *Device) Validate() error {

1
models/event.go

@ -26,6 +26,7 @@ var (
ENSensorPresenceStarted = "SensorPresenceStarted"
ENSensorPresenceEnding = "SensorPresenceEnding"
ENSensorPresenceEnded = "SensorPresenceEnded"
ENSensorTemperature = "SensorTemperature"
)
func BridgeConnectedEvent(bridge Bridge) Event {

Loading…
Cancel
Save