Skip to content

Commit

Permalink
Merge pull request #120 from Minims/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Minims authored Sep 11, 2023
2 parents 12b3255 + 3275943 commit 69befef
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 24 deletions.
5 changes: 2 additions & 3 deletions somfyProtect2Mqtt/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ COPY requirements.txt .

RUN apt-get update \
&& apt-get install --yes --no-install-recommends \
build-essential zlib1g-dev libjpeg62-turbo-dev ffmpeg \
&& python -m pip install -r requirements.txt \
&& apt-get autoremove --yes build-essential zlib1g-dev libjpeg62-turbo-dev \
python3-opencv ffmpeg \
&& python -m pip install -r requirements_addons.txt \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /app
Expand Down
24 changes: 6 additions & 18 deletions somfyProtect2Mqtt/business/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,14 @@ def update_site(api, mqtt_client, mqtt_config, site_id):
mqtt_publish(
mqtt_client=mqtt_client,
topic=f"{mqtt_config.get('topic_prefix', 'somfyProtect2mqtt')}/{site_id}/state",
payload={
"security_level": ALARM_STATUS.get(site.security_level, "disarmed")
},
payload={"security_level": ALARM_STATUS.get(site.security_level, "disarmed")},
retain=True,
)
except Exception as exp:
LOGGER.warning(f"Error while refreshing site {site_id}: {exp}")


def consume_mqtt_message(
msg, mqtt_config: dict, api: SomfyProtectApi, mqtt_client: client
):
def consume_mqtt_message(msg, mqtt_config: dict, api: SomfyProtectApi, mqtt_client: client):
"""Compute MQTT received message"""
try:
text_payload = msg.payload.decode("UTF-8")
Expand Down Expand Up @@ -134,9 +130,7 @@ def consume_mqtt_message(
site_id = msg.topic.split("/")[1]
device_id = msg.topic.split("/")[2]
if device_id:
LOGGER.info(
f"Message received for Site ID: {site_id}, Device ID: {device_id}, Action: {text_payload}"
)
LOGGER.info(f"Message received for Site ID: {site_id}, Device ID: {device_id}, Action: {text_payload}")
action_device = api.action_device(
site_id=site_id,
device_id=device_id,
Expand All @@ -153,9 +147,7 @@ def consume_mqtt_message(
device_id=device_id,
)
else:
LOGGER.info(
f"Message received for Site ID: {site_id}, Action: {text_payload}"
)
LOGGER.info(f"Message received for Site ID: {site_id}, Action: {text_payload}")

# Manage Manual Snapshot
elif msg.topic.split("/")[3] == "snapshot":
Expand Down Expand Up @@ -193,9 +185,7 @@ def consume_mqtt_message(
if setting == "stream":
return
device = api.get_device(site_id=site_id, device_id=device_id)
LOGGER.info(
f"Message received for Site ID: {site_id}, Device ID: {device_id}, Setting: {setting}"
)
LOGGER.info(f"Message received for Site ID: {site_id}, Device ID: {device_id}, Setting: {setting}")
settings = device.settings
settings["global"][setting] = text_payload
api.update_device(
Expand All @@ -215,6 +205,4 @@ def consume_mqtt_message(
)

except Exception as exp:
LOGGER.error(
f"Error when processing message: {exp}: {msg.topic} => {msg.payload}"
)
LOGGER.error(f"Error when processing message: {exp}: {msg.topic} => {msg.payload}")
4 changes: 2 additions & 2 deletions somfyProtect2Mqtt/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
version: '3'
services:
somfyprotect2mqtt:
build: .
image: somfyprotect2mqtt:v2023.9.1
image: somfyprotect2mqtt:v2023.9.2
volumes:
- ./config:/config
1 change: 1 addition & 0 deletions somfyProtect2Mqtt/homeassistant/ha_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ def ha_discovery_alarm(site: Site, mqtt_config: dict, homeassistant_config: dict
"payload_arm_night": "partial",
"payload_disarm": "disarmed",
"value_template": "{{ value_json.security_level }}",
"supported_features": ["arm_night", "arm_away", "trigger"],
"device": site_info,
}
if code and (isinstance(code, int)):
Expand Down
2 changes: 1 addition & 1 deletion somfyProtect2Mqtt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from somfy_protect.api import SomfyProtectApi
from somfy_protect.websocket import SomfyProtectWebsocket

VERSION = "2023.9.1"
VERSION = "2023.9.2"


def somfy_protect_loop(config, mqtt_client, api):
Expand Down

0 comments on commit 69befef

Please sign in to comment.