From fa0a452880df270a8e8539db87648845037a59af Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 18 May 2022 21:11:44 +0200 Subject: [PATCH 1/7] Build Docker image out of tree Fix docker-compose file --- somfyProtect2Mqtt/Dockerfile | 10 +++------- somfyProtect2Mqtt/docker-compose.yml | 10 ++-------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/somfyProtect2Mqtt/Dockerfile b/somfyProtect2Mqtt/Dockerfile index 6d4b3e2..b0f29f0 100644 --- a/somfyProtect2Mqtt/Dockerfile +++ b/somfyProtect2Mqtt/Dockerfile @@ -7,15 +7,11 @@ STOPSIGNAL SIGINT # SomfyProtect2MQTT version ARG VERSION=0.1.7 -# Download source and untar -WORKDIR /usr/src -ADD "https://github.com/Minims/SomfyProtect2MQTT/archive/refs/heads/dev.tar.gz" src.tar.gz -RUN tar -xvf src.tar.gz -RUN mv /usr/src/SomfyProtect2MQTT-dev /usr/src/SomfyProtect2MQTT +ADD . /app +WORKDIR /app # Install python requirements -WORKDIR /usr/src/SomfyProtect2MQTT/somfyProtect2Mqtt RUN pip3 install -r requirements.txt # Run -ENTRYPOINT ["./docker-entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["python3", "./main.py", "-c", "/config/config.yaml"] \ No newline at end of file diff --git a/somfyProtect2Mqtt/docker-compose.yml b/somfyProtect2Mqtt/docker-compose.yml index abc9327..b87b068 100644 --- a/somfyProtect2Mqtt/docker-compose.yml +++ b/somfyProtect2Mqtt/docker-compose.yml @@ -1,13 +1,7 @@ -version: "3.9" +version: "3" services: somfyprotect2mqtt: build: . - environment: - TZ: Europe/Paris volumes: - - ./data:/data - - ./app:/app - command: tail -f /dev/null + - ./config:/config -volumes: - mydata: From dd95696cf90507ee944555456d6928d833a9c7d8 Mon Sep 17 00:00:00 2001 From: Minims Date: Tue, 17 May 2022 21:48:16 +0200 Subject: [PATCH 2/7] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 199bc02..d03a216 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,8 @@ Ex: ### Easy Mode (via HomeAssistant Supervisor) +[![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2FMinims%2Fhomeassistant-addons) + In HomeAssistant, go to Supervisor > Add-on Store > Repositories Add this repo: https://github.com/minims/homeassistant-addons/ From d5a60861611a148bc0623d69424b420af9a2b9bc Mon Sep 17 00:00:00 2001 From: Minims Date: Fri, 20 May 2022 21:15:44 +0200 Subject: [PATCH 3/7] Add Somfy One/Somfy One Plus Camera --- somfyProtect2Mqtt/business/__init__.py | 6 ++++- .../somfy_protect/api/devices/category.py | 2 ++ .../somfy_protect/api/devices/somfy_one.py | 24 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 somfyProtect2Mqtt/somfy_protect/api/devices/somfy_one.py diff --git a/somfyProtect2Mqtt/business/__init__.py b/somfyProtect2Mqtt/business/__init__.py index 19deb15..4c6db4a 100644 --- a/somfyProtect2Mqtt/business/__init__.py +++ b/somfyProtect2Mqtt/business/__init__.py @@ -87,7 +87,9 @@ def ha_devices_config( device_config.get("config").get("command_topic") ) - if "camera" in device.device_definition.get("type"): + if "camera" in device.device_definition.get( + "type" + ) or "allinone" in device.device_definition.get("type"): LOGGER.info(f"Found Camera {device.device_definition.get('label')}") camera_config = ha_discovery_cameras( site_id=site_id, @@ -227,6 +229,8 @@ def update_camera_snapshot( Category.INDOOR_CAMERA, Category.OUTDDOR_CAMERA, Category.MYFOX_CAMERA, + Category.SOMFY_ONE_PLUS, + Category.SOMFY_ONE, ]: my_devices = api.get_devices(site_id=site_id, category=category) for device in my_devices: diff --git a/somfyProtect2Mqtt/somfy_protect/api/devices/category.py b/somfyProtect2Mqtt/somfy_protect/api/devices/category.py index 56465e3..57c7fdb 100644 --- a/somfyProtect2Mqtt/somfy_protect/api/devices/category.py +++ b/somfyProtect2Mqtt/somfy_protect/api/devices/category.py @@ -17,6 +17,8 @@ class Category(Enum): MOTION = "Myfox Security Infrared Sensor" SMOKE_DETECTOR = "Somfy Smoke Detector" EXTENDER = "Myfox Security Extender" + SOMFY_ONE_PLUS = "Somfy One Plus" + SOMFY_ONE = "Somfy One" @classmethod def _missing_name_(cls, name): diff --git a/somfyProtect2Mqtt/somfy_protect/api/devices/somfy_one.py b/somfyProtect2Mqtt/somfy_protect/api/devices/somfy_one.py new file mode 100644 index 0000000..78e947f --- /dev/null +++ b/somfyProtect2Mqtt/somfy_protect/api/devices/somfy_one.py @@ -0,0 +1,24 @@ +"""Security InDoor Siren""" +from typing import cast + +from somfy_protect.api.devices.base import SomfyProtectDevice + + +class SomfyOne(SomfyProtectDevice): + """Class to represent Somfy One/One+.""" + + def get_rlink_quality(self) -> float: + """Link Quality in % + + Returns: + float: Link Quality percentage + """ + return cast(float, self.get_status("rlink_quality_percent")) + + def get_battery_level(self) -> float: + """Battery Level + + Returns: + float: Battery Level percentage + """ + return cast(float, self.get_status("battery_level")) From d068800361449a936c6169171d528da16cf729c5 Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 22 May 2022 20:41:39 +0200 Subject: [PATCH 4/7] Slim down Dockerfile and don't run as root --- somfyProtect2Mqtt/.dockerignore | 25 +++++++++++++++++++++ somfyProtect2Mqtt/Dockerfile | 40 +++++++++++++++++++-------------- 2 files changed, 48 insertions(+), 17 deletions(-) create mode 100644 somfyProtect2Mqtt/.dockerignore diff --git a/somfyProtect2Mqtt/.dockerignore b/somfyProtect2Mqtt/.dockerignore new file mode 100644 index 0000000..e12d0af --- /dev/null +++ b/somfyProtect2Mqtt/.dockerignore @@ -0,0 +1,25 @@ +**/__pycache__ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +README.md diff --git a/somfyProtect2Mqtt/Dockerfile b/somfyProtect2Mqtt/Dockerfile index b0f29f0..d196207 100644 --- a/somfyProtect2Mqtt/Dockerfile +++ b/somfyProtect2Mqtt/Dockerfile @@ -1,17 +1,23 @@ -FROM python:3.8-slim-bullseye -LABEL maintainer="Minims" -ENV LANG C.UTF-8 - -STOPSIGNAL SIGINT - -# SomfyProtect2MQTT version -ARG VERSION=0.1.7 - -ADD . /app -WORKDIR /app - -# Install python requirements -RUN pip3 install -r requirements.txt - -# Run -ENTRYPOINT ["python3", "./main.py", "-c", "/config/config.yaml"] \ No newline at end of file +# For more information, please refer to https://aka.ms/vscode-docker-python +FROM python:3.8-slim + +# Keeps Python from generating .pyc files in the container +ENV PYTHONDONTWRITEBYTECODE=1 + +# Turns off buffering for easier container logging +ENV PYTHONUNBUFFERED=1 + +# Install pip requirements +COPY requirements.txt . +RUN python -m pip install -r requirements.txt + +WORKDIR /app +COPY . /app + +# Creates a non-root user with an explicit UID and adds permission to access the /app folder +# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers +RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app +USER appuser + +# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug +ENTRYPOINT ["python", "main.py", "-c", "/config/config.yaml"] From 947e4d8bd1d8a1f55b97d14361d7b211b53b1f47 Mon Sep 17 00:00:00 2001 From: Minims Date: Sun, 22 May 2022 21:08:47 +0200 Subject: [PATCH 5/7] Display Version while starting --- somfyProtect2Mqtt/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/somfyProtect2Mqtt/main.py b/somfyProtect2Mqtt/main.py index 6ed20b5..db87dae 100755 --- a/somfyProtect2Mqtt/main.py +++ b/somfyProtect2Mqtt/main.py @@ -15,6 +15,8 @@ from somfy_protect.api import SomfyProtectApi from somfy_protect.websocket import SomfyProtectWebsocket +VERSION = "0.2.0" + def somfy_protect_loop(somfy_protect_2_mqtt): """SomfyProtect 2 MQTT Loop""" @@ -47,7 +49,7 @@ def somfy_protect_wss_loop(somfy_protect_websocket): # Setup Logger setup_logger(debug=DEBUG, filename="somfyProtect2Mqtt.log") LOGGER = logging.getLogger(__name__) - LOGGER.info("Starting SomfyProtect2Mqtt") + LOGGER.info(f"Starting SomfyProtect2Mqtt {VERSION}") CONFIG = read_config_file(CONFIG_FILE) From 8b114d48612355c7a2f399c371581c57cd6817bc Mon Sep 17 00:00:00 2001 From: Minims Date: Sun, 22 May 2022 21:13:52 +0200 Subject: [PATCH 6/7] Improve logging --- somfyProtect2Mqtt/business/__init__.py | 3 ++- somfyProtect2Mqtt/somfy_protect_2_mqtt.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/somfyProtect2Mqtt/business/__init__.py b/somfyProtect2Mqtt/business/__init__.py index 4c6db4a..aa068cd 100644 --- a/somfyProtect2Mqtt/business/__init__.py +++ b/somfyProtect2Mqtt/business/__init__.py @@ -62,6 +62,7 @@ def ha_devices_config( for site_id in my_sites_id: my_devices = api.get_devices(site_id=site_id) for device in my_devices: + LOGGER.info(f"Configuring Device: {device.label}") settings = device.settings.get("global") status = device.status status_settings = {**status, **settings} @@ -122,7 +123,7 @@ def ha_devices_config( # Works with Websockets if "remote" in device.device_definition.get("type"): - LOGGER.info(f"Found Key Fob {device.device_definition.get('label')}") + LOGGER.info(f"Found {device.device_definition.get('label')}") key_fob_config = ha_discovery_devices( site_id=site_id, device=device, diff --git a/somfyProtect2Mqtt/somfy_protect_2_mqtt.py b/somfyProtect2Mqtt/somfy_protect_2_mqtt.py index 9100769..39a4f04 100644 --- a/somfyProtect2Mqtt/somfy_protect_2_mqtt.py +++ b/somfyProtect2Mqtt/somfy_protect_2_mqtt.py @@ -62,6 +62,7 @@ def __init__( sites = self.api.get_sites() LOGGER.info(f"Found {len(sites)} Site(s)") for site in sites: + LOGGER.info(f"Found Site : {site.label}") if site.label in self.my_sites: LOGGER.info(f"Storing Site ID for {site.label}") self.my_sites_id.append(site.id) From c237cd70275f072162b6669bc22546c1f5d12120 Mon Sep 17 00:00:00 2001 From: Minims Date: Mon, 23 May 2022 22:23:06 +0200 Subject: [PATCH 7/7] Add garage door type --- somfyProtect2Mqtt/homeassistant/ha_discovery.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/somfyProtect2Mqtt/homeassistant/ha_discovery.py b/somfyProtect2Mqtt/homeassistant/ha_discovery.py index 1594665..925c463 100644 --- a/somfyProtect2Mqtt/homeassistant/ha_discovery.py +++ b/somfyProtect2Mqtt/homeassistant/ha_discovery.py @@ -69,7 +69,7 @@ "support_type": { "type": "select", "config": { - "options": ["slidedoor", "window", "externdoor", "slidewindow"], + "options": ["slidedoor", "window", "externdoor", "slidewindow", "garage"], }, }, "video_mode": {