fix 'all.*' conditions counting 'incapable' devices like sensors.
This commit is contained in:
+35
-12
@@ -101,31 +101,54 @@ func (c *EventCondition) check(key, value string, targets []Device) bool {
|
|||||||
all := strings.HasPrefix(key, "all.")
|
all := strings.HasPrefix(key, "all.")
|
||||||
if any || all {
|
if any || all {
|
||||||
count := 0
|
count := 0
|
||||||
|
total := 0
|
||||||
for _, target := range targets {
|
for _, target := range targets {
|
||||||
if c.checkDevice(key[4:], target) {
|
matches, skip := c.checkDevice(key[4:], target)
|
||||||
|
if skip {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if matches {
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
|
total++
|
||||||
}
|
}
|
||||||
|
|
||||||
return (any && count > 0) || (all && count == len(targets))
|
return (any && count > 0) || (all && count == total)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.matches(value)
|
return c.matches(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *EventCondition) checkDevice(key string, device Device) bool {
|
func (c *EventCondition) checkDevice(key string, device Device) (matches bool, skip bool) {
|
||||||
switch key {
|
switch key {
|
||||||
case "power":
|
case "power":
|
||||||
return c.matches(strconv.FormatBool(device.State.Power))
|
if !device.HasCapability(DCPower) {
|
||||||
case "color":
|
return false, true
|
||||||
return c.matches(device.State.Color.String())
|
}
|
||||||
case "intensity":
|
|
||||||
return c.matches(strconv.FormatFloat(device.State.Intensity, 'f', -1, 64))
|
|
||||||
case "temperature":
|
|
||||||
return c.matches(strconv.FormatFloat(device.State.Temperature, 'f', -1, 64))
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
return c.matches(strconv.FormatBool(device.State.Power)), false
|
||||||
|
case "color":
|
||||||
|
if !device.HasCapability(DCColorKelvin, DCColorHS, DCColorHSK) {
|
||||||
|
return false, true
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.matches(device.State.Color.String()), false
|
||||||
|
case "intensity":
|
||||||
|
if !device.HasCapability(DCIntensity) {
|
||||||
|
return false, true
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.matches(strconv.FormatFloat(device.State.Intensity, 'f', -1, 64)), false
|
||||||
|
case "temperature":
|
||||||
|
if !device.HasCapability(DCTemperatureControl, DCTemperatureSensor) {
|
||||||
|
return false, true
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.matches(strconv.FormatFloat(device.State.Temperature, 'f', -1, 64)), false
|
||||||
|
default:
|
||||||
|
return false, true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var numRegex = regexp.MustCompile("^{-[0-9].}+$")
|
var numRegex = regexp.MustCompile("^{-[0-9].}+$")
|
||||||
|
|||||||
Reference in New Issue
Block a user