|
|
@ -87,11 +87,12 @@ func (s *hueLightState) CheckStaleness(state LightState) { |
|
|
|
} |
|
|
|
|
|
|
|
type hueSensorState struct { |
|
|
|
index int |
|
|
|
externalID int |
|
|
|
uniqueID string |
|
|
|
prevData *SensorData |
|
|
|
prevTime time.Time |
|
|
|
index int |
|
|
|
externalID int |
|
|
|
uniqueID string |
|
|
|
prevData *SensorData |
|
|
|
prevTime time.Time |
|
|
|
presenceCooldown bool |
|
|
|
} |
|
|
|
|
|
|
|
func (state *hueSensorState) Update(newData SensorData) *models.Event { |
|
|
@ -113,13 +114,14 @@ func (state *hueSensorState) Update(newData SensorData) *models.Event { |
|
|
|
if state.prevData != nil && newData.Type != state.prevData.Type { |
|
|
|
return nil |
|
|
|
} |
|
|
|
if time.Since(stateTime) > time.Second*3 { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
switch newData.Type { |
|
|
|
case "ZLLSwitch": |
|
|
|
{ |
|
|
|
if time.Since(stateTime) > time.Second*3 { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
pe := state.prevData.State.ButtonEvent |
|
|
|
ce := newData.State.ButtonEvent |
|
|
|
|
|
|
@ -153,7 +155,8 @@ func (state *hueSensorState) Update(newData SensorData) *models.Event { |
|
|
|
if state.prevData != nil && state.prevData.State.Presence != newData.State.Presence { |
|
|
|
name := models.ENSensorPresenceStarted |
|
|
|
if !newData.State.Presence { |
|
|
|
name = models.ENSensorPresenceEnded |
|
|
|
name = models.ENSensorPresenceEnding |
|
|
|
state.presenceCooldown = true |
|
|
|
} |
|
|
|
|
|
|
|
return &models.Event{ |
|
|
@ -163,6 +166,15 @@ func (state *hueSensorState) Update(newData SensorData) *models.Event { |
|
|
|
"deviceInternalId": newData.UniqueID, |
|
|
|
}, |
|
|
|
} |
|
|
|
} else if state.presenceCooldown && !newData.State.Presence && time.Since(stateTime) > time.Minute { |
|
|
|
state.presenceCooldown = false |
|
|
|
return &models.Event{ |
|
|
|
Name: models.ENSensorPresenceEnded, |
|
|
|
Payload: map[string]string{ |
|
|
|
"deviceId": strconv.Itoa(state.externalID), |
|
|
|
"deviceInternalId": newData.UniqueID, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|