-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(attachments): use once instance of mqtt
- Loading branch information
Showing
5 changed files
with
55 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,42 @@ | ||
from mqtt.mqtt_camera import MqttCamera | ||
from camera.camera_manager import CameraManager as CM | ||
from camera.camera_factory import camera_factory | ||
from camera.camera import Camera | ||
import paho.mqtt.client as mqtt | ||
from functools import partial | ||
import os | ||
import json | ||
|
||
|
||
def create_mqtt_client(mqtt_user: str, mqtt_pswd: str, mqtt_hostname: str, mqtt_port: str): | ||
client = mqtt.Client(client_id='rpi4-alarm-motion', clean_session=False) | ||
client.username_pw_set(mqtt_user, mqtt_pswd) | ||
|
||
client.connect(mqtt_hostname, int(mqtt_port), keepalive=120) | ||
|
||
# mqtt.Client | ||
return client | ||
|
||
mqtt_client = create_mqtt_client( | ||
os.environ['MQTT_USER'], | ||
os.environ['MQTT_PASSWORD'], | ||
os.environ['MQTT_HOSTNAME'], | ||
os.environ['MQTT_PORT'] | ||
) | ||
|
||
print(f'mqtt_client: {mqtt_client}') | ||
MQTT_ALARM_CAMERA_TOPIC = os.environ['MQTT_ALARM_CAMERA_TOPIC'] | ||
|
||
camera_factory = partial(camera_factory, mqtt_client) | ||
|
||
# c = Camera(mqtt_client) | ||
# # c.start() | ||
|
||
# c._presenceCallback(True, 'fdp') | ||
|
||
# infot = mqtt_client.publish('motion/camera', payload=json.dumps({"coucou": True}), qos=2) | ||
|
||
print('coucou') | ||
manager = CM(camera_factory) | ||
mqtt_camera_manager = MqttCamera(manager) | ||
mqtt_camera_manager = MqttCamera(mqtt_client, manager, MQTT_ALARM_CAMERA_TOPIC) | ||
|
||
mqtt_client.loop_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .camera import Camera | ||
|
||
def camera_factory() -> Camera: | ||
return Camera() | ||
def camera_factory(mqtt_client) -> Camera: | ||
return Camera(mqtt_client) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters