Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/demo #52

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 1 addition & 37 deletions Devices/LawnMower.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
from device import NotCompatibleDevice, Device, load_json, save_json
from .device import NotCompatibleDevice, Device, load_json, save_json


class LawnMower(Device):
def __init__(self, device_id: str, device_type: str):
super().__init__(device_id, device_type)

def get_name(self) -> str | None:
"""
Get the name of the lawn mower.
"""
return self.load_device_info().get('name', None)

def get_brand(self) -> str | None:
"""
Get the brand of the lawn mower.
"""
return self.load_device_info().get('brand', None)

def get_model(self) -> str | None:
"""
Get the model of the lawn mower.
"""
return self.load_device_info().get('model', None)

def get_power(self) -> str | None:
"""
Get the current power status of the lawn mower (on or off).
Expand Down Expand Up @@ -59,33 +41,15 @@ def get_total_cutting_time(self) -> int | None:
"""
return self.load_device_info().get('status', {}).get('total_cutting_time_minutes', None)

def get_location(self) -> str | None:
"""
Get the location of the lawn mower.
"""
return self.load_device_info().get('location', None)

def get_last_updated(self) -> str | None:
"""
Get the last updated time of the lawn mower.
"""
return self.load_device_info().get('last_updated', None)

if __name__ == "__main__":
lawn_mower_device = LawnMower("mower98765", "LawnMower")
lawn_mower_device.connect_to_device()


print("Name:", lawn_mower_device.get_name())
print("Brand:", lawn_mower_device.get_brand())
print("Model:", lawn_mower_device.get_model())
print("Power:", lawn_mower_device.get_power())
print("Battery Percentage:", lawn_mower_device.get_battery_percent())
print("Cutting Mode:", lawn_mower_device.get_cutting_mode())
print("Cutting Height (mm):", lawn_mower_device.get_cutting_height())
print("Current Area (m²):", lawn_mower_device.get_current_area())
print("Total Cutting Time (minutes):", lawn_mower_device.get_total_cutting_time())
print("Location:", lawn_mower_device.get_location())
print("Last Updated:", lawn_mower_device.get_last_updated())

lawn_mower_device.turn_on_off("off")
42 changes: 4 additions & 38 deletions Devices/WeatherStation.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
from device import NotCompatibleDevice, Device, load_json, save_json
from .device import NotCompatibleDevice, Device, load_json, save_json


class WeatherStation(Device):
def __init__(self, device_id: str, device_type: str):
super().__init__(device_id, device_type)

def get_name(self) -> str:
"""
Get the name of the weather station.
"""
return self.load_device_info().get('name', None)

def get_brand(self) -> str:
"""
Get the brand of the weather station.
"""
return self.load_device_info().get('brand', None)

def get_model(self) -> str:
"""
Get the model of the weather station.
"""
return self.load_device_info().get('model', None)
super().__init__(device_id, device_type)

def get_temperature(self) -> float:
"""
Expand Down Expand Up @@ -51,34 +33,18 @@ def get_rainfall(self) -> float:
"""
Get the rainfall measurement in millimeters.
"""
return self.load_device_info().get('status', {}).get('rainfall_mm', None)

def get_location(self) -> str:
"""
Get the location of the weather station.
"""
return self.load_device_info().get('location', None)

def get_last_updated(self) -> str:
"""
Get the last updated timestamp of the weather station.
"""
return self.load_device_info().get('last_updated', None)
return self.load_device_info().get('status', {}).get('rainfall_mm', None)

if __name__ == "__main__":
weather_station_device = WeatherStation("weatherstation56789", "WeatherStation")
weather_station_device.connect_to_device()


print("Name:", weather_station_device.get_name())
print("Brand:", weather_station_device.get_brand())
print("Model:", weather_station_device.get_model())

print("Temperature (C):", weather_station_device.get_temperature())
print("Humidity (%):", weather_station_device.get_humidity())
print("Pressure (hPa):", weather_station_device.get_pressure())
print("Wind Speed (km/h):", weather_station_device.get_wind_speed())
print("Rainfall (mm):", weather_station_device.get_rainfall())
print("Location:", weather_station_device.get_location())
print("Last Updated:", weather_station_device.get_last_updated())

weather_station_device.turn_on_off("off")
29 changes: 1 addition & 28 deletions Devices/bulb.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
from device import NotCompatibleDevice, Device, load_json, save_json
from .device import NotCompatibleDevice, Device, load_json, save_json


class Bulb(Device):
def __init__(self, device_id: str, device_type: str):
super().__init__(device_id, device_type)

def get_name(self) -> str | None:
"""
Get the name of the bulb.

The name of the bulb as a string, or None if not found.
"""
return self.load_device_info().get('name', None)

def get_brand(self) -> str | None:
"""
Get the brand of the bulb.

The brand of the bulb as a string, or None if not found.
"""
return self.load_device_info().get('brand', None)

def get_model(self) -> str | None:
"""
Get the model of the bulb.

The model of the bulb as a string, or None if not found.
"""
return self.load_device_info().get('model', None)

def get_power(self) -> str | None:
"""
Get the current power status of the bulb (on or off).
Expand Down Expand Up @@ -64,9 +40,6 @@ def get_rgb(self) -> dict | None:
if __name__ == '__main__':
bulb_device = Bulb("1234567890abcdef", "Bulb")
bulb_device.connect_to_device()
print("Name:", bulb_device.get_name())
print("Brand:", bulb_device.get_brand())
print("Model:", bulb_device.get_model())
print("Power:", bulb_device.get_power())
print("Brightness:", bulb_device.get_brightness())
print("Color Temperature:", bulb_device.get_color_temp())
Expand Down
2 changes: 1 addition & 1 deletion Devices/curtain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from device import NotCompatibleDevice, Device, load_json
from .device import NotCompatibleDevice, Device, load_json

class Curtain(Device):
def __init__(self, device_id: str, device_type: str):
Expand Down
3 changes: 2 additions & 1 deletion Devices/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import json
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from datetime import datetime
from colorama import Fore, init

sys.path.append(os.path.abspath('..'))
from logging_config import get_logger

FILE_PATH = "../devices.json"
FILE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../devices.json")
MAX_ATTEMPTS = 3
# Initialize Colorama (necessary for Windows compatibility)
init(autoreset=True)
Expand Down
2 changes: 1 addition & 1 deletion Devices/plug.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from device import NotCompatibleDevice, Device, load_json
from .device import NotCompatibleDevice, Device, load_json

class Plug(Device):
def __init__(self, device_id: str, device_type: str):
Expand Down
2 changes: 1 addition & 1 deletion Devices/thermostat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from device import NotCompatibleDevice, Device, load_json
from .device import NotCompatibleDevice, Device, load_json

class Thermostat(Device):
def __init__(self, device_id: str, device_type: str):
Expand Down
36 changes: 18 additions & 18 deletions devices.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"devices": [
{
"device_id": "1234567890abcdef",
"device_id": "bulb1",
"device_secret_key": "xxx",
"name": "Smart Light Bulb",
"name": "bulb111111",
"type": "bulb",
"brand": "Tuya",
"model": "TY-SLB-01",
"status": {
"power": "OFF",
"power": "on",
"brightness": 80,
"color_temp": 5000,
"rgb": {
Expand All @@ -19,10 +19,10 @@
},
"location": "Living Room",
"connected": true,
"last_updated": "2024-12-01 20:12:21"
"last_updated": "2024-12-14 14:43:20"
},
{
"device_id": "abcdef1234567890",
"device_id": "bulb2",
"device_secret_key": "xxx",
"name": "Smart Light Bulb",
"type": "bulb",
Expand All @@ -43,14 +43,14 @@
"last_updated": "2024-10-19T14:52:00Z"
},
{
"device_id": "1234567890abcdef",
"device_id": "bulb3",
"device_secret_key": "xxx",
"name": "Smart Light Bulb",
"type": "bulb",
"brand": "Tuya",
"model": "TY-SLB-01",
"status": {
"power": "off",
"power": "on",
"brightness": 80,
"color_temp": 5000,
"rgb": {
Expand All @@ -64,7 +64,7 @@
"last_updated": "2024-10-19T14:52:00Z"
},
{
"device_id": "abcdef1234567999",
"device_id": "plug1",
"device_secret_key": "xxx",
"name": "new_plug_name",
"type": "plug",
Expand All @@ -82,7 +82,7 @@
"last_updated": "2024-12-01 20:04:41"
},
{
"device_id": "abcdef1234561547",
"device_id": "plug2",
"device_secret_key": "xxx",
"name": "Smart Plug",
"type": "plug",
Expand All @@ -100,7 +100,7 @@
"last_updated": "2024-10-19T14:50:00Z"
},
{
"device_id": "abcdef123456578",
"device_id": "plug3",
"device_secret_key": "xxx",
"name": "Smart Plug",
"type": "plug",
Expand All @@ -118,7 +118,7 @@
"last_updated": "2024-10-19T14:50:00Z"
},
{
"device_id": "abcdef1234563298",
"device_id": "thermostat1",
"device_secret_key": "xxx",
"name": "Smart Thermostat",
"type": "thermostat",
Expand All @@ -135,7 +135,7 @@
"last_updated": "2024-10-19T14:55:00Z"
},
{
"device_id": "curtain12345",
"device_id": "curtain1",
"device_secret_key": "xxx",
"name": "Automatic Curtain",
"type": "curtain",
Expand All @@ -151,10 +151,10 @@
"last_updated": "2024-10-19T14:58:00Z"
},
{
"device_id": "weatherstation56789",
"device_id": "station1",
"device_secret_key": "xxx",
"name": "Smart Weather Station",
"type": "weather_station",
"type": "weatherstation",
"brand": "Tuya",
"model": "TY-WS-01",
"status": {
Expand All @@ -170,14 +170,14 @@
"last_updated": "2024-12-01 20:26:09"
},
{
"device_id": "mower98765",
"device_id": "mower1",
"device_secret_key": "xxx",
"name": "Automatic Lawn Mower",
"type": "lawn_mower",
"type": "lawnmower",
"brand": "Tuya",
"model": "TY-AM-01",
"status": {
"power": "off",
"power": "on",
"battery_percent": 85,
"cutting_mode": "auto",
"cutting_height_mm": 30,
Expand All @@ -186,7 +186,7 @@
},
"location": "Backyard",
"connected": true,
"last_updated": "2024-12-01 20:20:42"
"last_updated": "2024-12-14 14:47:52"
}
]
}
Loading