Skip to content

Commit

Permalink
Merge pull request #14 from b2un0/main
Browse files Browse the repository at this point in the history
migrate to flat layout
  • Loading branch information
slespersen authored Dec 19, 2024
2 parents a46e3e1 + 180546b commit f8c3682
Show file tree
Hide file tree
Showing 19 changed files with 1,796 additions and 1,760 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ ADD . /app

WORKDIR /app

RUN apk add --no-cache bluez && pip install -r requirements.txt
RUN apk add --no-cache bluez jq && pip install .

ENTRYPOINT ["/app/entrypoint.sh"]
45 changes: 28 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,19 @@ The following functions are in the making:
- **Automatic Temperature Unit Update**: Automatically updating of the enabled and disabled temperature unit sensor in Home Assistant to not pollute the different statistics.
- **Additional Status Messages**: Additional messages for both charge_start and charge_stop.

## Installation
## Installation with pipx

Since `evseMQTT` is not yet available on pip, it needs to be installed manually. Follow these steps:
install [pipx](https://pipx.pypa.io/latest/installation/)

1. Clone the repository:
```bash
git clone https://github.com/slespersen/evseMQTT.git
```

2. Create a symbolic link to your Python library directory:
```bash
ln -s /path/to/evseMQTT /path/to/your/python/lib
```
```bash
sudo pipx install git+https://github.com/slespersen/evseMQTT
sudo ln -s ~/.local/bin/evseMQTT /usr/local/bin/evseMQTT
/usr/local/bin/evseMQTT --help
```

## Usage

`main.py` is provided for running the library. Below are the arguments it accepts:
`evseMQTT` is provided for running the library. Below are the arguments it accepts:

### Arguments

Expand All @@ -75,7 +71,7 @@ Since `evseMQTT` is not yet available on pip, it needs to be installed manually.
Here's an example of how to run `main.py` with the necessary arguments:

```bash
python main.py --address "your_device_mac_address" \
evseMQTT --address "your_device_mac_address" \
--password "your_6_digit_pin" \
--unit "W" \
--mqtt \
Expand Down Expand Up @@ -106,20 +102,35 @@ docker run -d --name evseMQTT \
```

### Run as systemd service
A template for a systemd service file has been provided. The arguments needs to be updated according to the, as well as the path to the library.

See evseMQTT.service for details.
A systemd service file has been provided.

you need to create the environment file `/etc/default/evseMQTT` with the following content:

```bash
sudo cp /path/to/evseMQTT/evseMQTT.service /etc/systemd/system/evseMQTT.service
BLE_ADDRESS=AA:BB:CC:DD:EE:FF
BLE_PASSWORD=123456
UNIT="W"
MQTT_BROKER=_broker_
MQTT_PORT=1883
MQTT_USER=_user_
MQTT_PASSWORD=_password_
LOGGING_LEVEL=INFO
```

```bash
sudo curl https://raw.githubusercontent.com/slespersen/evseMQTT/refs/heads/main/evseMQTT.service -o /etc/systemd/system/evseMQTT.service

# create the config file and edit it
sudo nano /etc/default/evseMQTT

sudo systemctl daemon-reload

sudo systemctl enable evseMQTT.service

sudo systemctl start evseMQTT.service

sudo systemctl status evseMQTT.service
sudo journalctl -f -u evseMQTT
```

### Handle bluetooth module crashes in container
Expand Down
8 changes: 7 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/usr/bin/env sh

# if configured as HA addon export options to env
if [ -f "/data/options.json" ]; then
echo "/data/options.json file found -> parsing options"
export $(jq -r 'to_entries | .[] | "\(.key)=\(.value)"' "/data/options.json")
fi

MQTT_ENABLED=${MQTT_ENABLED:-"true"}
MQTT_ARGS=""
SYS_MODULE_TO_RELOAD=${SYS_MODULE_TO_RELOAD:-""}
Expand All @@ -24,7 +30,7 @@ fi

echo "Starting evseMQTT ..."

python main.py ${MQTT_ARGS} \
/usr/local/bin/evseMQTT ${MQTT_ARGS} \
--address "${BLE_ADDRESS}" \
--password "${BLE_PASSWORD}" \
--unit "${UNIT}" \
Expand Down
8 changes: 4 additions & 4 deletions evseMQTT.service
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[Unit]
Description=Communicating with EVSE-based Electric Vehicle Charging Wallboxes using Bluetooth Low Energy (BLE)
After=network.target
Description=Communicating with BESEN-based Electric Vehicle Charging Wallboxes using Bluetooth Low Energy (BLE)
After=network.target dbus.service

[Service]
ExecStart=/usr/bin/python3 /path/to/evseMQTT/main.py --address <address> --password <password> --unit <unit> --mqtt --mqtt_broker <mqtt_broker> --mqtt_port <mqtt_port>
WorkingDirectory=/opt/evseMQTT
EnvironmentFile=/etc/default/evseMQTT
ExecStart=/usr/local/bin/evseMQTT --address ${BLE_ADDRESS} --password ${BLE_PASSWORD} --unit ${UNIT} --mqtt --mqtt_broker ${MQTT_BROKER} --mqtt_port ${MQTT_PORT} --mqtt_user ${MQTT_USER} --mqtt_password ${MQTT_PASSWORD} --logging_level ${LOGGING_LEVEL}
Restart=always

[Install]
Expand Down
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[project]
name = "evseMQTT"
version = "0.0.1"
readme = "README.md"
license = { file = "LICENSE" }
keywords = ["evse", "mqtt", "BESEN", "BS20", "WALLBOX", "BLE"]
requires-python = ">=3.7"

dependencies = [
"bleak==0.20.2",
"paho-mqtt==1.6.1"
]

[project.scripts]
evseMQTT = "main:main"

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

20 changes: 10 additions & 10 deletions evseMQTT/__init__.py → src/evseMQTT/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from .ble_manager import BLEManager
from .device import Device
from .event_handlers import EventHandlers
from .logger import Logger
from .utils import Utils
from .constants import Constants
from .parsers import Parsers
from .mqttpayloads import MQTTPayloads
from .mqttclient import MQTTClient
from .mqttcallback import MQTTCallback
from .ble_manager import BLEManager
from .device import Device
from .event_handlers import EventHandlers
from .logger import Logger
from .utils import Utils
from .constants import Constants
from .parsers import Parsers
from .mqttpayloads import MQTTPayloads
from .mqttclient import MQTTClient
from .mqttcallback import MQTTCallback
from .commands import Commands
6 changes: 3 additions & 3 deletions evseMQTT/ble_manager.py → src/evseMQTT/ble_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, event_handler, logger, callback=None):

self.write_uuid = ""
self.read_uuid = ""

# Ensure bleak does not go bananas, if we set logging to DEBUG
self.logger_bleak = logging.getLogger("bleak")
self.logger_bleak.setLevel(logging.INFO)
Expand All @@ -27,13 +27,13 @@ async def scan(self):
self.logger.info("Scanning for evse BLE devices...")
try:
devices = await BleakScanner.discover(return_adv=True)

# Filter devices with "ACP#" in their name
self.available_devices = {dev.address: (dev, adv_data) for dev, adv_data in devices.values() if "ACP#" in dev.name}
for address, (device, adv_data) in self.available_devices.items():
self.logger.info(f"Found device: {device.name} ({address})")
self.connectiondata[address] = device

if any("0000fff0" in uuid for uuid in adv_data.service_uuids):
self.logger.info(f"Device {device.name} ({device.address}) matches UUIDs for Old Board")

Expand Down
Loading

0 comments on commit f8c3682

Please sign in to comment.