def get(self, channel_id):
        channel = int(channel_id)
        if not (channel == 0 or channel == 1):
            return connection_state_dict("Channel number must be 0 or 1"), 403

        # yeh, more groan
        status = evil_global.comms.get_channel_status(
            int(channel), evil_global.last_seen_charger_device_id)

        obj = status.to_primitive()
        obj.update(connection_state_dict())

        return obj
    def get(self):
        syst = evil_global.comms.get_system_storage()

        obj = syst.to_primitive()
        obj.update(connection_state_dict())

        return obj
 def put(self, channel_id):
     channel_number = int(channel_id)
     logger.info("Stop, channel {0}".format(channel_number))
     operation_response = evil_global.comms.stop_operation(
         channel_number).to_primitive()
     operation_response.update(connection_state_dict())
     return operation_response
    def get(self):
        info = evil_global.comms.get_device_info()

        evil_global.last_seen_charger_device_id = info.device_id

        obj = info.to_primitive()
        obj.update(connection_state_dict())

        return obj
    def wrapper(self, *args, **kwargs):
        with evil_global.lock:
            retry = 0
            while retry < RETRY_LIMIT:
                try:
                    return func(self, *args, **kwargs)

                except ObjectNotFoundException as e:
                    abort(404, message=e.message)

                except BadRequest as badRequest:
                    # Just return it, it's a validation failure
                    raise badRequest

                except ValueError as ve:
                    raise ve

                except Exception, ex:
                    retry += 1

                    logger.warning(
                        "{0}/{3}, will try again (count is at {1}/{2})".format(
                            ex, retry, RETRY_LIMIT, type(ex)))

                    # If the charger isn't plugged in. This could fail.
                    try:
                        evil_global.comms.reset()
                    except Exception, ex:
                        logger.error(
                            "Error resetting comms! Charger not plugged in? {0}"
                            .format(ex))

                    if retry >= RETRY_LIMIT:
                        logger.warning(
                            "retry limit exceeded, aborting the call completely"
                        )
                        return connection_state_dict(ex), 504
 def put(self, channel_id, preset_memory_slot):
     device_status = evil_global.comms.run_operation(
         Operation.Charge, int(channel_id), int(preset_memory_slot))
     annotated_device_status = device_status.to_primitive()
     annotated_device_status.update(connection_state_dict())
     return annotated_device_status