elif channel.state == "error" or channel.state == "verror": if leds_on: channel.set_led(RED, write=False) else: channel.set_led(OFF, write=False) # update all the LEDs at once, so don't write them all after each iteration - just once at the end status_leds.write() # request new temperature readings for next time temperature_sensors.request_temperatures() stats = json.dumps({"channels": stats}) ws.send(packet.build_device_status(stats)) for channel in channels: voltage_and_current = channel.request_voltage_and_current() channel.voltage_and_current = voltage_and_current channel.temperature = channel.get_temperature() v = voltage_and_current["voltage"] c = voltage_and_current["current"] t = channel.temperature if channel.state == "empty": # if the voltage is above the min required to start discharging and below threshold if channel.start_discharge_voltage_cutoff < v < MAX_CELL_VOLTAGE: channel.cell_inserted()