Esempio n. 1
0
    def mutate(root, info, id, state):
        roller = Roller.objects.get(id=id)

        payload = "open" if state else "close"

        if not can_proceed(roller.open if state else roller.close):
            return SetRoller(ok=False)

        mqtt_publish.send(__name__, topic=roller.mqtt_topic, payload=payload)
        return SetRoller(ok=True)
Esempio n. 2
0
    def mutate(root, info, id_list, state):
        rollers = Roller.objects.filter(id__in=id_list)

        payload = "open" if state else "close"

        for roller in rollers:
            if can_proceed(roller.open if state else roller.close):
                mqtt_publish.send(__name__, topic=roller.mqtt_topic, payload=payload)

        return BatchSetRoller(ok=True)
Esempio n. 3
0
    def mutate(root, info, id_list, state):
        sockets = Socket.objects.filter(id__in=id_list)

        for socket in sockets:
            if can_proceed(socket.on if state else socket.off):
                mqtt_publish.send(__name__,
                                  topic=socket.mqtt_topic,
                                  payload="on" if state else "off")

        return BatchSetSocket(ok=True)
Esempio n. 4
0
    def mutate(root, info, id, state):
        socket = Socket.objects.get(id=id)

        if not can_proceed(socket.on if state else socket.off):
            return SetSocket(ok=False)

        mqtt_publish.send(__name__,
                          topic=socket.mqtt_topic,
                          payload="on" if state else "off")
        return SetSocket(ok=True, new_state=state)
Esempio n. 5
0
    def mutate(root, info, id_list, state):
        lamps = Lamp.objects.filter(id__in=id_list)

        for lamp in lamps:
            if can_proceed(lamp.on if state else lamp.off):
                mqtt_publish.send(__name__,
                                  topic=lamp.mqtt_topic,
                                  payload="on" if state else "off")

        return BatchSetLamp(ok=True)
Esempio n. 6
0
    def mutate(root, info, id, state):
        lamp = Lamp.objects.get(id=id)

        if not can_proceed(lamp.on if state else lamp.off):
            return SetLamp(ok=False)

        mqtt_publish.send(__name__,
                          topic=lamp.mqtt_topic,
                          payload="on" if state else "off")
        return SetLamp(ok=True)
Esempio n. 7
0
    def mutate(root, info, id):
        roller = Roller.objects.get(id=id)

        if can_proceed(roller.open):
            payload = "open"
        elif can_proceed(roller.close):
            payload = "close"
        else:
            return ToggleRoller(ok=False)

        mqtt_publish.send(__name__, topic=roller.mqtt_topic, payload=payload)
        return ToggleRoller(ok=True)
Esempio n. 8
0
    def mutate(root, info, id):
        socket = Socket.objects.get(id=id)

        if can_proceed(socket.on):
            payload = "on"
        elif can_proceed(socket.off):
            payload = "off"
        else:
            return ToggleSocket(ok=False)

        mqtt_publish.send(__name__, topic=socket.mqtt_topic, payload=payload)
        return ToggleSocket(ok=True)
Esempio n. 9
0
    def mutate(root, info, id):
        lamp = Lamp.objects.get(id=id)

        if can_proceed(lamp.on):
            payload = "on"
        elif can_proceed(lamp.off):
            payload = "off"
        else:
            return ToggleLamp(ok=False)

        mqtt_publish.send(__name__, topic=lamp.mqtt_topic, payload=payload)
        return ToggleLamp(ok=True)