i created a simple web service in flask, the problem i have is that the requests seem to leave an extra thread kicking about - this also seems to block some resources, and the fan will stop responding to requests after 3 or so have been made.
from libpurecoollink.dyson import DysonAccount
from libpurecoollink.const import FanSpeed, FanMode, NightMode, Oscillation, \
FanState, StandbyMonitoring, QualityTarget, ResetFilter, HeatMode, \
FocusMode, HeatTarget
from libpurecoollink.dyson_pure_state import DysonPureHotCoolState, \
DysonPureCoolState, DysonEnvironmentalSensorState
from datetime import datetime
import re
app = Flask(__name__)
@app.route("/")
def home():
return "Hello, Dyson!"
@app.route("/hellodyson/<ip>/set-heattarget/<heat>")
def setheattarget(ip, heat):
dyson_account = DysonAccount(...)
logged = dyson_account.login()
if not logged:
print('Unable to login to Dyson account')
exit(1)
devices = dyson_account.devices()
name = devices[0].name
if not devices[0].connected:
devices[0].connect(ip)
if devices[0].connected:
devices[0].set_configuration(heat_target=HeatTarget.celsius(int(heat)))
devices[0].disconnect()
content = "Dyson Fan at IP " + ip + "(" + name + ") is set to temperature " + heat
else:
content = "ERROR: Setting Dyson Fan at IP " + ip + "(" + name + ") to temperature " + heat
del dyson_account, logged, devices, name
return content
@app.route("/hellodyson/<ip>/set-fanspeed/<speed>")
def setfanspeed(ip, speed):
dyson_account = DysonAccount(...)
logged = dyson_account.login()
if not logged:
print('Unable to login to Dyson account')
exit(1)
devices = dyson_account.devices()
name = devices[0].name
if not devices[0].connected:
devices[0].connect(ip)
if devices[0].connected:
devices[0].set_configuration(fan_speed=FanSpeed(speed))
devices[0].disconnect()
content = "Dyson Fan at IP " + ip + "(" + name + ") is set to speed " + speed
else:
content = "ERROR: Setting Dyson Fan at IP " + ip + "(" + name + ") to speed " + speed
del dyson_account, logged, devices, name
return content
hi,
i created a simple web service in flask, the problem i have is that the requests seem to leave an extra thread kicking about - this also seems to block some resources, and the fan will stop responding to requests after 3 or so have been made.