Skip to content

"address" argument on LEDs #422#446

Merged
dwalton76 merged 3 commits intoev3dev:developfrom
dwalton76:leds-address-str
Jan 31, 2018
Merged

"address" argument on LEDs #422#446
dwalton76 merged 3 commits intoev3dev:developfrom
dwalton76:leds-address-str

Conversation

@dwalton76
Copy link
Copy Markdown
Collaborator

No description provided.

Copy link
Copy Markdown
Member

@WasabiFan WasabiFan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the __str__ implementation be overridden to print the device name in this case?

@dwalton76
Copy link
Copy Markdown
Collaborator Author

It will print the class name if there is no “address”...not sure what the device name would be for the LEDs?

@WasabiFan
Copy link
Copy Markdown
Member

I believe the the led structure is /sys/class/leds/<device_name>/... such that the name describes which LED it is. That would be the useful information to provide.

@dwalton76
Copy link
Copy Markdown
Collaborator Author

dwalton76 commented Jan 31, 2018

ok so self.__class__.__name__ will print something like <ev3dev.ev3.Leds object at 0xb6710dd0>...I was expecting just Leds here I am not sure where this is coming from.

@dwalton76
Copy link
Copy Markdown
Collaborator Author

ah, is it because class Leds does not inherit from class Device

@dwalton76
Copy link
Copy Markdown
Collaborator Author

quick summary:

  • the Led and Leds classes are off on their own right now in terms of __str__. Will fix these up.
  • for any Motor object there will be an address so Device.__str__() will print something like LargeMotor(outA)
  • Sensor objects typically don't have an address specified so Device.__str__() will print just the class name. I kinda like this because it is nice and simple and not too long...if we print all of self._path for that object that is going to be really long.

@dwalton76
Copy link
Copy Markdown
Collaborator Author

This

leds = Leds()
log.info("%s: is the Leds object" % leds)
log.info("%s: is a single Led object" % leds.leds['red_left'])

results in

2018-01-31 03:45:22,179  INFO: Leds: is the Leds object
2018-01-31 03:45:22,217  INFO: red_left: is a single Led object

For a single Led object the desc is almost always going to be set so we get the handy red_left output

@WasabiFan
Copy link
Copy Markdown
Member

Looks good to me! It might be nice to have the class name in there too but I don't think it makes much of a difference; we should avoid over-complicating things.

@dwalton76 dwalton76 merged commit 1801911 into ev3dev:develop Jan 31, 2018
@dwalton76 dwalton76 deleted the leds-address-str branch January 31, 2018 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants