asd
This commit is contained in:
32
init.py
32
init.py
@@ -3,10 +3,41 @@ from astral import LocationInfo
|
||||
from astral.sun import sun
|
||||
from datetime import date, datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
import requests
|
||||
|
||||
from grove.gpio import GPIO
|
||||
from grove.display.jhd1802 import JHD1802
|
||||
|
||||
shelly_server = "https://shelly-237-eu.shelly.cloud"
|
||||
shelly_token = "M2M5YTYxdWlkEFD82A2301693D62637E530B4CDDC0DC6E2CDD8F01BE5E5102000B92638A2DA74019E6A81E6D17E0"
|
||||
|
||||
shelly_deviceId = "8cbfea9fd6d0"
|
||||
|
||||
def setShellyPlugState(deviceId: str, state: bool) -> dict:
|
||||
"""
|
||||
Set the state of a Shelly plug/switch device.
|
||||
|
||||
Args:
|
||||
deviceId: The Shelly device id
|
||||
state: True to turn on, False to turn off
|
||||
|
||||
Returns:
|
||||
Response from the API as a dictionary
|
||||
"""
|
||||
url = f"{shelly_server}/v2/devices/api/set/switch"
|
||||
params = {"auth_key": shelly_token}
|
||||
payload = {
|
||||
"id": deviceId,
|
||||
"on": state
|
||||
}
|
||||
|
||||
response = requests.post(url, params=params, json=payload)
|
||||
|
||||
if response.status_code == 200:
|
||||
return {"success": True}
|
||||
else:
|
||||
return response.json()
|
||||
|
||||
city = LocationInfo("Seinäjoki", "Finland", "Europe/Helsinki", 62.7900, 22.8400)
|
||||
s = sun(city.observer, date=date.today())
|
||||
print(f"City: {city.name}, {city.region}")
|
||||
@@ -94,6 +125,7 @@ class AlarmClock:
|
||||
if self.configMode == "normal":
|
||||
# Normal mode: toggle relay
|
||||
self.setRelayState(not self.relayGpio.read())
|
||||
setShellyPlugState(shelly_deviceId, self.relayGpio.read() == 1)
|
||||
elif self.configMode == "set_hour":
|
||||
# Increment hour
|
||||
self.alarmHour = (self.alarmHour + 1) % 24
|
||||
|
||||
Reference in New Issue
Block a user