Skip to content

Commit

Permalink
fix rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
dgomes committed Sep 12, 2023
2 parents 63113ab + 7cfd876 commit 4087ae7
Show file tree
Hide file tree
Showing 14 changed files with 350 additions and 255 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Tests

on: [push, pull_request]

jobs:

unit_tests:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']

steps:
# Checks out a copy of your repository on the ubuntu-latest machine
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest flake8
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
flake8 dali2mqtt --count --show-source --statistics --max-line-length=127
- name: Test with pytest
timeout-minutes: 3
run: |
pytest -vvv
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
![pytest workflow](https://github.com/dgomes/dali2mqtt/actions/workflows/pytest.yml/badge.svg)

# dali2mqtt
DALI <-> MQTT bridge
Expand Down Expand Up @@ -35,7 +36,7 @@ pip install -r requirements.txt
You can create a configuration file when you call the daemon the first time

```bash
venv/bin/python3 ./dali_mqtt_daemon.py
venv/bin/python3 -m dali2mqtt.dali2mqtt
```

Then just edit the file accordingly. You can also create the file with the right values, by using the arguments of dali_mqtt_daemon.py:
Expand Down
4 changes: 2 additions & 2 deletions dali2mqtt.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Description=dali2mqtt
After=network.target

[Service]
ExecStart=/opt/dali2mqtt/venv/bin/python3 dali-mqtt-daemon.py
WorkingDirectory=/opt/dali2mqtt
ExecStart=/home/homeassistant/dali2mqtt/venv/bin/python3 -m dali2mqtt.dali2mqtt
WorkingDirectory=/home/homeassistant/dali2mqtt
StandardOutput=inherit
StandardError=inherit
Environment=PYTHONUNBUFFERED=true
Expand Down
1 change: 1 addition & 0 deletions dali2mqtt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""DALI 2 MQTT package."""
42 changes: 21 additions & 21 deletions config.py → dali2mqtt/config.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
"""Configuration Object."""
import logging
import yaml
import voluptuous as vol
from watchdog.events import FileSystemEventHandler
from watchdog.observers.polling import PollingObserver as Observer

from consts import (
DEFAULT_MQTT_PORT,
DEFAULT_MQTT_SERVER,
DEFAULT_HA_DISCOVERY_PREFIX,
DEFAULT_MQTT_BASE_TOPIC,
DEFAULT_DEVICES_NAMES_FILE,
DEFAULT_LOG_LEVEL,
DEFAULT_LOG_COLOR,
DEFAULT_DALI_DRIVER,
DALI_DRIVERS,
import voluptuous as vol
import yaml
from dali2mqtt.consts import (
ALL_SUPPORTED_LOG_LEVELS,
LOG_FORMAT,
CONF_CONFIG,
CONF_DALI_DRIVER,
CONF_DEVICES_NAMES_FILE,
CONF_HA_DISCOVERY_PREFIX,
CONF_LOG_COLOR,
CONF_LOG_LEVEL,
CONF_HA_DISCOVERY_PREFIX,
CONF_DEVICES_NAMES_FILE,
CONF_MQTT_BASE_TOPIC,
CONF_MQTT_PASSWORD,
CONF_MQTT_PORT,
CONF_MQTT_SERVER,
CONF_MQTT_USERNAME,
CONF_MQTT_PASSWORD,
DALI_DRIVERS,
DEFAULT_DALI_DRIVER,
DEFAULT_DEVICES_NAMES_FILE,
DEFAULT_HA_DISCOVERY_PREFIX,
DEFAULT_LOG_COLOR,
DEFAULT_LOG_LEVEL,
DEFAULT_MQTT_BASE_TOPIC,
DEFAULT_MQTT_PORT,
DEFAULT_MQTT_SERVER,
LOG_FORMAT,
)

from watchdog.events import FileSystemEventHandler
from watchdog.observers.polling import PollingObserver as Observer

CONF_SCHEMA = vol.Schema(
{
Expand Down Expand Up @@ -101,7 +100,8 @@ def load_config_file(self):
)
configuration = {}
self._config = CONF_SCHEMA(configuration)
self._callback()
if self._callback:
self._callback()
except AttributeError:
# No callback configured
pass
Expand All @@ -112,8 +112,8 @@ def load_config_file(self):
def save_config_file(self):
"""Save configuration back to yaml file."""
try:
cfg = self._config.pop(CONF_CONFIG) # temporary displace config file
with open(self._path, "w", encoding="utf8") as outfile:
cfg = self._config.pop(CONF_CONFIG) # temporary displace config file
yaml.dump(
self._config, outfile, default_flow_style=False, allow_unicode=True
)
Expand Down
6 changes: 4 additions & 2 deletions consts.py → dali2mqtt/consts.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Constants common the various modules."""

import logging

"""Constants common the various modules."""
__author__ = "Diogo Gomes"
__version__ = "0.0.1"
__version__ = "0.0.3"
__email__ = "[email protected]"

HASSEB = "hasseb"
Expand Down Expand Up @@ -52,6 +53,7 @@

MIN_HASSEB_FIRMWARE_VERSION = 2.3
MIN_BACKOFF_TIME = 2
MAX_BACKOFF_TIME = 10
MAX_RETRIES = 10

ALL_SUPPORTED_LOG_LEVELS = {
Expand Down
Loading

0 comments on commit 4087ae7

Please sign in to comment.