Skip to content

Commit

Permalink
Merge pull request #49 from Minims/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Minims authored May 23, 2022
2 parents fd5d99c + ef78639 commit 977e0f2
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 33 deletions.
25 changes: 25 additions & 0 deletions somfyProtect2Mqtt/.dockerignore
Original file line number Diff line number Diff line change
@@ -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
44 changes: 23 additions & 21 deletions somfyProtect2Mqtt/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +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

# 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

# Install python requirements
WORKDIR /usr/src/SomfyProtect2MQTT/somfyProtect2Mqtt
RUN pip3 install -r requirements.txt

# Run
ENTRYPOINT ["./docker-entrypoint.sh"]
# 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"]
9 changes: 7 additions & 2 deletions somfyProtect2Mqtt/business/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -87,7 +88,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,
Expand Down Expand Up @@ -120,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,
Expand Down Expand Up @@ -227,6 +230,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:
Expand Down
10 changes: 2 additions & 8 deletions somfyProtect2Mqtt/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
2 changes: 1 addition & 1 deletion somfyProtect2Mqtt/homeassistant/ha_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"support_type": {
"type": "select",
"config": {
"options": ["slidedoor", "window", "externdoor", "slidewindow"],
"options": ["slidedoor", "window", "externdoor", "slidewindow", "garage"],
},
},
"video_mode": {
Expand Down
4 changes: 3 additions & 1 deletion somfyProtect2Mqtt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions somfyProtect2Mqtt/somfy_protect/api/devices/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
24 changes: 24 additions & 0 deletions somfyProtect2Mqtt/somfy_protect/api/devices/somfy_one.py
Original file line number Diff line number Diff line change
@@ -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"))
1 change: 1 addition & 0 deletions somfyProtect2Mqtt/somfy_protect_2_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 977e0f2

Please sign in to comment.