async def turn_valve_on_handler(iot_device: IotDevice, values):
    # TODO: Cancel any previous timer.
    if values and type(values) == int:
        print("Turning device on for {count} secs".format(count=values))
        # TODO: Set a timer to turn off device.
    else:
        print("Turning device on.")
    iot_device.turn_valve_on()
示例#2
0
async def turn_valve_on_handler(iot_device: IotDevice, values):
    iot_device.cancel_timer()
    if values and type(values) == int:
        duration = values
        print("Turning device on for {0} secs".format(duration))
        _auto_shutoff_timer(iot_device, duration)
    else:
        print("Turning device on.")
    iot_device.turn_valve_on()
async def testDevice(device: IotDevice):
    print("\n\nTesting {0} device.".format(type(device)))
    printTelemetry(device)

    print("\nTurning on valve, then waiting 5 seconds...")
    device.turn_valve_on()
    await asyncio.sleep(5)

    printTelemetry(device)
    if device.get_flow() == 0:
        print("\033[93mWARNING: *** NO FLOW DETECTED ***\033[0m")

    print("\nTurning off valve, then waiting 5 seconds...")
    device.turn_valve_off()
    await asyncio.sleep(5)

    printTelemetry(device)
    if device.get_flow() != 0:
        print("\033[93mWARNING: *** FLOW DETECTED ***\033[0m")
 def turn_valve_on(self):
     IotDevice.set_flow(self, 6.2)
     IotDevice.turn_valve_on(self)