Location string `yaml:"Location"`
FriendlyName string `yaml:"FriendlyName"`
OverrideSeconds int `yaml:"OverrideSeconds"`
+ OverrideHoldSeconds int `yaml:"OverrideHoldSeconds"`
StateExpiresAt time.Time
ColorStateExpiresAt time.Time
parentRelay *RGBRelay
return fmt.Sprintf("zigbee2mqtt.%s", curSwitch.FriendlyName)
}
-func (curSwitch *Switch) setState(state bool) {
+func (curSwitch *Switch) setStateExpireSeconds(state bool, expireSeconds int) {
curTime := time.Now().UTC()
curSwitch.State = state
- curSwitch.StateExpiresAt = curTime.Add(time.Duration(curSwitch.OverrideSeconds) * time.Second)
+ curSwitch.StateExpiresAt = curTime.Add(time.Duration(expireSeconds) * time.Second)
logger.Info("Setting state for switch", "state", state, "switch", curSwitch)
}
+func (curSwitch *Switch) setState(state bool) {
+ curSwitch.setStateExpireSeconds(state, curSwitch.OverrideSeconds)
+}
-func (curSwitch *Switch) setColor() {
+func (curSwitch *Switch) setStateHold(state bool) {
+ curSwitch.setStateExpireSeconds(state, curSwitch.OverrideHoldSeconds)
+}
+
+func (curSwitch *Switch) setColorExpireSeconds(expireSeconds int) {
curTime := time.Now().UTC()
curSwitch.ColorStateExpiresAt = curTime.Add(time.Duration(curSwitch.OverrideSeconds) * time.Second)
curSwitch.parentRelay.ForceRefresh()
logger.Info("Setting color state for switch", "switch", curSwitch)
+
+}
+
+func (curSwitch *Switch) setColor() {
+ curSwitch.setColorExpireSeconds(curSwitch.OverrideSeconds)
+}
+
+func (curSwitch *Switch) setColorHold() {
+ curSwitch.setColorExpireSeconds(curSwitch.OverrideHoldSeconds)
}
// get on off status, first "is active", second "is on (or off)"
switch switchAction {
case "on_press_release", "on_press":
curSwitch.setState(true)
+ case "on_hold_release", "on_hold":
+ curSwitch.setStateHold(true)
case "off_press_release", "off_press":
curSwitch.setState(false)
+ case "off_hold_release", "off_hold":
+ curSwitch.setStateHold(false)
case "up_press", "up_press_release":
curSwitch.setColor()
+ case "up_hold", "up_hold_release":
+ curSwitch.setColorHold()
case "down_press", "down_press_release":
curSwitch.setExpired(true)
default:
year, month, day,
)
oneDay, _ := time.ParseDuration("24h")
- fudgeDuration, _ := time.ParseDuration("2h")
+ fudgeDuration, _ := time.ParseDuration("3h")
year, month, day = localTime.Add(-oneDay).Date()
risePrevious, setPrevious := sunrise.SunriseSunset(
sunriseLat, sunriseLon,