fix: small bug for PGXL fan and ultrabeam direction
This commit is contained in:
@@ -45,6 +45,10 @@ type Client struct {
|
||||
|
||||
statusMu sync.RWMutex
|
||||
status Status
|
||||
// Optimistic fan mode kept until the amp's status poll confirms it (or it
|
||||
// ages out) — otherwise a stale poll right after a change reverts the UI.
|
||||
fanPending string
|
||||
fanPendingAt time.Time
|
||||
|
||||
cmdID atomic.Int64
|
||||
stop chan struct{}
|
||||
@@ -102,7 +106,10 @@ func (c *Client) SetFanMode(mode string) error {
|
||||
if _, err := c.command("setup fanmode=" + m); err != nil {
|
||||
return err
|
||||
}
|
||||
c.setStatus(func(s *Status) { s.FanMode = m }) // optimistic
|
||||
c.statusMu.Lock()
|
||||
c.status.FanMode = m // optimistic
|
||||
c.fanPending, c.fanPendingAt = m, time.Now()
|
||||
c.statusMu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -217,7 +224,13 @@ func (c *Client) parse(resp string) {
|
||||
case "state":
|
||||
c.status.State = kv[1]
|
||||
case "fanmode":
|
||||
c.status.FanMode = strings.ToUpper(kv[1])
|
||||
dev := strings.ToUpper(kv[1])
|
||||
// Honour a recent optimistic change until the amp confirms it.
|
||||
if c.fanPending != "" && time.Since(c.fanPendingAt) < 3*time.Second && dev != c.fanPending {
|
||||
break
|
||||
}
|
||||
c.fanPending = ""
|
||||
c.status.FanMode = dev
|
||||
case "temp":
|
||||
c.status.Temperature, _ = strconv.ParseFloat(kv[1], 64)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user