Skip to content

Conversation

@AlanRosenthal
Copy link
Contributor

No description provided.

@AlanRosenthal AlanRosenthal force-pushed the treadmill branch 2 times, most recently from 3b1808b to 5e060a2 Compare July 16, 2024 18:49
await self.peer.discover_all()
print("Service discovery complete!")

hr_measurement_characteristics = self.peer.get_characteristics_by_uuid(
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could use the HeartRateServiceProxy class from the profiles. Something like: heart_rate_service = peer.create_service_proxy(HeartRateServiceProxy).
(see examples/heart_rate_client.py for an example)

uuid=GATT_HEART_RATE_MEASUREMENT_CHARACTERISTIC,
service=GATT_HEART_RATE_SERVICE,
)
hr_measurement_characteristic = hr_measurement_characteristics[0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be safe to check that the service actually has that characteristic, otherwise that's going to raise.

if listener := self.listeners.get('on_security_request'):
listener()

def on(self, event_name, listener):
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can just subclass pyee.EventEmitter and get all the listener management and event emission implemented already for you.

async def on_connection(self, connection: Connection):
self.emit_connection_updates(connection)
connection.listener = self
connection.on('security_request', self.on_security_request)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you want to prompt the user to accept/reject pairing, you should probably use the PairingDelegate mechanism rather than intercepting security requests. See apps/pair.py for an example (see how the --prompt option is handled, it does exactly that: ask the user to accept pairing or not).

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.

4 participants