add support for hue temp sensor, fix saturation not working for hue bulbs.
This commit is contained in:
@@ -132,6 +132,7 @@ type SensorData struct {
|
|||||||
ButtonEvent int `json:"buttonevent"`
|
ButtonEvent int `json:"buttonevent"`
|
||||||
LastUpdated string `json:"lastupdated"`
|
LastUpdated string `json:"lastupdated"`
|
||||||
Presence bool `json:"presence"`
|
Presence bool `json:"presence"`
|
||||||
|
Temperature int
|
||||||
} `json:"state"`
|
} `json:"state"`
|
||||||
Config struct {
|
Config struct {
|
||||||
On bool `json:"on"`
|
On bool `json:"on"`
|
||||||
|
|||||||
@@ -266,6 +266,9 @@ func (d *Driver) ListDevices(ctx context.Context, bridge models.Bridge) ([]model
|
|||||||
case "ZLLPresence":
|
case "ZLLPresence":
|
||||||
device.Capabilities = append(device.Capabilities, models.DCPresence)
|
device.Capabilities = append(device.Capabilities, models.DCPresence)
|
||||||
device.Icon = "sensor"
|
device.Icon = "sensor"
|
||||||
|
case "ZLLTemperature":
|
||||||
|
device.Capabilities = append(device.Capabilities, models.DCTemperatureSensor)
|
||||||
|
device.Icon = "thermometer"
|
||||||
case "Daylight":
|
case "Daylight":
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func (s *hueLightState) Update(state models.DeviceState) {
|
|||||||
s.stale = true
|
s.stale = true
|
||||||
}
|
}
|
||||||
|
|
||||||
input.Sat = ptrInt(int(state.Color.Hue * 255))
|
input.Sat = ptrInt(int(state.Color.Saturation * 255))
|
||||||
if *input.Sat > 254 {
|
if *input.Sat > 254 {
|
||||||
*input.Sat = 254
|
*input.Sat = 254
|
||||||
}
|
}
|
||||||
@@ -118,6 +118,7 @@ func (state *hueSensorState) Update(newData SensorData) *models.Event {
|
|||||||
switch newData.Type {
|
switch newData.Type {
|
||||||
case "ZLLSwitch":
|
case "ZLLSwitch":
|
||||||
{
|
{
|
||||||
|
// Ignore old events.
|
||||||
if time.Since(stateTime) > time.Second*3 {
|
if time.Since(stateTime) > time.Second*3 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -151,7 +152,6 @@ func (state *hueSensorState) Update(newData SensorData) *models.Event {
|
|||||||
}
|
}
|
||||||
case "ZLLPresence":
|
case "ZLLPresence":
|
||||||
{
|
{
|
||||||
// TODO: Test this!
|
|
||||||
if state.prevData != nil && state.prevData.State.Presence != newData.State.Presence {
|
if state.prevData != nil && state.prevData.State.Presence != newData.State.Presence {
|
||||||
name := models.ENSensorPresenceStarted
|
name := models.ENSensorPresenceStarted
|
||||||
if !newData.State.Presence {
|
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
|
return nil
|
||||||
|
|||||||
+11
-8
@@ -48,13 +48,14 @@ type DeviceRepository interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
DCPower DeviceCapability = "Power"
|
DCPower DeviceCapability = "Power"
|
||||||
DCColorHS DeviceCapability = "ColorHS"
|
DCColorHS DeviceCapability = "ColorHS"
|
||||||
DCColorKelvin DeviceCapability = "ColorKelvin"
|
DCColorKelvin DeviceCapability = "ColorKelvin"
|
||||||
DCButtons DeviceCapability = "Buttons"
|
DCButtons DeviceCapability = "Buttons"
|
||||||
DCPresence DeviceCapability = "Presence"
|
DCPresence DeviceCapability = "Presence"
|
||||||
DCIntensity DeviceCapability = "Intensity"
|
DCIntensity DeviceCapability = "Intensity"
|
||||||
DCTemperature DeviceCapability = "Temperature"
|
DCTemperatureControl DeviceCapability = "TemperatureControl"
|
||||||
|
DCTemperatureSensor DeviceCapability = "TemperatureSensor"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Capabilities = []DeviceCapability{
|
var Capabilities = []DeviceCapability{
|
||||||
@@ -62,8 +63,10 @@ var Capabilities = []DeviceCapability{
|
|||||||
DCColorHS,
|
DCColorHS,
|
||||||
DCColorKelvin,
|
DCColorKelvin,
|
||||||
DCButtons,
|
DCButtons,
|
||||||
|
DCPresence,
|
||||||
DCIntensity,
|
DCIntensity,
|
||||||
DCTemperature,
|
DCTemperatureControl,
|
||||||
|
DCTemperatureSensor,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) Validate() error {
|
func (d *Device) Validate() error {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ var (
|
|||||||
ENSensorPresenceStarted = "SensorPresenceStarted"
|
ENSensorPresenceStarted = "SensorPresenceStarted"
|
||||||
ENSensorPresenceEnding = "SensorPresenceEnding"
|
ENSensorPresenceEnding = "SensorPresenceEnding"
|
||||||
ENSensorPresenceEnded = "SensorPresenceEnded"
|
ENSensorPresenceEnded = "SensorPresenceEnded"
|
||||||
|
ENSensorTemperature = "SensorTemperature"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BridgeConnectedEvent(bridge Bridge) Event {
|
func BridgeConnectedEvent(bridge Bridge) Event {
|
||||||
|
|||||||
Reference in New Issue
Block a user