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

This commit is contained in:
2021-06-04 09:57:21 +02:00
parent 5cdb4f3cf5
commit 677d9aa9b1
5 changed files with 33 additions and 10 deletions
+1
View File
@@ -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
View File
@@ -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
}
+17 -2
View File
@@ -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