Skip to content

Commit

Permalink
Learn to code and remove over-optimized SetPower* state check
Browse files Browse the repository at this point in the history
  • Loading branch information
pdf committed Aug 6, 2016
1 parent ab25224 commit b83b766
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/lifx/light.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func lightList(c *cobra.Command, args []string) {
func getLights() []common.Light {
var lights []common.Light

logger.WithField(`ids`, flagLightLabels).Debug(`Requested IDs`)
logger.WithField(`ids`, flagLightIDs).Debug(`Requested IDs`)
logger.WithField(`labels`, flagLightLabels).Debug(`Requested labels`)

if len(flagLightIDs) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion protocol/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ func (p *V2) process(pkt *packet.Packet, addr *net.UDPAddr) {
}
p.wg.Add(1)
p.deviceQueue <- dev
p.wg.Done()
default:
if pkt.GetTarget() == 0 {
common.Log.Debugf("Skipping packet without target")
Expand Down Expand Up @@ -613,7 +614,6 @@ func (p *V2) removeGroup(id string) {
func (p *V2) addDevices() {
for dev := range p.deviceQueue {
p.addDevice(dev)
p.wg.Done()
// Perform state discovery on lights
if l, ok := dev.(*device.Light); ok {
if err := l.Get(); err != nil {
Expand Down
6 changes: 1 addition & 5 deletions protocol/v2/device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (d *Device) SetStateLabel(pkt *packet.Packet) error {
if err := pkt.DecodePayload(&l); err != nil {
return err
}
common.Log.Debugf("Got label (%d): %v", d.id, l.Label)
common.Log.Debugf("Got label (%d): %v", d.id, string(l.Label[:]))
newLabel := stripNull(string(l.Label[:]))
if newLabel != d.CachedLabel() {
d.Lock()
Expand Down Expand Up @@ -380,10 +380,6 @@ func (d *Device) CachedPower() bool {
}

func (d *Device) SetPower(state bool) error {
if state && d.CachedPower() {
return nil
}

p := &payloadPower{}
if state {
p.Level = math.MaxUint16
Expand Down
4 changes: 0 additions & 4 deletions protocol/v2/device/light.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ func (l *Light) CachedColor() common.Color {
}

func (l *Light) SetPowerDuration(state bool, duration time.Duration) error {
if state != l.CachedPower() {
return nil
}

p := new(payloadPowerDuration)
if state {
p.Level = math.MaxUint16
Expand Down

0 comments on commit b83b766

Please sign in to comment.