Skip to content

Vehicle notifier should only allow a callback to be added/removed once for a particular attribute #110

Closed

Description

@hamishwillee

Vehicle.add_attribute_observer will add an observer as many times as it is called, and Vehicle.remove_attribute_observer will remove as many instances of the observer as times it is called.

IMO you might want to assign multiple observers to the same attribute, but I would expect them to be different. You might in theory want to also apply the same observer to multiple attributes. However a callback should really only be added once as an observer for an attribute, however many times it is called to be added.

The code below shows that if add_attribute_observer is called 4 times to add an observer, and then removed once, the callback is called 3 times. It should be called once, however many times it is added.

# Now change the vehicle into STABILIZE mode
v.mode = VehicleMode("STABILIZE")


# Define example callback for mode
def armed_callback(attribute):
    print "Armed-state changed: ", v.armed

v.add_attribute_observer('armed', armed_callback)
v.add_attribute_observer('armed', armed_callback)
v.add_attribute_observer('armed', armed_callback)
v.add_attribute_observer('armed', armed_callback)
v.remove_attribute_observer('armed', armed_callback)

print "Disarming..."
v.armed = False
v.flush()

Activity

  1. assigned and unassigned on Jul 16, 2015
  2. added this to the milestone on Jul 16, 2015
  3. hamishwillee commented on Jul 21, 2015

    @hamishwillee
    ContributorAuthor

    This will be fixed by #224. Check docs at that point to see if update required.

  4. modified the milestones: v1.4.2, v1.4.1 on Jul 27, 2015
  5. added a commit that references this issue on Jul 29, 2015
    a32a59d
  6. tcr3dr commented on Jul 29, 2015

    @tcr3dr
    Contributor

    Addressed by #224.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions