Process a message before going back to smartsleep.

def handle_smartsleep(msg):
    """Process a message before going back to smartsleep."""
    while msg.gateway.sensors[msg.node_id].queue:
        msg.gateway.add_job(
            str, msg.gateway.sensors[msg.node_id].queue.popleft())
    for child in msg.gateway.sensors[msg.node_id].children.values():
        new_child = msg.gateway.sensors[msg.node_id].new_state.get(
            child.id, ChildSensor(child.id, child.type, child.description))
        msg.gateway.sensors[msg.node_id].new_state[child.id] = new_child
        for value_type, value in child.values.items():
            new_value = new_child.values.get(value_type)
            if new_value is not None and new_value != value:
                msg.gateway.add_job(
                    msg.gateway.sensors[msg.node_id].set_child_value,
                    child.id, value_type, new_value)