Skip to content

Commit af04ba3

Browse files
committed
separate venv with bleak version for psk pairing
1 parent 8baa601 commit af04ba3

File tree

9 files changed

+40
-55
lines changed

9 files changed

+40
-55
lines changed

.idea/deployment.xml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/offgrid.iml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ RUN apk add git
1818
# copy files
1919
COPY . .
2020

21+
# create a separate venv for a specific bleak version that has a pairing agent that can pair devices with a PSK
22+
RUN python3 -m venv venv_bleak_pairing
23+
RUN venv_bleak_pairing/bin/pip3 install -r requirements.txt
24+
RUN venv_bleak_pairing/bin/pip3 install 'git+https://github.com/jpeters-ml/bleak@feature/windowsPairing'
25+
26+
2127
RUN python3 -m venv venv
2228
RUN venv/bin/pip3 install -r requirements.txt
29+
RUN venv/bin/pip3 install influxdb || true
2330
RUN . venv/bin/activate
2431

2532
RUN chmod a+x addon_main.sh

addon_main.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#!/usr/bin/with-contenv bashio
22

3-
. /app/venv/bin/activate
4-
5-
python install_bleak.py
6-
7-
83
MQTT_HOST=$(bashio::services mqtt "host")
94
MQTT_USER=$(bashio::services mqtt "username")
105
MQTT_PASSWORD=$(bashio::services mqtt "password")
116

12-
MQTT_HOST=$MQTT_HOST MQTT_USER=$MQTT_USER MQTT_PASSWORD=$MQTT_PASSWORD python3 main.py
7+
/app/venv/bin/python3 main.py pair-only
8+
9+
10+
MQTT_HOST=$MQTT_HOST MQTT_USER=$MQTT_USER MQTT_PASSWORD=$MQTT_PASSWORD \
11+
/app/venv/bin/python3 main.py
1312

install_bleak.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ async def background_loop(timeout: float, sampler_list: List[BmsSampler]):
113113
async def main():
114114
global shutdown
115115

116+
pair_only = len(sys.argv) > 1 and sys.argv[1] == "pair-only"
117+
if pair_only:
118+
logger.info('Started in pair-only mode (bleak %s)', bmslib.bt.bleak_version())
119+
psks = set(dev.get('psk', None) for dev in user_config.get('devices', []) if dev.get('psk', None))
120+
if not psks:
121+
logger.info('No PSK, nothing to pair')
122+
sys.exit(0)
123+
116124
bms_list: List[bmslib.bt.BtBms] = []
117125
extra_tasks = [] # currently unused, add custom coroutines here. must return True on success and can raise
118126

@@ -288,6 +296,9 @@ async def main():
288296
except:
289297
pass
290298

299+
if pair_only:
300+
sys.exit(0)
301+
291302
if parallel_fetch:
292303
# parallel_fetch now uses a loop for each BMS, so they don't delay each other
293304

requirements.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
#bleak
2-
#git+https://github.com/hbldh/bleak@ed0b1c1cddf3a2f01882512745199e0f8f4dfa68 #https://github.com/hbldh/bleak/pull/640
3-
#git+https://github.com/jpeters-ml/bleak@ed0b1c1
4-
git+https://github.com/jpeters-ml/bleak@feature/windowsPairing
51

6-
# bleak==0.20.2 # (installed with install_bleak.py)
2+
bleak==0.22.3 # see Dockerfile
73

84
paho-mqtt==2.1.0
95
backoff
106
crcmod
117

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

0 commit comments

Comments
 (0)