Skip to content

Commit

Permalink
Add capability to include tx power in advertisement (#410)
Browse files Browse the repository at this point in the history
* Support tx-power in advertisement

* Use discard rather than remove for tx-power

* pep8 fixes

* Update GitHub Actions dependencies

* Update required packages

Update to reflect BlueZ version changes and PEP 707

* doc config update
  • Loading branch information
ukBaz authored May 18, 2024
1 parent 2b0aba8 commit 8e984b6
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install python dependencies
Expand Down
20 changes: 13 additions & 7 deletions bluezero/advertisement.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, advert_id, ad_type):
'ManufacturerData': None,
'SolicitUUIDs': None,
'ServiceData': None,
'IncludeTxPower': False,
'Includes': set(),
'Appearance': None,
'LocalName': None
}
Expand Down Expand Up @@ -150,13 +150,19 @@ def service_data(self, data):
@property
def include_tx_power(self):
"""Include TX power in advert (Different from beacon packet)"""
return self.Get(constants.LE_ADVERTISEMENT_IFACE,
'IncludeTxPower')
includes = self.Get(constants.LE_ADVERTISEMENT_IFACE, 'Includes')
return 'tx-power' in includes

@include_tx_power.setter
def include_tx_power(self, state):
return self.Set(constants.LE_ADVERTISEMENT_IFACE,
'IncludeTxPower', state)
if state:
self.props[
constants.LE_ADVERTISEMENT_IFACE][
'Includes'].add('tx-power')
else:
self.props[
constants.LE_ADVERTISEMENT_IFACE][
'Includes'].discard('tx-power')

@property
def local_name(self):
Expand Down Expand Up @@ -217,8 +223,8 @@ def GetAll(self, interface_name): # pylint: disable=invalid-name
if self.props[interface_name]['Appearance'] is not None:
response['Appearance'] = dbus.UInt16(
self.props[interface_name]['Appearance'])
response['IncludeTxPower'] = dbus.Boolean(
self.props[interface_name]['IncludeTxPower'])
response['Includes'] = dbus.Array(
self.props[interface_name]['Includes'], signature='s')

return response

Expand Down
Empty file added docs/_static/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = 'en'

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
Expand Down
14 changes: 8 additions & 6 deletions docs/developer_docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ of installing for edit is as follows:
git clone https://github.com/ukBaz/python-bluezero.git
cd python-bluezero
python3 -m venv --system-site-packages venv
python3 -m venv venv
. venv/bin/activate
pip3 install -e .[dev]
.. note::

Use of a Python Virtual environment is good practice when developing
with Python. Because some of the dependencies for Bluezero are installed
system-wide with `apt`, then it is necessary to use the
`--system-site-packages` option when creating the virtual environment so
those packages can be found.
Use of a Python Virtual environment has become the preferred with `PEP707 <https://peps.python.org/pep-0704/>`_
Some of the dependencies for Bluezero are installed
system-wide with `apt` and historically haven't worked reliably in a virtual environment.
These issues have been fixed in recent releases. However,
occasionally people see a `ModuleNotFoundError: No module named 'gi'` reported.
If this happens take a look at the `PyGObject <https://pygobject.gnome.org/getting_started.html#ubuntu-getting-started>`_
install notes.


Release Checklist
Expand Down
8 changes: 4 additions & 4 deletions docs/system_setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ Overview
--------

Bluezero relies on the dbus interface of BlueZ. This version of Bluezero is
tested wtih BlueZ version **5.50**. As the BlueZ DBus API is undergoing
tested wtih BlueZ version **5.64**. As the BlueZ DBus API is undergoing
changes between versions it is best to aim for that version when working
with Bluezero.
BlueZ 5.50 was chosen as the version to align with as this is the default version
of BlueZ in Debian Stretch which was the latest/popular version at the time of
BlueZ 5.64 was chosen as the version to align with as this is the default version
of BlueZ in Ubuntu 22.04.4 LTS which was the latest/popular version at the time of
release. This means it is likely that the Linux version you have installed will
have the correct version.
To check the version use bluetoothctl and type version::

$ bluetoothctl -v
5.50
5.64


More instructions are available in the `Getting Started
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

here = path.abspath(path.dirname(__file__))

required_packages = []
required_packages = ['PyGObject']
extras_rel = ['bumpversion', 'twine']
extras_doc = ['sphinx', 'sphinx_rtd_theme']
extras_test = ['coverage', 'pycodestyle', 'python-dbusmock']
Expand Down

0 comments on commit 8e984b6

Please sign in to comment.