Skip to content

Commit

Permalink
separate venv with bleak version for psk pairing
Browse files Browse the repository at this point in the history
  • Loading branch information
fl4p committed Feb 2, 2025
1 parent 8baa601 commit af04ba3
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 55 deletions.
11 changes: 11 additions & 0 deletions .idea/deployment.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/offgrid.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ RUN apk add git
# copy files
COPY . .

# create a separate venv for a specific bleak version that has a pairing agent that can pair devices with a PSK
RUN python3 -m venv venv_bleak_pairing
RUN venv_bleak_pairing/bin/pip3 install -r requirements.txt
RUN venv_bleak_pairing/bin/pip3 install 'git+https://github.com/jpeters-ml/bleak@feature/windowsPairing'


RUN python3 -m venv venv
RUN venv/bin/pip3 install -r requirements.txt
RUN venv/bin/pip3 install influxdb || true
RUN . venv/bin/activate

RUN chmod a+x addon_main.sh
Expand Down
11 changes: 5 additions & 6 deletions addon_main.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/with-contenv bashio

. /app/venv/bin/activate

python install_bleak.py


MQTT_HOST=$(bashio::services mqtt "host")
MQTT_USER=$(bashio::services mqtt "username")
MQTT_PASSWORD=$(bashio::services mqtt "password")

MQTT_HOST=$MQTT_HOST MQTT_USER=$MQTT_USER MQTT_PASSWORD=$MQTT_PASSWORD python3 main.py
/app/venv/bin/python3 main.py pair-only


MQTT_HOST=$MQTT_HOST MQTT_USER=$MQTT_USER MQTT_PASSWORD=$MQTT_PASSWORD \
/app/venv/bin/python3 main.py

42 changes: 0 additions & 42 deletions install_bleak.py

This file was deleted.

11 changes: 11 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ async def background_loop(timeout: float, sampler_list: List[BmsSampler]):
async def main():
global shutdown

pair_only = len(sys.argv) > 1 and sys.argv[1] == "pair-only"
if pair_only:
logger.info('Started in pair-only mode (bleak %s)', bmslib.bt.bleak_version())
psks = set(dev.get('psk', None) for dev in user_config.get('devices', []) if dev.get('psk', None))
if not psks:
logger.info('No PSK, nothing to pair')
sys.exit(0)

bms_list: List[bmslib.bt.BtBms] = []
extra_tasks = [] # currently unused, add custom coroutines here. must return True on success and can raise

Expand Down Expand Up @@ -288,6 +296,9 @@ async def main():
except:
pass

if pair_only:
sys.exit(0)

if parallel_fetch:
# parallel_fetch now uses a loop for each BMS, so they don't delay each other

Expand Down
8 changes: 2 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#bleak
#git+https://github.com/hbldh/bleak@ed0b1c1cddf3a2f01882512745199e0f8f4dfa68 #https://github.com/hbldh/bleak/pull/640
#git+https://github.com/jpeters-ml/bleak@ed0b1c1
git+https://github.com/jpeters-ml/bleak@feature/windowsPairing

# bleak==0.20.2 # (installed with install_bleak.py)
bleak==0.22.3 # see Dockerfile

paho-mqtt==2.1.0
backoff
crcmod

#influxdb #optional (installed with install_bleak.py)
#influxdb # see Dockerfile
# the influxdb package appears to be not available from some platforms, so install it only if needed
# see https://github.com/fl4p/batmon-ha/issues/147 (rpi 3)

0 comments on commit af04ba3

Please sign in to comment.