Exemplo n.º 1
0
def get_slave(id):
    slave = Status.get(Status.id == id)
    if request.method == 'GET':
        return jsonify(slave.__data__)
    elif request.method == 'DELETE':
        Status.delete_by_id(slave.id)
        return Response(None, 200)
Exemplo n.º 2
0
def all_slave():
    if request.method == 'GET':
        data = [each.__data__ for each in Status.select()]
        return jsonify(data)
    elif request.method == 'POST':
        card_id = request.json['card_id']
        Status(card_id=card_id).save()
        return Response(None, 200)
Exemplo n.º 3
0
 def power_first(self):
     for item in Request.select():
         status = Status.get(Status.id == item.slave_id)
         if status.speed == 0 and item.speed > 0:  # 开机请求
             yield item
         elif status.speed == 3 and item.speed == 0:  # 关机请求
             yield item
Exemplo n.º 4
0
def init(id, init):
    if not ac.flag:
        ac.init(int(id), int(init))
        ac.flag = True
    else:
        ac.cur_temp = ac.out_temp = int(init)
        ac.status = Status.get(Status.id == id)
    executor.submit(ac.run)
    return 'ok'
Exemplo n.º 5
0
def temp_op(op, id):
    slave = Status.get(Status.id == id)
    if (op == 'high'):
        if slave.target_temp < 30:
            slave.target_temp += 1
            slave.save()
            return Response(None, 200)

    elif (op == 'low'):
        if slave.target_temp > 10:
            slave.target_temp -= 1
            slave.save()
            return Response(None, 200)

    abort(302)
Exemplo n.º 6
0
def speed_op(op, id):
    slave = Status.get(Status.id == id)
    if (op == 'high'):
        if slave.speed < 5:
            slave.speed += 1
            slave.save()
            return Response(None, 200)

    elif (op == 'low'):
        if slave.speed > 0:
            slave.speed -= 1
            slave.save()
            return Response(None, 200)

    abort(302)
Exemplo n.º 7
0
 def resolve_request(self):  # 处理队列中的请求
     for item in self.requestList:
         status = Status.get(Status.id == item.slave_id)
         if item.speed >= 0 and item.speed <= 3:  # 风速在可调控范围内
             if self.main_status == 1 and item.temp >= 18 and item.temp <= 25:  # 处于制冷模式并且温度在可调控范围内
                 if status.cur_temp < item.temp:  # 从机当前温度低于目标温度则风速调0,等待温度回升
                     status.target_temp = item.temp
                     status.speed = 0
                     status.save()
                     Log(slave_id=item.slave_id,
                         card_id=status.card_id,
                         cur_temp=status.cur_temp,
                         target_temp=item.temp,
                         speed=0,
                         req_time=item.time).save()
                 else:
                     status.target_temp = item.temp
                     status.speed = item.speed
                     status.save()
                     Log(slave_id=item.slave_id,
                         card_id=status.card_id,
                         cur_temp=status.cur_temp,
                         target_temp=item.temp,
                         speed=item.speed,
                         req_time=item.time).save()
             elif self.main_status == 2 and item.temp >= 25 and item.temp <= 30:
                 if status.cur_temp > item.temp:  # 从机当前温度高于目标温度则风速调0,等待温度下降
                     status.target_temp = item.temp
                     status.speed = 0
                     status.save()
                     Log(slave_id=item.slave_id,
                         card_id=status.card_id,
                         cur_temp=status.cur_temp,
                         target_temp=item.temp,
                         speed=0,
                         req_time=item.time).save()
                 else:
                     status.target_temp = item.temp
                     status.speed = item.speed
                     status.save()
                     Log(slave_id=item.slave_id,
                         card_id=status.card_id,
                         cur_temp=status.cur_temp,
                         target_temp=item.temp,
                         speed=item.speed,
                         req_time=item.time).save()
Exemplo n.º 8
0
def speed_op(op, id):
    slave = Status.get(Status.id == id)
    if (op == 'high'):
        if slave.speed < 5:
            Request(
                slave_id=id, speed=slave.speed + 1,
                temp=slave.target_temp).save()
            return Response(None, 200)

    elif (op == 'low'):
        if slave.speed > 0:
            Request(
                slave_id=id, speed=slave.speed - 1,
                temp=slave.target_temp).save()
            return Response(None, 200)

    abort(302)
Exemplo n.º 9
0
def temp_op(op, id):
    slave = Status.get(Status.id == id)
    if (op == 'high'):
        if slave.target_temp < 30:
            Request(
                slave_id=id, speed=slave.speed,
                temp=slave.target_temp + 1).save()
            return Response(None, 200)

    elif (op == 'low'):
        if slave.target_temp > 10:
            Request(
                slave_id=id, speed=slave.speed,
                temp=slave.target_temp - 1).save()
            return Response(None, 200)

    abort(302)
Exemplo n.º 10
0
 def init(self):  # 初始化
     # 删除所有请求
     Request.delete()
     # 重置从机温度
     for item in Status.select():
         if self.main_status == 1 and item.target_temp > 25:
             item.target_temp = 22
             item.speed = 0
             item.save()
             Log(slave_id=item.id,
                 card_id=item.card_id,
                 cur_temp=item.cur_temp,
                 target_temp=22,
                 speed=0).save()
         elif self.main_status == 2 and item.target_temp <= 25:
             item.target_temp = 28
             item.speed = 0
             item.save()
             Log(slave_id=item.id,
                 card_id=item.card_id,
                 cur_temp=item.cur_temp,
                 target_temp=28,
                 speed=0).save()
Exemplo n.º 11
0
 def exit(self):
     Status.update(speed=0)
     self.flag = False
Exemplo n.º 12
0
def slave_shutdown(id):
    slave = Status.get(Status.id == id)
    Request(slave_id=id, speed=0, temp=slave.target_temp).save()
    return Response(None, 200)
Exemplo n.º 13
0
def check(card_id):
    data = Status.get(Status.card_id == card_id).__data__
    return jsonify(data)
Exemplo n.º 14
0
 def init(self, id, out_temp):
     self.status = Status.get(Status.id == id)
     self.syntax()
     self.cur_temp = self.out_temp = out_temp
     self.update()
     self.time = time.time()
Exemplo n.º 15
0
 def syntax(self):
     self.status = Status.get(Status.id == self.status.id)
     self.target_temp = self.status.target_temp
     self.speed = self.status.speed