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

Threads hanging about (Pure Hot+Cold Link) #21

Open
theboyknowsclass opened this issue Nov 28, 2018 · 0 comments
Open

Threads hanging about (Pure Hot+Cold Link) #21

theboyknowsclass opened this issue Nov 28, 2018 · 0 comments

Comments

@theboyknowsclass
Copy link

theboyknowsclass commented Nov 28, 2018

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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant