2022-12-15 12:13:09 +00:00
|
|
|
from lib import migenie, utils
|
2022-12-15 14:51:58 +00:00
|
|
|
from flask_restful import reqparse
|
|
|
|
from time import sleep
|
2022-12-15 12:13:09 +00:00
|
|
|
|
|
|
|
def get_heating_root()->dict:
|
|
|
|
"""_summary_
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
dict: _description_
|
|
|
|
"""
|
|
|
|
data = migenie.get_heating_data()
|
|
|
|
return data, 200
|
|
|
|
|
|
|
|
def get_heating_status()->dict:
|
|
|
|
"""_summary_
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
dict: _description_
|
|
|
|
"""
|
|
|
|
data = migenie.get_heating_data()['status']
|
|
|
|
heatingStatus = {
|
|
|
|
"heatingOn": utils.is_item_on(data['currentSetpoint']),
|
2022-12-15 14:51:58 +00:00
|
|
|
"measuredRoomTemp": utils.format_temp(data['measuredRoomTemp']),
|
2022-12-15 12:13:09 +00:00
|
|
|
"currentSetpoint": utils.convert_to_real_temp(data['currentSetpoint']),
|
|
|
|
"lastTimerSetPoint": utils.convert_to_real_temp(data['lastTimerSetPoint']),
|
|
|
|
"lastTimerDurationMinutes": data['lastTimerDurationMinutes'],
|
2022-12-15 12:37:46 +00:00
|
|
|
"nextScheduleEventUtcTime": utils.format_datetime(data['nextScheduleEventUtcTime']),
|
|
|
|
"nextEventTime":utils.format_time(data['nextScheduleEventUtcTime'])
|
2022-12-15 12:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return heatingStatus, 200
|
2022-12-15 14:51:58 +00:00
|
|
|
|
|
|
|
def turn_on_heating()->dict:
|
|
|
|
parser = reqparse.RequestParser() # initialize
|
|
|
|
parser.add_argument('time', required=True)
|
|
|
|
parser.add_argument('temp', required=True)
|
|
|
|
time = int(parser.parse_args()['time'])
|
|
|
|
temp = float(parser.parse_args()['temp'])
|
|
|
|
data = migenie.turn_on_heating(temp, time)
|
|
|
|
sleep(2)
|
|
|
|
if get_heating_status()[0]['heatingOn']:
|
|
|
|
return data, 200 # return data with 200 OK
|
|
|
|
else:
|
|
|
|
return data, 400
|
|
|
|
|
|
|
|
def turn_off_heating()->dict:
|
|
|
|
data = migenie.turn_off_heating()
|
|
|
|
return data, 200
|