|
@ -87,11 +87,12 @@ func (s *hueLightState) CheckStaleness(state LightState) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type hueSensorState struct { |
|
|
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 { |
|
|
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 { |
|
|
if state.prevData != nil && newData.Type != state.prevData.Type { |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
if time.Since(stateTime) > time.Second*3 { |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch newData.Type { |
|
|
switch newData.Type { |
|
|
case "ZLLSwitch": |
|
|
case "ZLLSwitch": |
|
|
{ |
|
|
{ |
|
|
|
|
|
if time.Since(stateTime) > time.Second*3 { |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
pe := state.prevData.State.ButtonEvent |
|
|
pe := state.prevData.State.ButtonEvent |
|
|
ce := newData.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 { |
|
|
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 { |
|
|
name = models.ENSensorPresenceEnded |
|
|
|
|
|
|
|
|
name = models.ENSensorPresenceEnding |
|
|
|
|
|
state.presenceCooldown = true |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return &models.Event{ |
|
|
return &models.Event{ |
|
@ -163,6 +166,15 @@ func (state *hueSensorState) Update(newData SensorData) *models.Event { |
|
|
"deviceInternalId": newData.UniqueID, |
|
|
"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, |
|
|
|
|
|
}, |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|