Skip to content

Commit

Permalink
Merge pull request #24 from Minims/dev
Browse files Browse the repository at this point in the history
2024.9.1
  • Loading branch information
Minims authored Sep 16, 2024
2 parents 79b9938 + da9a0da commit bd3c172
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion myFox2Mqtt/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /
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"]
ENTRYPOINT ["python", "main.py", "-c", "/config/config.yaml", "-l", "''"]
15 changes: 14 additions & 1 deletion myFox2Mqtt/business/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Business Functions"""

import logging
from datetime import datetime, timedelta
import pytz
from time import sleep

from exceptions import MyFoxInitError
Expand Down Expand Up @@ -372,6 +374,15 @@ def ha_devices_config(
)


def convert_utc_to_paris(date: datetime) -> datetime:

utc_zone = pytz.utc
date = utc_zone.localize(date)
paris_zone = pytz.timezone("Europe/Paris")
paris_date = date.astimezone(paris_zone)
return paris_date


def update_sites_status(
api: MyFoxApi,
mqtt_client: MQTTClient,
Expand All @@ -389,7 +400,9 @@ def update_sites_status(
created_at = event.get("createdAt")
date_format = "%Y-%m-%dT%H:%M:%SZ"
created_at_date = datetime.strptime(created_at, date_format)
now = datetime.now()
created_at_date = convert_utc_to_paris(date=created_at_date)
paris_tz = pytz.timezone("Europe/Paris")
now = datetime.now(paris_tz)
if now - created_at_date < timedelta(seconds=90):
if created_at in HISTORY:
LOGGER.info(f"History still published: {HISTORY[created_at]}")
Expand Down
2 changes: 1 addition & 1 deletion myFox2Mqtt/config/config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ mqtt:
ha_discover_prefix: "homeassistant"

# MyFox2MQTT
delay_site: 10 # seconds
delay_site: 60 # seconds
delay_device: 60 # seconds
manual_snapshot: false
2 changes: 1 addition & 1 deletion myFox2Mqtt/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ version: "3"
services:
myfox2mqtt:
build: .
image: myfox2mqtt:v2023.11.0
image: myfox2mqtt:v2024.9.1
volumes:
- ./config:/config
6 changes: 4 additions & 2 deletions myFox2Mqtt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from myfox.sso import init_sso
from myfox.api import MyFoxApi

VERSION = "2023.11.0"
VERSION = "2024.9.1"


def myfox_loop(config, mqtt_client, api):
Expand All @@ -31,12 +31,14 @@ def myfox_loop(config, mqtt_client, api):
PARSER = argparse.ArgumentParser()
PARSER.add_argument("--verbose", "-v", action="store_true", help="verbose mode")
PARSER.add_argument("--configuration", "-c", type=str, help="config file path")
PARSER.add_argument("--logfile", "-l", type=str, help="logfile", default="myFox2Mqtt.log")
ARGS = PARSER.parse_args()
DEBUG = ARGS.verbose
CONFIG_FILE = ARGS.configuration
LOG_FILE = ARGS.logfile

# Setup Logger
setup_logger(debug=DEBUG, filename="myFox2Mqtt.log")
setup_logger(debug=DEBUG, filename=LOG_FILE)
LOGGER = logging.getLogger(__name__)
LOGGER.info(f"Starting MyFox2Mqtt {VERSION}")

Expand Down
5 changes: 3 additions & 2 deletions myFox2Mqtt/myfox_2_mqtt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""MyFox 2 Mqtt"""

import logging
from time import sleep

Expand Down Expand Up @@ -41,10 +42,10 @@ def __init__(self, api: MyFoxApi, mqtt_client: MQTTClient, config: dict) -> None
self.my_sites_id = []

self.delay_site = config.get("delay_site", 60)
self.delay_site = max(self.delay_site, 10)
self.delay_site = max(self.delay_site, 60)

self.delay_device = config.get("delay_device", 60)
self.delay_device = max(self.delay_device, 10)
self.delay_device = max(self.delay_device, 60)

self.manual_snapshot = config.get("manual_snapshot", False)

Expand Down
1 change: 1 addition & 0 deletions myFox2Mqtt/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ paho-mqtt==1.6.1
pyyaml==6.0.1
requests-oauthlib==1.3.1
schedule==1.2.0
pytz==2024.1
14 changes: 9 additions & 5 deletions myFox2Mqtt/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@
LOGGER = logging.getLogger(__name__)


def setup_logger(debug: bool = False, filename: str = "/var/log/myFox.log") -> None:
def setup_logger(filename: str, debug: bool = False) -> None:
"""Setup Logging
Args:
debug (bool, optional): True if debug enabled. Defaults to False.
filename (str, optional): log filename. Defaults to "/var/log/myFox.log".
"""
log_level = logging.DEBUG if debug else logging.INFO
handlers = [
logging.StreamHandler(),
]
if filename:
handlers.append(logging.FileHandler(filename=filename))

logging.basicConfig(
level=log_level,
format="%(asctime)s [%(levelname)s] [%(name)s:%(lineno)d] %(message)s",
handlers=[
logging.StreamHandler(),
logging.FileHandler(filename=filename),
],
handlers=handlers,
)



def read_config_file(config_file: str) -> Dict[str, Any]:
"""Read config file
Expand Down

0 comments on commit bd3c172

Please sign in to comment.