From 1a3bcb88f040126a47fc05d7ca5ac7fdbd2f1e1f Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Wed, 7 Aug 2024 03:26:47 +0200 Subject: [PATCH] Restructured bridges --- src/endpoints/hue.py | 2 +- src/fritz_test.py | 2 +- src/hue/hue_feature.py | 2 +- src/mash/__init__.py | 1 + src/mash/bridges/bedscale.py | 0 src/mash/bridges/fritzbox/__init__.py | 1 + .../bridges/{fritzbox.py => fritzbox/fritzbox_bridge.py} | 2 +- src/mash/bridges/hue/__init__.py | 1 + src/mash/bridges/{hue.py => hue/hue_bridge.py} | 2 +- src/mash/bridges/matrixclock/__init__.py | 1 + .../matrixclock/matrixclock_entity.py} | 2 +- src/mash/bridges/openweatherapi.py | 0 src/mash/bridges/peoplecounter.py | 0 src/mash/bridges/restapi.py | 0 src/mash/bridges/restapi/__init__.py | 1 + src/mash/bridges/restapi/restapi_bridge.py | 6 ++++++ src/mash/bridges/spotify.py | 0 src/mash/bridges/zigbee2mqtt/__init__.py | 1 + .../{zigbee2mqtt.py => zigbee2mqtt/zigbee2mqtt_bridge.py} | 2 +- src/mash/core/__init__.py | 5 +++++ src/mash/{bridges => core}/bridge.py | 0 src/mash/{entities => core}/entity.py | 0 src/mash/{ => core}/feature.py | 0 src/mash/{entities => core}/group.py | 2 +- src/mash/{ => core}/home.py | 4 ++-- src/mash/mash.py | 2 +- src/matrix_clock/matrix_clock_feature.py | 2 +- src/mqtt_test.py | 2 +- 28 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 src/mash/__init__.py delete mode 100644 src/mash/bridges/bedscale.py create mode 100644 src/mash/bridges/fritzbox/__init__.py rename src/mash/bridges/{fritzbox.py => fritzbox/fritzbox_bridge.py} (98%) create mode 100644 src/mash/bridges/hue/__init__.py rename src/mash/bridges/{hue.py => hue/hue_bridge.py} (98%) create mode 100644 src/mash/bridges/matrixclock/__init__.py rename src/mash/{entities/matrixclock.py => bridges/matrixclock/matrixclock_entity.py} (97%) delete mode 100644 src/mash/bridges/openweatherapi.py delete mode 100644 src/mash/bridges/peoplecounter.py delete mode 100644 src/mash/bridges/restapi.py create mode 100644 src/mash/bridges/restapi/__init__.py create mode 100644 src/mash/bridges/restapi/restapi_bridge.py delete mode 100644 src/mash/bridges/spotify.py create mode 100644 src/mash/bridges/zigbee2mqtt/__init__.py rename src/mash/bridges/{zigbee2mqtt.py => zigbee2mqtt/zigbee2mqtt_bridge.py} (98%) create mode 100644 src/mash/core/__init__.py rename src/mash/{bridges => core}/bridge.py (100%) rename src/mash/{entities => core}/entity.py (100%) rename src/mash/{ => core}/feature.py (100%) rename src/mash/{entities => core}/group.py (98%) rename src/mash/{ => core}/home.py (62%) diff --git a/src/endpoints/hue.py b/src/endpoints/hue.py index 72be1cf..d237e42 100644 --- a/src/endpoints/hue.py +++ b/src/endpoints/hue.py @@ -1,7 +1,7 @@ from fastapi import FastAPI, APIRouter from hue.hue_adapter import HueAdapter -from ..mash.feature import Feature +from ..mash.core.feature import Feature from fastapi import APIRouter from fastapi.responses import HTMLResponse diff --git a/src/fritz_test.py b/src/fritz_test.py index 7a80f96..7bf1b00 100644 --- a/src/fritz_test.py +++ b/src/fritz_test.py @@ -1,4 +1,4 @@ -from mash.bridges.fritzbox import FritzBoxBridge, FritzDeviceState +from mash.bridges.fritzbox.fritzbox_bridge import FritzBoxBridge, FritzDeviceState from time import sleep import logging diff --git a/src/hue/hue_feature.py b/src/hue/hue_feature.py index 72be1cf..d237e42 100644 --- a/src/hue/hue_feature.py +++ b/src/hue/hue_feature.py @@ -1,7 +1,7 @@ from fastapi import FastAPI, APIRouter from hue.hue_adapter import HueAdapter -from ..mash.feature import Feature +from ..mash.core.feature import Feature from fastapi import APIRouter from fastapi.responses import HTMLResponse diff --git a/src/mash/__init__.py b/src/mash/__init__.py new file mode 100644 index 0000000..1ce177f --- /dev/null +++ b/src/mash/__init__.py @@ -0,0 +1 @@ +from .mash import MaSH diff --git a/src/mash/bridges/bedscale.py b/src/mash/bridges/bedscale.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/mash/bridges/fritzbox/__init__.py b/src/mash/bridges/fritzbox/__init__.py new file mode 100644 index 0000000..291e9de --- /dev/null +++ b/src/mash/bridges/fritzbox/__init__.py @@ -0,0 +1 @@ +from .fritzbox_bridge import FritzBoxBridge diff --git a/src/mash/bridges/fritzbox.py b/src/mash/bridges/fritzbox/fritzbox_bridge.py similarity index 98% rename from src/mash/bridges/fritzbox.py rename to src/mash/bridges/fritzbox/fritzbox_bridge.py index 1e75c5e..9f6eb42 100644 --- a/src/mash/bridges/fritzbox.py +++ b/src/mash/bridges/fritzbox/fritzbox_bridge.py @@ -1,7 +1,7 @@ from datetime import datetime import logging from typing import Coroutine, Optional -from mash.bridges.bridge import Bridge +from mash.core.bridge import Bridge from fritzconnection import FritzConnection import asyncio diff --git a/src/mash/bridges/hue/__init__.py b/src/mash/bridges/hue/__init__.py new file mode 100644 index 0000000..fc873ea --- /dev/null +++ b/src/mash/bridges/hue/__init__.py @@ -0,0 +1 @@ +from .hue_bridge import HueBridge diff --git a/src/mash/bridges/hue.py b/src/mash/bridges/hue/hue_bridge.py similarity index 98% rename from src/mash/bridges/hue.py rename to src/mash/bridges/hue/hue_bridge.py index 85b1e07..3755b55 100644 --- a/src/mash/bridges/hue.py +++ b/src/mash/bridges/hue/hue_bridge.py @@ -1,5 +1,5 @@ import logging -from mash.bridges.bridge import Bridge +from mash.core.bridge import Bridge from phue import Bridge as phueBridge from time import sleep diff --git a/src/mash/bridges/matrixclock/__init__.py b/src/mash/bridges/matrixclock/__init__.py new file mode 100644 index 0000000..7cc944e --- /dev/null +++ b/src/mash/bridges/matrixclock/__init__.py @@ -0,0 +1 @@ +from .matrixclock_entity import MatrixClockEntity diff --git a/src/mash/entities/matrixclock.py b/src/mash/bridges/matrixclock/matrixclock_entity.py similarity index 97% rename from src/mash/entities/matrixclock.py rename to src/mash/bridges/matrixclock/matrixclock_entity.py index 46fbce4..5a99baa 100644 --- a/src/mash/entities/matrixclock.py +++ b/src/mash/bridges/matrixclock/matrixclock_entity.py @@ -1,4 +1,4 @@ -from mash.entities.entity import Entity +from mash.core.entity import Entity import requests as r diff --git a/src/mash/bridges/openweatherapi.py b/src/mash/bridges/openweatherapi.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/mash/bridges/peoplecounter.py b/src/mash/bridges/peoplecounter.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/mash/bridges/restapi.py b/src/mash/bridges/restapi.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/mash/bridges/restapi/__init__.py b/src/mash/bridges/restapi/__init__.py new file mode 100644 index 0000000..6fb54e0 --- /dev/null +++ b/src/mash/bridges/restapi/__init__.py @@ -0,0 +1 @@ +from .restapi_bridge import RestApiBridge diff --git a/src/mash/bridges/restapi/restapi_bridge.py b/src/mash/bridges/restapi/restapi_bridge.py new file mode 100644 index 0000000..b50a8b6 --- /dev/null +++ b/src/mash/bridges/restapi/restapi_bridge.py @@ -0,0 +1,6 @@ +from mash.core.bridge import Bridge + + +class RestApiBridge(Bridge): + def __init__(self, *, id: str) -> None: + super().__init__(id=id, type="restapi") diff --git a/src/mash/bridges/spotify.py b/src/mash/bridges/spotify.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/mash/bridges/zigbee2mqtt/__init__.py b/src/mash/bridges/zigbee2mqtt/__init__.py new file mode 100644 index 0000000..24a7184 --- /dev/null +++ b/src/mash/bridges/zigbee2mqtt/__init__.py @@ -0,0 +1 @@ +from .zigbee2mqtt_bridge import Z2mBridge diff --git a/src/mash/bridges/zigbee2mqtt.py b/src/mash/bridges/zigbee2mqtt/zigbee2mqtt_bridge.py similarity index 98% rename from src/mash/bridges/zigbee2mqtt.py rename to src/mash/bridges/zigbee2mqtt/zigbee2mqtt_bridge.py index f17ef5e..fc162ca 100644 --- a/src/mash/bridges/zigbee2mqtt.py +++ b/src/mash/bridges/zigbee2mqtt/zigbee2mqtt_bridge.py @@ -1,6 +1,6 @@ import logging from typing import Optional -from mash.bridges.bridge import Bridge +from mash.core.bridge import Bridge import paho.mqtt.client as mqtt import json diff --git a/src/mash/core/__init__.py b/src/mash/core/__init__.py new file mode 100644 index 0000000..ed333cb --- /dev/null +++ b/src/mash/core/__init__.py @@ -0,0 +1,5 @@ +from .bridge import Bridge, BridgeException +from .entity import Entity +from .group import Group +from .home import Home +from .feature import Feature diff --git a/src/mash/bridges/bridge.py b/src/mash/core/bridge.py similarity index 100% rename from src/mash/bridges/bridge.py rename to src/mash/core/bridge.py diff --git a/src/mash/entities/entity.py b/src/mash/core/entity.py similarity index 100% rename from src/mash/entities/entity.py rename to src/mash/core/entity.py diff --git a/src/mash/feature.py b/src/mash/core/feature.py similarity index 100% rename from src/mash/feature.py rename to src/mash/core/feature.py diff --git a/src/mash/entities/group.py b/src/mash/core/group.py similarity index 98% rename from src/mash/entities/group.py rename to src/mash/core/group.py index 04b818c..e270749 100644 --- a/src/mash/entities/group.py +++ b/src/mash/core/group.py @@ -1,4 +1,4 @@ -from mash.entities.entity import Entity +from mash.core.entity import Entity from fnmatch import fnmatch diff --git a/src/mash/home.py b/src/mash/core/home.py similarity index 62% rename from src/mash/home.py rename to src/mash/core/home.py index a3778b5..6dda77d 100644 --- a/src/mash/home.py +++ b/src/mash/core/home.py @@ -1,5 +1,5 @@ -from mash.entities.entity import Entity -from mash.entities.group import Group +from mash.core.entity import Entity +from mash.core.group import Group class Home(Group): diff --git a/src/mash/mash.py b/src/mash/mash.py index 64b649d..553dcbb 100644 --- a/src/mash/mash.py +++ b/src/mash/mash.py @@ -1,7 +1,7 @@ import yaml from fastapi import FastAPI -from mash.feature import Feature +from mash.core.feature import Feature class MaSH: diff --git a/src/matrix_clock/matrix_clock_feature.py b/src/matrix_clock/matrix_clock_feature.py index fb03235..25cabbf 100644 --- a/src/matrix_clock/matrix_clock_feature.py +++ b/src/matrix_clock/matrix_clock_feature.py @@ -1,4 +1,4 @@ -from mash.feature import Feature +from mash.core.feature import Feature class MatrixClockIntegration(Feature): diff --git a/src/mqtt_test.py b/src/mqtt_test.py index 9fda9cd..cbbdd85 100644 --- a/src/mqtt_test.py +++ b/src/mqtt_test.py @@ -1,5 +1,5 @@ from time import sleep -from mash.bridges.zigbee2mqtt import Z2mBridge +from mash.bridges.zigbee2mqtt.zigbee2mqtt_bridge import Z2mBridge z2m = Z2mBridge(id="z2m", ip="192.168.178.115")