Skip to content

Commit

Permalink
update packages en patch homie
Browse files Browse the repository at this point in the history
  • Loading branch information
ArdKuijpers committed Dec 1, 2024
1 parent afde03f commit b2cd9c2
Show file tree
Hide file tree
Showing 7 changed files with 953 additions and 782 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.patch binary
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ __pycache__/
# local files
.env
.vscode
.vs
.vs
dist/*.whl
dist/*.tar.gz
60 changes: 32 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
FROM python:3.11-slim AS build
WORKDIR /app
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache

COPY pyproject.toml poetry.lock ./

RUN apt update && apt install -y build-essential
RUN if [ $(dpkg --print-architecture) = "armhf" ]; then \
printf "[global]\nextra-index-url=https://www.piwheels.org/simple\n" > /etc/pip.conf ; \
fi
RUN pip install poetry
RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --without dev --no-root

FROM python:3.11-slim AS final
WORKDIR /app
ENV VIRTUAL_ENV=/app/.venv \
PATH="/app/.venv/bin:$PATH" \
PYTHONDONTWRITEBYTECODE=1

RUN apt update && apt install -y bluez

COPY --from=build ${VIRTUAL_ENV} ${VIRTUAL_ENV}
COPY ./atagmqtt atagmqtt

# During debugging, this entry point will be overridden. For more information, refer to https://aka.ms/vscode-docker-python-debug
FROM python:3.12 AS build
WORKDIR /app
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache

COPY pyproject.toml poetry.lock ./

RUN apt update && apt install -y build-essential dos2unix
RUN if [ $(dpkg --print-architecture) = "armhf" ]; then \
printf "[global]\nextra-index-url=https://www.piwheels.org/simple\n" > /etc/pip.conf ; \
fi
RUN pip install poetry
RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --without dev --no-root

COPY homie.patch ./
RUN find .venv/lib/python3.12/site-packages/homie -type f -print0 | xargs -0 unix2dos
RUN patch --verbose -p0 -i homie.patch

FROM python:3.12-slim AS final
WORKDIR /app
ENV VIRTUAL_ENV=/app/.venv \
PATH="/app/.venv/bin:$PATH" \
PYTHONDONTWRITEBYTECODE=1

RUN apt update && apt install -y bluez

COPY --from=build ${VIRTUAL_ENV} ${VIRTUAL_ENV}
COPY ./atagmqtt atagmqtt

# During debugging, this entry point will be overridden. For more information, refer to https://aka.ms/vscode-docker-python-debug
CMD ["python", "-m", "atagmqtt"]
8 changes: 3 additions & 5 deletions atagmqtt/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,12 @@ def handle_exception(loop, context):
logger.error(f'Connection to AtagOne device could not be established within {settings.atag_setup_timeout} s')
except AtagException as atag_ex:
logger.error(f"Caught ATAG exception: {atag_ex}")
logger.info(f'Waiting {_settings.restart_timeout} s to restart')
time.sleep(_settings.restart_timeout)
except KeyboardInterrupt:
logger.info('Closing connection to AtagOne due to keyboard interrupt')
finally:
logger.info("AtagOne2mqtt bridge has stopped")

if __name__ == "__main__":
try:
asyncio.run(main(_settings))
except:
logger.error(f'Unrecoverable error caught. Waiting {_settings.restart_timeout} s')
time.sleep(_settings.restart_timeout)
asyncio.run(main(_settings))
49 changes: 49 additions & 0 deletions homie.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--- .venv/lib/python3.12/site-packages/homie/device_base.py.orig 2024-12-01 13:13:19.563768881 +0100
+++ .venv/lib/python3.12/site-packages/homie/device_base.py 2024-12-01 13:15:44.858792494 +0100
@@ -97,7 +97,7 @@

self.mqtt_subscription_handlers = {}

- global devices
+ global devices
devices.append(self)

#atexit.register(self.close)
@@ -166,7 +166,7 @@
def publish_extensions(self, retain=True, qos=1):
extensions = ",".join(self.extensions)

- if extensions is not "":
+ if extensions != "":
self.publish("/".join((self.topic, "$extensions")), extensions, retain, qos)

if "stats" in self.extensions:
@@ -195,7 +195,7 @@

# def publish_homeassistant(self,hass_config,hass_payload):
# self.publish(hass_config,hass_payload, True, 1)
-
+
def add_subscription(self,topic,handler,qos=0): #subscription list to the required MQTT topics, used by properties to catch set topics
self.mqtt_subscription_handlers [topic] = handler
self.mqtt_client.subscribe (topic,qos)
@@ -309,7 +309,7 @@

def close_devices(*arg):
logger.info ('Closing Devices')
- global devices
+ global devices
for device in devices:
device.close()
logger.info ('Closed Devices')
--- .venv/lib/python3.12/site-packages/homie/node/property/property_base.py.orig 2024-12-01 13:13:19.563768881 +0100
+++ .venv/lib/python3.12/site-packages/homie/node/property/property_base.py 2024-12-01 13:16:45.943557530 +0100
@@ -148,7 +148,7 @@

def publish_tags(self, retain=True, qos=1):
tags = ",".join(self.tags)
- if tags is not "":
+ if tags != "":
self.publish("/".join((self.topic, "$tags")), tags, retain, qos)

def publish_meta(self, retain=True, qos=1):
Loading

0 comments on commit b2cd9c2

Please sign in to comment.