Skip to content

Attribute observer callbacks pass in the name of the attribute, not the value #61

Closed

Description

@eliao

This seems unexpected to me.

eg, If I call:
vehicle.add_attribute_observer('mode', mode_callback)

mode_callback is called with 'mode' as a parameter. I would expect to be passed the value of vehicle.mode. I'm not sure why I would want the name of the attribute, as I already know the name.

Perhaps the intention is for a single callback to handle multiple attributes? That seems odd to me, and the API does not enforce such a construct.

Activity

  1. mrpollo commented on Apr 9, 2015

    @mrpollo
    Member

    I agree, this is confusing, right now the right way of doing reading the value is just reading through the global on the callback listener, the value will be updated before the trigger of callbacks relevant source for this behavior is here:

    APIModule
    https://github.com/diydrones/dronekit-python/blob/master/droneapi/module/api.py#L395-L397

    HasObservers
    https://github.com/diydrones/dronekit-python/blob/master/droneapi/lib/__init__.py#L179-L193

    I'm not entirely sure why we went this route, but I'll find out and maybe try to add a feature request for next version to also include param values, what would you expect the normal behavior form a callback wold be?

  2. eliao commented on Apr 9, 2015

    @eliao
    Author

    I would expect the callback to pass in the new value of the attribute.

    Preferably only when it changes, as referenced by #60

  3. tcr3dr commented on Nov 9, 2015

    @tcr3dr
    Contributor

    This is changed as of #426 to have the value passed in.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions